diff --git a/bun.lockb b/bun.lockb index 0549f2a5..4c75131e 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/web/components/routes/page/detail/PageDetailRoute.tsx b/web/components/routes/page/detail/PageDetailRoute.tsx index 191c5e96..a1bd5776 100644 --- a/web/components/routes/page/detail/PageDetailRoute.tsx +++ b/web/components/routes/page/detail/PageDetailRoute.tsx @@ -1,9 +1,8 @@ "use client" -import * as React from "react" +import React, { useCallback, useRef, useEffect } from "react" import { ID } from "jazz-tools" import { PersonalPage } from "@/lib/schema" -import { useCallback, useRef, useEffect } from "react" import { LAEditor, LAEditorRef } from "@/components/la-editor" import { Content, EditorContent, useEditor } from "@tiptap/react" import { StarterKit } from "@/components/la-editor/extensions/starter-kit" @@ -29,7 +28,6 @@ export function PageDetailRoute({ pageId }: { pageId: string }) { const isMobile = useMedia("(max-width: 770px)") const page = useCoState(PersonalPage, pageId as ID) const router = useRouter() - const confirm = useConfirm() const handleDelete = async () => { @@ -38,17 +36,11 @@ export function PageDetailRoute({ pageId }: { pageId: string }) { description: "Are you sure you want to delete this page?", confirmText: "Delete", cancelText: "Cancel", - cancelButton: { - variant: "outline" - }, - confirmButton: { - variant: "destructive" - } + cancelButton: { variant: "outline" }, + confirmButton: { variant: "destructive" } }) - if (result) { - if (!me?.root.personalPages) return - + if (result && me?.root.personalPages) { try { const index = me.root.personalPages.findIndex(item => item?.id === pageId) if (index === -1) { @@ -56,22 +48,11 @@ export function PageDetailRoute({ pageId }: { pageId: string }) { return } - toast.success("Page deleted.", { - position: "bottom-right", - description: ( - - {page?.title} has been deleted. - - ) - }) - me.root.personalPages.splice(index, 1) - - // push without history + toast.success("Page deleted.", { position: "bottom-right" }) router.replace("/") } catch (error) { console.error("Delete operation fail", { error }) - return } } } @@ -82,48 +63,49 @@ export function PageDetailRoute({ pageId }: { pageId: string }) {
- +
- - {!isMobile && ( -
-
-
- Page actions -
- -
- { - page.topic = topic - page.updatedAt = new Date() - }} - variant="ghost" - className="-ml-1.5" - renderSelectedText={() => ( - {page.topic?.prettyName || "Select a topic"} - )} - /> - -
-
-
- )} + {!isMobile && }
) } -export const DetailPageForm = ({ page }: { page: PersonalPage }) => { +const SidebarActions = ({ page, handleDelete }: { page: PersonalPage; handleDelete: () => void }) => ( +
+
+
+ Page actions +
+
+
+ { + page.topic = topic + page.updatedAt = new Date() + }} + variant="ghost" + className="-ml-1.5" + renderSelectedText={() => {page.topic?.prettyName || "Select a topic"}} + /> +
+
+ +
+
+
+
+) + +const DetailPageForm = ({ page }: { page: PersonalPage }) => { const { me } = useAccount() const titleEditorRef = useRef(null) const contentEditorRef = useRef(null) - const isTitleInitialMount = useRef(true) const isContentInitialMount = useRef(true) @@ -132,7 +114,6 @@ export const DetailPageForm = ({ page }: { page: PersonalPage }) => { isContentInitialMount.current = false return } - model.content = content model.updatedAt = new Date() } @@ -143,13 +124,10 @@ export const DetailPageForm = ({ page }: { page: PersonalPage }) => { return } - const personalPages = me?.root?.personalPages?.toJSON() || [] const newTitle = editor.getText() - - // Only update if the title has actually changed if (newTitle !== page.title) { + const personalPages = me?.root?.personalPages?.toJSON() || [] const slug = generateUniqueSlug(personalPages, page.slug || "") - page.title = newTitle page.slug = slug page.updatedAt = new Date() @@ -181,7 +159,6 @@ export const DetailPageForm = ({ page }: { page: PersonalPage }) => { } break } - return false }, []) @@ -198,7 +175,6 @@ export const DetailPageForm = ({ page }: { page: PersonalPage }) => { titleEditorRef.current?.commands.focus("end") return true } - return false }, []) @@ -217,9 +193,7 @@ export const DetailPageForm = ({ page }: { page: PersonalPage }) => { strike: false, focus: false, gapcursor: false, - placeholder: { - placeholder: TITLE_PLACEHOLDER - } + placeholder: { placeholder: TITLE_PLACEHOLDER } }) ], editorProps: { diff --git a/web/components/routes/page/detail/header.tsx b/web/components/routes/page/detail/header.tsx index e66989fb..bb9b6afc 100644 --- a/web/components/routes/page/detail/header.tsx +++ b/web/components/routes/page/detail/header.tsx @@ -1,42 +1,43 @@ -"use client" - -import * as React from "react" +import React from "react" import { ContentHeader, SidebarToggleButton } from "@/components/custom/content-header" import { PersonalPage } from "@/lib/schema/personal-page" -import { useMedia } from "react-use" import { TopicSelector } from "@/components/custom/topic-selector" import { Button } from "@/components/ui/button" import { LaIcon } from "@/components/custom/la-icon" -export const DetailPageHeader = ({ page, handleDelete }: { page: PersonalPage; handleDelete: () => void }) => { - const isMobile = useMedia("(max-width: 770px)") +interface DetailPageHeaderProps { + page: PersonalPage + handleDelete: () => void + isMobile: boolean +} + +export const DetailPageHeader: React.FC = ({ page, handleDelete, isMobile }) => { + if (!isMobile) return null return ( - isMobile && ( - <> - -
- -
-
- -
- { - page.topic = topic - page.updatedAt = new Date() - }} - align="start" - variant="outline" - renderSelectedText={() => {page.topic?.prettyName || "Select a topic"}} - /> - + <> + +
+
- - ) +
+ +
+ { + page.topic = topic + page.updatedAt = new Date() + }} + align="start" + variant="outline" + renderSelectedText={() => {page.topic?.prettyName || "Select a topic"}} + /> + +
+ ) }