81 lines
2.0 KiB
TypeScript
81 lines
2.0 KiB
TypeScript
import { defineStore } from 'pinia';
|
|
import type { DirectoryEntry } from '#shared/types';
|
|
import type { WarrenData } from '#shared/types/warrens';
|
|
|
|
export const useWarrenStore = defineStore('warrens', {
|
|
state: () => ({
|
|
warrens: {} as Record<string, WarrenData>,
|
|
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 = '';
|
|
},
|
|
},
|
|
});
|