From f0c7f9625c63ef9c9c23e9ed02eabb8627740013 Mon Sep 17 00:00:00 2001 From: Joery Date: Fri, 19 Apr 2024 17:02:19 +0200 Subject: [PATCH 1/2] feat: Added renaming of projects Added a way of patching changes to projects. Extracted the logic that decides what storage controller to use with which project into a seperate function --- .../components/Editor/Library/LibraryItem.vue | 21 +++----- .../src/components/InplaceRename.vue | 53 +++++++++++++++++++ .../Menu/ProjectList/ProjectList.vue | 18 ++++++- packages/safelight/src/main.ts | 2 + packages/safelight/src/stores/useProject.ts | 37 +++++++------ .../shared/src/Storage/IndexedDbStorage.ts | 45 ++++++++++++---- packages/shared/src/base/Storage.ts | 3 ++ 7 files changed, 137 insertions(+), 42 deletions(-) create mode 100644 packages/safelight/src/components/InplaceRename.vue diff --git a/packages/safelight/src/components/Editor/Library/LibraryItem.vue b/packages/safelight/src/components/Editor/Library/LibraryItem.vue index 3ca3e555..f3603446 100644 --- a/packages/safelight/src/components/Editor/Library/LibraryItem.vue +++ b/packages/safelight/src/components/Editor/Library/LibraryItem.vue @@ -74,21 +74,12 @@ const menuItems = ref([ // My god // TODO: Not this -const hasItemInTimeline = computed(() => { - console.log('A'); - return project.project - ? project.project.timelines.some( - (t) => - t.isSimpleTimeline() && - t.items.some( - (i) => - i.isBaseTimelineItem() && - i.isVideo() && - i.media.value?.id == props.item.id - ) - ) - : false; -}); +const hasItemInTimeline = computed( + () => + project.project && + project.project.isSimpleProject() && + project.project.usesMedia(props.item) +); const alertt = (text: string) => window.alert(text); diff --git a/packages/safelight/src/components/InplaceRename.vue b/packages/safelight/src/components/InplaceRename.vue new file mode 100644 index 00000000..5becf148 --- /dev/null +++ b/packages/safelight/src/components/InplaceRename.vue @@ -0,0 +1,53 @@ + + + diff --git a/packages/safelight/src/components/Menu/ProjectList/ProjectList.vue b/packages/safelight/src/components/Menu/ProjectList/ProjectList.vue index 38a154ae..5b82050b 100644 --- a/packages/safelight/src/components/Menu/ProjectList/ProjectList.vue +++ b/packages/safelight/src/components/Menu/ProjectList/ProjectList.vue @@ -16,7 +16,11 @@ /> - + + + diff --git a/packages/safelight/src/main.ts b/packages/safelight/src/main.ts index fb68d4c8..26e7748f 100644 --- a/packages/safelight/src/main.ts +++ b/packages/safelight/src/main.ts @@ -8,6 +8,7 @@ import ConfirmationService from 'primevue/confirmationservice'; import 'primevue/resources/primevue.min.css'; import 'primevue/resources/themes/aura-dark-amber/theme.css'; import Tooltip from 'primevue/tooltip'; +import FocusTrap from 'primevue/focustrap'; import './style.scss'; @@ -29,5 +30,6 @@ app.use(ConfirmationService); // Directives app.directive('tooltip', Tooltip); +app.directive('focustrap', FocusTrap); app.mount('#app'); diff --git a/packages/safelight/src/stores/useProject.ts b/packages/safelight/src/stores/useProject.ts index f6b6f286..8f6fa84f 100644 --- a/packages/safelight/src/stores/useProject.ts +++ b/packages/safelight/src/stores/useProject.ts @@ -1,6 +1,6 @@ import { router } from '@/main'; import type BaseProject from '@safelight/shared/base/Project'; -import { Storage, type StoredProject } from '@safelight/shared/base/Storage'; +import BaseStorageController, { Storage, type StoredProject } from '@safelight/shared/base/Storage'; import MediaManager from '@safelight/shared/Storage/MediaManager'; export const useProject = defineStore('Project', () => { @@ -79,25 +79,32 @@ async function newSimpleProject() { await toEditor(); } +export async function getStorageControllerForProject( + project: StoredProject +): Promise { + if (project.type == 'Simple') { + return new (await import('@safelight/shared/Storage/IndexedDbStorage')).default(); + } else { + console.error('Project type not supported'); + } +} + async function openProject(selectedProject: StoredProject) { - if (selectedProject.type == 'Simple') { - const IndexedDbStorageController = ( - await import('@safelight/shared/Storage/IndexedDbStorage') - ).default; + const storageType = await getStorageControllerForProject(selectedProject); + if (!storageType) { + throw new Error('Could not find storage controller for project type'); + } - const projectStore = useProject(); - Storage.setStorage(new IndexedDbStorageController()); + const projectStore = useProject(); + Storage.setStorage(storageType); - const project = await Storage.getStorage().LoadProject(selectedProject.id); + const project = await Storage.getStorage().LoadProject(selectedProject.id); - if (project) { - projectStore.setProject(project); - await toEditor(); - } else { - console.error('Could not load project'); - } + if (project) { + projectStore.setProject(project); + await toEditor(); } else { - console.error('Project type not supported'); + console.error('Could not load project'); } } diff --git a/packages/shared/src/Storage/IndexedDbStorage.ts b/packages/shared/src/Storage/IndexedDbStorage.ts index 34c294b5..2658424b 100644 --- a/packages/shared/src/Storage/IndexedDbStorage.ts +++ b/packages/shared/src/Storage/IndexedDbStorage.ts @@ -19,18 +19,21 @@ export default class IndexedDbStorageController extends BaseStorageController { private db = new SafelightIndexedDB(); - async SaveProject(project: BaseProject): Promise { + async SaveProject(project: BaseProject | StoredProject): Promise { const existingProject = await this.db.project.get({ id: project.id }); - const storableProject: StoredProject = { - id: project.id, - name: project.name, - type: project.type, - media: project.media.map((m) => m.id).filter((id) => id !== undefined), - timelines: project.timelines.map((m) => m.id), - updated: DateTime.now().toISO(), - created: existingProject?.created ?? DateTime.now().toISO() - }; + const storableProject: StoredProject = + 'updated' in project + ? project + : { + id: project.id, + name: project.name, + type: project.type, + media: project.media.map((m) => m.id).filter((id) => id !== undefined), + timelines: project.timelines.map((m) => m.id), + updated: DateTime.now().toISO(), + created: existingProject?.created ?? DateTime.now().toISO() + }; try { await this.db.project.put(storableProject, project.id); @@ -78,6 +81,28 @@ export default class IndexedDbStorageController extends BaseStorageController { } }); } + async UpdateStoredProject( + project: Partial & Pick + ): Promise { + const existingProject = await this.db.project.get({ id: project.id }); + + // Remove created so it can't be overridden + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const { created, ...restProject } = project; + + const storableProject: StoredProject = { + ...existingProject, + ...(restProject as StoredProject), + updated: DateTime.now().toISO() + }; + + try { + await this.db.project.put(storableProject, project.id); + return 'Success'; + } catch (error: any) { + return error.toString(); + } + } static getProjects(): Promise { return new Promise(async (resolve) => { const db = new SafelightIndexedDB(); diff --git a/packages/shared/src/base/Storage.ts b/packages/shared/src/base/Storage.ts index a2cae9fc..58f2da93 100644 --- a/packages/shared/src/base/Storage.ts +++ b/packages/shared/src/base/Storage.ts @@ -18,6 +18,9 @@ export default abstract class BaseStorageController { abstract SaveProject(project: BaseProject): Promise; abstract LoadProject(projectId: string): Promise; + abstract UpdateStoredProject( + project: Partial & Pick + ): Promise; static getProjects: () => Promise; abstract SaveMedia(media: StoredMedia): Promise; From 903d0795d236a314ad1d202c0d61259275fd9da5 Mon Sep 17 00:00:00 2001 From: Joery Date: Fri, 19 Apr 2024 17:39:55 +0200 Subject: [PATCH 2/2] docs: Removed comment --- .../safelight/src/components/Editor/Library/LibraryItem.vue | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/safelight/src/components/Editor/Library/LibraryItem.vue b/packages/safelight/src/components/Editor/Library/LibraryItem.vue index f3603446..da38049f 100644 --- a/packages/safelight/src/components/Editor/Library/LibraryItem.vue +++ b/packages/safelight/src/components/Editor/Library/LibraryItem.vue @@ -72,8 +72,6 @@ const menuItems = ref([ } ]); -// My god -// TODO: Not this const hasItemInTimeline = computed( () => project.project &&