feat: import
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import type { ServiceObject } from '@ChronoManager/models/service'
|
||||
import { useCollectionsStore } from '@ChronoManager/stores/collectionsStore'
|
||||
import { useEntitiesStore } from '@ChronoManager/stores/entitiesStore'
|
||||
import { useServicesStore } from '@ChronoManager/stores/servicesStore'
|
||||
import { useImportStore } from '@ChronoManager/stores/importStore'
|
||||
import type { CalendarView as CalendarViewType } from '@/types'
|
||||
import {
|
||||
AGENDA_VIEW_SPANS,
|
||||
@@ -24,6 +25,7 @@ export const useChronoStore = defineStore('chronoStore', () => {
|
||||
const servicesStore = useServicesStore()
|
||||
const collectionsStore = useCollectionsStore()
|
||||
const entitiesStore = useEntitiesStore()
|
||||
const importStore = useImportStore()
|
||||
|
||||
const savedCalendarView = userStore.getSetting('chrono.calendarView')
|
||||
const savedDaysViewSpan = userStore.getSetting('chrono.daysViewSpan')
|
||||
@@ -55,6 +57,7 @@ export const useChronoStore = defineStore('chronoStore', () => {
|
||||
const showEventEditor = ref(false)
|
||||
const showTaskEditor = ref(false)
|
||||
const showCollectionEditor = ref(false)
|
||||
const showImportDialog = ref(false)
|
||||
|
||||
const entityEditorMode = ref<'edit' | 'view'>('view')
|
||||
const editingCollection = shallowRef<CollectionObject | null>(null)
|
||||
@@ -357,6 +360,33 @@ export const useChronoStore = defineStore('chronoStore', () => {
|
||||
showCollectionEditor.value = false
|
||||
}
|
||||
|
||||
async function openImport(files: File[]) {
|
||||
importStore.removeAllFiles()
|
||||
importStore.reset()
|
||||
for (const file of files) {
|
||||
const id = importStore.addFile({ name: file.name, contents: await file.text(), size: file.size, type: file.type })
|
||||
if (selectedCollection.value && collections.value.some(collection => collection.identifier === selectedCollection.value?.identifier)) {
|
||||
importStore.setCollectionForFile(id, selectedCollection.value.identifier)
|
||||
}
|
||||
}
|
||||
importStore.stage = 'selecting'
|
||||
showImportDialog.value = true
|
||||
}
|
||||
|
||||
async function closeImport(refresh = false) {
|
||||
showImportDialog.value = false
|
||||
if (refresh) {
|
||||
const targets = new Set<CollectionObject['identifier']>()
|
||||
for (const id of importStore.order) {
|
||||
const target = importStore.sessions[id]?.targetIdentifier
|
||||
if (target) targets.add(target)
|
||||
}
|
||||
for (const target of targets) await entitiesStore.list([target])
|
||||
}
|
||||
importStore.removeAllFiles()
|
||||
importStore.reset()
|
||||
}
|
||||
|
||||
async function initialize() {
|
||||
loading.value = true
|
||||
try {
|
||||
@@ -391,6 +421,7 @@ export const useChronoStore = defineStore('chronoStore', () => {
|
||||
showEventEditor,
|
||||
showTaskEditor,
|
||||
showCollectionEditor,
|
||||
showImportDialog,
|
||||
entityEditorMode,
|
||||
editingCollection,
|
||||
collectionEditorMode,
|
||||
@@ -433,6 +464,8 @@ export const useChronoStore = defineStore('chronoStore', () => {
|
||||
deleteTask,
|
||||
saveCollection,
|
||||
deleteCollection,
|
||||
openImport,
|
||||
closeImport,
|
||||
initialize,
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user