|
4 | 4 | */ |
5 | 5 |
|
6 | 6 | import { defineStore } from 'pinia' |
7 | | -import { set } from 'vue' |
8 | | -import { generateUrl } from '@nextcloud/router' |
9 | | -import axios from '@nextcloud/axios' |
10 | | -import { emit, subscribe } from '@nextcloud/event-bus' |
| 7 | +import { loadState } from '@nextcloud/initial-state' |
11 | 8 |
|
12 | 9 | export const useUserConfigStore = defineStore('userconfig', { |
13 | 10 | state: () => ({ |
14 | | - grid_view: true, // valor inicial, mas será sobrescrito pelo servidor |
| 11 | + grid_view: loadState('libresign', 'config', { grid_view: false }).grid_view, |
15 | 12 | }), |
16 | 13 | actions: { |
17 | 14 | onUpdate(key, value) { |
18 | | - set(this, key, value) |
| 15 | + this[key] = value |
19 | 16 | }, |
20 | 17 |
|
21 | 18 | async update(key, value) { |
22 | | - const oldValue = this[key] |
23 | 19 | this.onUpdate(key, value) |
24 | 20 |
|
25 | | - try { |
26 | | - const response = await axios.put( |
27 | | - generateUrl('/apps/files/api/v1/config/{key}', { key }), |
28 | | - { value }, |
29 | | - ) |
30 | | - |
31 | | - if (response?.data?.value !== undefined) { |
32 | | - this.onUpdate(key, response.data.value) |
33 | | - } |
34 | | - |
35 | | - emit('files:config:updated', { key, value }) |
36 | | - } catch (error) { |
37 | | - console.error('Erro ao salvar configuração:', error) |
38 | | - this.onUpdate(key, oldValue) |
39 | | - } |
| 21 | + OCP.AppConfig.setValue('libresign', 'grid_view', value) |
40 | 22 | }, |
41 | 23 |
|
42 | | - initListeners() { |
43 | | - console.log('Initializing user config listeners...') |
44 | | - subscribe('files:config:updated', ({ key, value }) => { |
45 | | - this.onUpdate(key, value) |
46 | | - }) |
47 | | - }, |
48 | 24 | }, |
49 | 25 | }) |
0 commit comments