Files
warren/frontend/stores/index.ts
2025-07-20 13:14:31 +02:00

81 lines
1.9 KiB
TypeScript

import { defineStore } from 'pinia';
import type { DirectoryEntry } from '#shared/types';
import type { Warren } from '#shared/types/warrens';
export const useWarrenStore = defineStore('warrens', {
state: () => ({
warrens: {} as Record<string, Warren>,
current: null as { warrenId: string; path: string } | null,
loading: false,
}),
actions: {
setCurrentWarren(warrenId: string, path: string) {
this.current = {
warrenId,
path,
};
},
addToCurrentWarrenPath(path: string) {
if (this.current == null) {
return;
}
if (!this.current.path.endsWith('/')) {
path = '/' + path;
}
this.current.path += path;
},
setCurrentWarrenPath(path: string) {
if (this.current == null) {
return;
}
if (!path.startsWith('/')) {
path = '/' + path;
}
this.current.path = path;
},
clearCurrentWarren() {
this.current = null;
},
},
});
export const useCreateDirectoryDialog = defineStore('create_directory_dialog', {
state: () => ({
open: false,
value: '',
}),
actions: {
openDialog() {
this.open = true;
},
reset() {
this.open = false;
this.value = '';
},
},
});
export const useRenameDirectoryDialog = defineStore('rename_directory_dialog', {
state: () => ({
open: false,
entry: null as DirectoryEntry | null,
value: '',
}),
actions: {
openDialog(entry: DirectoryEntry) {
this.entry = entry;
this.value = entry.name;
this.open = true;
},
reset() {
this.open = false;
this.entry = null;
this.value = '';
},
},
});