fix(files): paths store reactivity

Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
pull/37866/head
John Molakvoæ 2023-04-21 15:41:28 +07:00
parent 1de3666e16
commit cae00d2e96
No known key found for this signature in database
GPG Key ID: 60C25B8C072916CF
3 changed files with 18 additions and 12 deletions

@ -59,11 +59,11 @@ export const useFilesStore = function() {
updateNodes(nodes: Node[]) {
// Update the store all at once
const files = nodes.reduce((acc, node) => {
if (!node.attributes.fileid) {
if (!node.fileid) {
logger.warn('Trying to update/set a node without fileid', node)
return acc
}
acc[node.attributes.fileid] = node
acc[node.fileid] = node
return acc
}, {} as FilesStore)

@ -24,20 +24,22 @@ import type { PathOptions, ServicesState } from '../types.ts'
import { defineStore } from 'pinia'
import { subscribe } from '@nextcloud/event-bus'
import type { FileId } from '../types'
import type { FileId, PathsStore } from '../types'
import Vue from 'vue'
export const usePathsStore = function() {
const store = defineStore('paths', {
state: (): ServicesState => ({}),
state: () => ({
paths: {} as ServicesState
} as PathsStore),
getters: {
getPath: (state) => {
return (service: string, path: string): FileId|undefined => {
if (!state[service]) {
if (!state.paths[service]) {
return undefined
}
return state[service][path]
return state.paths[service][path]
}
},
},
@ -45,12 +47,12 @@ export const usePathsStore = function() {
actions: {
addPath(payload: PathOptions) {
// If it doesn't exists, init the service state
if (!this[payload.service]) {
Vue.set(this, payload.service, {})
if (!this.paths[payload.service]) {
Vue.set(this.paths, payload.service, {})
}
// Now we can set the provided path
Vue.set(this[payload.service], payload.path, payload.fileid)
Vue.set(this.paths[payload.service], payload.path, payload.fileid)
},
}
})

@ -49,13 +49,17 @@ export interface RootOptions {
// Paths store
export type ServicesState = {
[service: Service]: PathsStore
[service: Service]: PathConfig
}
export type PathsStore = {
export type PathConfig = {
[path: string]: number
}
export type PathsStore = {
paths: ServicesState
}
export interface PathOptions {
service: Service
path: string
@ -91,4 +95,4 @@ export interface ViewConfigs {
}
export interface ViewConfigStore {
viewConfig: ViewConfigs
}
}