-
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.
feat(draft): develop draft create, save and publish action
- Loading branch information
1 parent
e2720d5
commit 39606ac
Showing
16 changed files
with
9,655 additions
and
1,946 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
"use client"; | ||
import "@benjamin/ui/benjamin-ui-global.css"; | ||
import { SnackbarProvider } from "notistack"; | ||
|
||
export default function RootLayout({ | ||
children, | ||
}: Readonly<{ | ||
children: React.ReactNode; | ||
}>) { | ||
return <main className="px-4 py-6">{children}</main>; | ||
return ( | ||
<SnackbarProvider | ||
preventDuplicate | ||
autoHideDuration={2000} | ||
anchorOrigin={{ vertical: "top", horizontal: "center" }} | ||
> | ||
<main className="px-4 py-6">{children}</main>; | ||
</SnackbarProvider> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,3 +1,32 @@ | ||
"use client"; | ||
import { useCreateDraft } from "@/server/post"; | ||
import { Button } from "@benjamin/ui"; | ||
import { Loader2 } from "lucide-react"; | ||
import { useRouter } from "next/navigation"; | ||
|
||
export default function Home() { | ||
return <div></div>; | ||
const { mutateAsync: createDraftApi, isPending } = useCreateDraft(); | ||
|
||
const router = useRouter(); | ||
|
||
const handlePublish = async () => { | ||
try { | ||
const draftData = await createDraftApi(); | ||
router.push(`/editor/${draftData.id}`); | ||
} catch (err) { | ||
// todo | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="w-content mx-auto py-6 px-3 flex"> | ||
<Button onClick={handlePublish} disabled={isPending}> | ||
{isPending && <Loader2 className="mr-2 h-4 w-4 animate-spin" />} | ||
发文章 | ||
</Button> | ||
<Button className="mx-5">管理文章</Button> | ||
<Button>管理标签</Button> | ||
<Button className="mx-5">管理草稿</Button> | ||
</div> | ||
); | ||
} |
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,2 @@ | ||
export { EditorStoreProvider } from "./editorProvider"; | ||
export { ReactQueryProvider } from "./queryProvider"; |
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,43 @@ | ||
"use client"; | ||
import { | ||
QueryClient, | ||
QueryClientProvider, | ||
isServer, | ||
} from "@tanstack/react-query"; | ||
import { ReactQueryDevtools } from "@tanstack/react-query-devtools"; | ||
import { ReactQueryStreamedHydration } from "@tanstack/react-query-next-experimental"; | ||
import * as React from "react"; | ||
|
||
function makeQueryClient() { | ||
return new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
staleTime: 60 * 1000, | ||
}, | ||
}, | ||
}); | ||
} | ||
|
||
let browserQueryClient: QueryClient | undefined = undefined; | ||
|
||
function getQueryClient() { | ||
if (isServer) { | ||
return makeQueryClient(); | ||
} else { | ||
if (!browserQueryClient) browserQueryClient = makeQueryClient(); | ||
return browserQueryClient; | ||
} | ||
} | ||
|
||
export function ReactQueryProvider(props: { children: React.ReactNode }) { | ||
const queryClient = getQueryClient(); | ||
|
||
return ( | ||
<QueryClientProvider client={queryClient}> | ||
<ReactQueryStreamedHydration> | ||
{props.children} | ||
</ReactQueryStreamedHydration> | ||
<ReactQueryDevtools initialIsOpen={false} /> | ||
</QueryClientProvider> | ||
); | ||
} |
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,2 @@ | ||
export { useInfiniteQueryPost } from "./post/"; | ||
export { client } from "./request/"; |
Oops, something went wrong.