mirror of
https://github.com/linsa-io/linsa.git
synced 2026-01-12 12:20:23 +01:00
delete empty page
This commit is contained in:
@@ -9,6 +9,7 @@ import { Button } from "@/components/ui/button"
|
|||||||
import { LaIcon } from "@/components/custom/la-icon"
|
import { LaIcon } from "@/components/custom/la-icon"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
|
import { useEffect } from "react"
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
@@ -57,7 +58,6 @@ export const PageSection: React.FC<{ pathname?: string }> = ({ pathname }) => {
|
|||||||
const [show, setShow] = useAtom(pageShowAtom)
|
const [show, setShow] = useAtom(pageShowAtom)
|
||||||
|
|
||||||
const pageCount = me?.root.personalPages?.length || 0
|
const pageCount = me?.root.personalPages?.length || 0
|
||||||
// const isActive = pathname ? pathname.startsWith("/pages") : false
|
|
||||||
const isActive = pathname === "/pages"
|
const isActive = pathname === "/pages"
|
||||||
|
|
||||||
if (!me) return null
|
if (!me) return null
|
||||||
|
|||||||
@@ -23,12 +23,44 @@ import { useRouter } from "next/navigation"
|
|||||||
|
|
||||||
const TITLE_PLACEHOLDER = "Untitled"
|
const TITLE_PLACEHOLDER = "Untitled"
|
||||||
|
|
||||||
|
const emptyPage = (page: PersonalPage): boolean => {
|
||||||
|
return (!page.title || page.title.trim() === "") && (!page.content || Object.keys(page.content).length === 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const deleteEmptyPage = (currentPageId: string | null) => {
|
||||||
|
const router = useRouter()
|
||||||
|
const { me } = useAccount({
|
||||||
|
root: {
|
||||||
|
personalPages: []
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleRouteChange = () => {
|
||||||
|
if (!currentPageId || !me?.root?.personalPages) return
|
||||||
|
|
||||||
|
const currentPage = me.root.personalPages.find(page => page?.id === currentPageId)
|
||||||
|
if (currentPage && emptyPage(currentPage)) {
|
||||||
|
const index = me.root.personalPages.findIndex(page => page?.id === currentPageId)
|
||||||
|
if (index !== -1) {
|
||||||
|
me.root.personalPages.splice(index, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
handleRouteChange()
|
||||||
|
}
|
||||||
|
}, [currentPageId, me, router])
|
||||||
|
}
|
||||||
|
|
||||||
export function PageDetailRoute({ pageId }: { pageId: string }) {
|
export function PageDetailRoute({ pageId }: { pageId: string }) {
|
||||||
const { me } = useAccount({ root: { personalLinks: [] } })
|
const { me } = useAccount({ root: { personalLinks: [] } })
|
||||||
const isMobile = useMedia("(max-width: 770px)")
|
const isMobile = useMedia("(max-width: 770px)")
|
||||||
const page = useCoState(PersonalPage, pageId as ID<PersonalPage>)
|
const page = useCoState(PersonalPage, pageId as ID<PersonalPage>)
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const confirm = useConfirm()
|
const confirm = useConfirm()
|
||||||
|
deleteEmptyPage(pageId)
|
||||||
|
|
||||||
const handleDelete = async () => {
|
const handleDelete = async () => {
|
||||||
const result = await confirm({
|
const result = await confirm({
|
||||||
|
|||||||
Reference in New Issue
Block a user