-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔄 Merge pull request #14 from steeeee0223/feature/worxpace
Feature/worxpace: complete notion-like documents
- Loading branch information
Showing
56 changed files
with
2,903 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"use server"; | ||
|
||
import { revalidatePath } from "next/cache"; | ||
|
||
import type { Document } from "@acme/prisma"; | ||
import { createSafeAction, type ActionHandler } from "@acme/ui/lib"; | ||
import { UpdateDocument, type UpdateDocumentInput } from "@acme/validators"; | ||
|
||
import { | ||
createAuditLog, | ||
documents, | ||
fetchClient, | ||
UnauthorizedError, | ||
} from "~/lib"; | ||
|
||
const handler: ActionHandler<UpdateDocumentInput, Document> = async (data) => { | ||
let result; | ||
const { log, id, ...updateData } = data; | ||
|
||
try { | ||
const { userId, orgId } = fetchClient(); | ||
result = await documents.update({ userId, orgId, id, ...updateData }); | ||
/** Activity Log */ | ||
if (log) | ||
await createAuditLog( | ||
{ type: "DOCUMENT", entityId: id, title: result.title }, | ||
"UPDATE", | ||
); | ||
} catch (error) { | ||
if (error instanceof UnauthorizedError) return { error: "Unauthorized" }; | ||
console.log(`ERROR`, error); | ||
return { error: "Failed to update document." }; | ||
} | ||
|
||
revalidatePath(`/documents/${data.id}`); | ||
return { data: result }; | ||
}; | ||
|
||
export const updateDocument = createSafeAction(UpdateDocument, handler); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"use client"; | ||
|
||
import { PropsWithChildren } from "react"; | ||
|
||
const PublicLayout = ({ children }: PropsWithChildren) => { | ||
return <div className="h-full dark:bg-[#1F1F1F]">{children}</div>; | ||
}; | ||
|
||
export default PublicLayout; |
65 changes: 65 additions & 0 deletions
65
apps/worxpace/src/app/(platform)/(public)/preview/d/[documentId]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
"use client"; | ||
|
||
import { useMemo } from "react"; | ||
import dynamic from "next/dynamic"; | ||
import { notFound } from "next/navigation"; | ||
|
||
import type { Document } from "@acme/prisma"; | ||
import { Cover } from "@acme/ui/components"; | ||
import { useFetch } from "@acme/ui/hooks"; | ||
import { cn } from "@acme/ui/lib"; | ||
|
||
import { getDocument } from "~/app/(platform)/_functions"; | ||
import { ToolbarSkeleton } from "~/app/(platform)/(tools)/documents/[documentId]/_component/toolbar"; | ||
import { theme } from "~/constants/theme"; | ||
|
||
interface Params { | ||
params: { | ||
documentId: string; | ||
}; | ||
} | ||
|
||
const DocumentPage = ({ params: { documentId } }: Params) => { | ||
const { | ||
data: document, | ||
isLoading, | ||
error, | ||
} = useFetch<Document>( | ||
async () => await getDocument(documentId, true), | ||
{ | ||
onSuccess: (data) => console.log(`fetched data`, data), | ||
onError: (e) => console.log(e), | ||
}, | ||
[documentId], | ||
); | ||
/** Block Note Editor */ | ||
const BlockNoteEditor = useMemo( | ||
() => dynamic(() => import("~/components/block-editor"), { ssr: false }), | ||
[], | ||
); | ||
|
||
if (error) return notFound(); | ||
if (!document || isLoading) return <ToolbarSkeleton />; | ||
return ( | ||
<div className="pb-40 dark:bg-[#1F1F1F]"> | ||
<Cover preview url={document.coverImage} /> | ||
<div className="mx-auto md:max-w-3xl lg:max-w-4xl"> | ||
<div className="group relative pl-[54px]"> | ||
{!!document.icon && <p className="pt-6 text-6xl">{document.icon}</p>} | ||
<div | ||
className={cn( | ||
theme.flex.gap1, | ||
"py-4 opacity-0 group-hover:opacity-100", | ||
)} | ||
/> | ||
<div className="break-words pb-[11.5px] text-5xl font-bold text-[#3F3F3F] outline-none dark:text-[#CFCFCF]"> | ||
{document.title} | ||
</div> | ||
</div> | ||
<BlockNoteEditor editable={false} initialContent={document.content} /> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default DocumentPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.