mirror of
https://github.com/ClipFusion-org/clipfusion.git
synced 2025-08-05 19:25:09 +00:00
ui: implemented better duplication mechanism
This commit is contained in:
parent
68cdef63eb
commit
aa64aeaa26
@ -2,7 +2,7 @@
|
|||||||
import { SidebarTrigger } from "@/components/ui/sidebar";
|
import { SidebarTrigger } from "@/components/ui/sidebar";
|
||||||
import { ReactNode, useState } from "react";
|
import { ReactNode, useState } from "react";
|
||||||
import { useLiveQuery } from "dexie-react-hooks";
|
import { useLiveQuery } from "dexie-react-hooks";
|
||||||
import { db } from "@/lib/db";
|
import { addProject, db, deleteProject } from "@/lib/db";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { CopyIcon, EditIcon, EllipsisIcon, InfoIcon, ListCheckIcon, PencilIcon, PlusIcon, TrashIcon } from "lucide-react";
|
import { CopyIcon, EditIcon, EllipsisIcon, InfoIcon, ListCheckIcon, PencilIcon, PlusIcon, TrashIcon } from "lucide-react";
|
||||||
@ -95,7 +95,7 @@ const RenameProjectDialog = ({ project }: { project: Project }) => {
|
|||||||
|
|
||||||
const DeleteProjectDialog = ({ project }: { project: Project }) => {
|
const DeleteProjectDialog = ({ project }: { project: Project }) => {
|
||||||
const handleDelete = async () => {
|
const handleDelete = async () => {
|
||||||
await db.projects.delete(project.uuid);
|
deleteProject(project.uuid);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -122,15 +122,27 @@ const ProjectDropdown = ({ project }: { project: Project }): ReactNode => {
|
|||||||
const isMobile = useIsMobile();
|
const isMobile = useIsMobile();
|
||||||
|
|
||||||
const handleDuplicate = async () => {
|
const handleDuplicate = async () => {
|
||||||
|
let originProject = await db.projects.where('uuid').equals(project.origin).first();
|
||||||
|
if (!originProject) originProject = project;
|
||||||
|
let newProjectTitle = originProject.title;
|
||||||
|
|
||||||
|
const duplication = await db.duplications.where('uuid').equals(originProject.uuid).first();
|
||||||
|
if (!duplication) return;
|
||||||
|
newProjectTitle = `${originProject.title} (${duplication.count + 1})`;
|
||||||
|
await db.duplications.update(duplication.uuid, {
|
||||||
|
...duplication,
|
||||||
|
count: duplication.count + 1
|
||||||
|
});
|
||||||
|
|
||||||
const newProject = {
|
const newProject = {
|
||||||
...project,
|
...project,
|
||||||
uuid: generateUUID(),
|
uuid: generateUUID(),
|
||||||
creationDate: Date.now(),
|
creationDate: Date.now(),
|
||||||
editDate: Date.now(),
|
editDate: Date.now(),
|
||||||
title: project.title.includes("Copy of") ? project.title : `Copy of ${project.title}`,
|
title: newProjectTitle,
|
||||||
origin: project.origin
|
origin: originProject.uuid
|
||||||
};
|
};
|
||||||
await db.projects.add(newProject);
|
addProject(newProject as Project);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -239,14 +251,14 @@ export default function Home(): ReactNode {
|
|||||||
|
|
||||||
const newProjectSubmit = async (data: z.infer<typeof ProjectInfoFormSchema>) => {
|
const newProjectSubmit = async (data: z.infer<typeof ProjectInfoFormSchema>) => {
|
||||||
const date = Date.now();
|
const date = Date.now();
|
||||||
await db.projects.add({
|
addProject({
|
||||||
uuid: generateUUID(),
|
uuid: generateUUID(),
|
||||||
creationDate: date,
|
creationDate: date,
|
||||||
editDate: date,
|
editDate: date,
|
||||||
title: data.title,
|
title: data.title,
|
||||||
description: data.description,
|
description: data.description,
|
||||||
origin: ""
|
origin: ""
|
||||||
});
|
} as Project);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -27,9 +27,8 @@ const PersistenceProvider = ({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const tryToPersist = async () => {
|
const tryToPersist = async () => {
|
||||||
const isPersistent = await isStoragePersisted();
|
const isPersistent = await isStoragePersisted();
|
||||||
console.log(isPersistent);
|
|
||||||
if (!isPersistent) {
|
if (!isPersistent) {
|
||||||
if ((localStorage.getItem('persistence-status') != "persisted" && localStorage.getItem('persistence-status') == undefined) || localStorage.getItem('persistence-status') === "") {
|
if ((localStorage.getItem('persistence-status') !== "persisted" && localStorage.getItem('persistence-status') === undefined) || localStorage.getItem('persistence-status') === "") {
|
||||||
const persistenceStatus = await tryPersistWithoutPromtingUser();
|
const persistenceStatus = await tryPersistWithoutPromtingUser();
|
||||||
localStorage.setItem("persistence-status", persistenceStatus);
|
localStorage.setItem("persistence-status", persistenceStatus);
|
||||||
if (persistenceStatus == "never") {
|
if (persistenceStatus == "never") {
|
||||||
|
@ -94,11 +94,11 @@ export const Dashboard = (): ReactNode => {
|
|||||||
<Tooltip>
|
<Tooltip>
|
||||||
<TooltipTrigger>
|
<TooltipTrigger>
|
||||||
<a href="https://github.com/ClipFusion-org/clipfusion" target="_blank">
|
<a href="https://github.com/ClipFusion-org/clipfusion" target="_blank">
|
||||||
<Image src="/github-mark.svg" aria-hidden width="25" height="25" alt="ClipFusion GitHub Repository" className="duration-100 dark:invert hover:opacity-95 active:scale-95"/>
|
<Image src="/github-mark.svg" aria-hidden width="25" height="25" alt="ClipFusion GitHub" className="duration-100 dark:invert hover:opacity-95 active:scale-95"/>
|
||||||
</a>
|
</a>
|
||||||
</TooltipTrigger>
|
</TooltipTrigger>
|
||||||
<TooltipContent>
|
<TooltipContent>
|
||||||
<p>ClipFusion GitHub Repository</p>
|
<p>ClipFusion GitHub</p>
|
||||||
</TooltipContent>
|
</TooltipContent>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
|
@ -1,7 +1,21 @@
|
|||||||
import EditorDB from "@/types/EditorDB";
|
import EditorDB from "@/types/EditorDB";
|
||||||
|
import Project from "@/types/Project";
|
||||||
|
|
||||||
export const db = new EditorDB();
|
export const db = new EditorDB();
|
||||||
|
|
||||||
|
export function addProject(project: Project) {
|
||||||
|
db.projects.add(project);
|
||||||
|
db.duplications.add({
|
||||||
|
uuid: project.uuid,
|
||||||
|
count: 0
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function deleteProject(uuid: string) {
|
||||||
|
db.projects.delete(uuid);
|
||||||
|
db.duplications.delete(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
// StorageManager code from https://dexie.org/docs/StorageManager
|
// StorageManager code from https://dexie.org/docs/StorageManager
|
||||||
|
|
||||||
/** Check if storage is persisted already.
|
/** Check if storage is persisted already.
|
||||||
|
7
src/types/Duplication.ts
Normal file
7
src/types/Duplication.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { Entity } from "dexie";
|
||||||
|
import EditorDB from "./EditorDB";
|
||||||
|
|
||||||
|
export default class Duplication extends Entity<EditorDB> {
|
||||||
|
uuid!: string;
|
||||||
|
count!: number;
|
||||||
|
}
|
@ -1,14 +1,18 @@
|
|||||||
import Dexie, { type EntityTable } from "dexie";
|
import Dexie, { type EntityTable } from "dexie";
|
||||||
import Project from "./Project";
|
import Project from "./Project";
|
||||||
|
import Duplication from "./Duplication";
|
||||||
|
|
||||||
export default class EditorDB extends Dexie {
|
export default class EditorDB extends Dexie {
|
||||||
projects!: EntityTable<Project, 'uuid'>;
|
projects!: EntityTable<Project, 'uuid'>;
|
||||||
|
duplications!: EntityTable<Duplication, 'uuid'>;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super('EditorDB');
|
super('EditorDB');
|
||||||
this.version(1).stores({
|
this.version(1).stores({
|
||||||
projects: 'uuid, project'
|
projects: 'uuid, project',
|
||||||
|
duplications: 'uuid, count'
|
||||||
});
|
});
|
||||||
this.projects.mapToClass(Project);
|
this.projects.mapToClass(Project);
|
||||||
|
this.duplications.mapToClass(Duplication);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user