import { defineStore } from 'pinia'; import type { DirectoryEntry } from '#shared/types'; import type { WarrenData } from '#shared/types/warrens'; import { getParentPath } from '~/utils/files'; export const useWarrenStore = defineStore('warrens', { state: () => ({ warrens: {} as Record, imageViewer: { src: null as string | null, }, 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; }, backCurrentPath() { if (this.current == null || this.current.path === '/') { return; } this.current.path = getParentPath(this.current.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 = ''; }, }, });