Skip to content

Commit 8770d14

Browse files
committed
chore: configurations to fix the button and try to save the state
Signed-off-by: Crisciany Souza <criscianysilva1997@gmail.com>
1 parent cd1e7ac commit 8770d14

2 files changed

Lines changed: 24 additions & 9 deletions

File tree

src/store/userconfig.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,45 @@
55

66
import { defineStore } from 'pinia'
77
import { set } from 'vue'
8-
import axios from 'axios'
8+
import { generateUrl } from '@nextcloud/router'
9+
import axios from '@nextcloud/axios'
10+
import { emit, subscribe } from '@nextcloud/event-bus'
911

1012
export const useUserConfigStore = defineStore('userconfig', {
1113
state: () => ({
12-
grid_view: true,
14+
grid_view: true, // valor inicial, mas será sobrescrito pelo servidor
1315
}),
1416
actions: {
17+
onUpdate(key, value) {
18+
set(this, key, value)
19+
},
20+
1521
async update(key, value) {
1622
const oldValue = this[key]
17-
18-
set(this, key, value)
23+
this.onUpdate(key, value)
1924

2025
try {
2126
const response = await axios.put(
22-
`/apps/files/api/v1/config/${key}`,
23-
{ value }
27+
generateUrl('/apps/files/api/v1/config/{key}', { key }),
28+
{ value },
2429
)
2530

2631
if (response?.data?.value !== undefined) {
27-
set(this, key, response.data.value)
32+
this.onUpdate(key, response.data.value)
2833
}
34+
35+
emit('files:config:updated', { key, value })
2936
} catch (error) {
3037
console.error('Erro ao salvar configuração:', error)
31-
32-
set(this, key, oldValue)
38+
this.onUpdate(key, oldValue)
3339
}
3440
},
41+
42+
initListeners() {
43+
console.log('Initializing user config listeners...')
44+
subscribe('files:config:updated', ({ key, value }) => {
45+
this.onUpdate(key, value)
46+
})
47+
},
3548
},
3649
})

src/views/FilesList/FilesList.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ export default {
154154
this.filesStore.updateAllFiles()
155155
},
156156
toggleGridView() {
157+
console.log('Toggling grid view')
158+
console.log(this.userConfigStore)
157159
this.userConfigStore.update('grid_view', !this.userConfigStore.grid_view)
158160
},
159161
closeSidebar() {

0 commit comments

Comments
 (0)