@bbki.ng/site 2.0.9 → 2.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/package.json +1 -1
- package/src/blog/app.tsx +2 -5
- package/src/blog/components/app_ctx_menu/index.tsx +1 -1
- package/src/blog/hooks/use_clipboard_content.ts +21 -0
- package/src/blog/hooks/use_clipboard_to_post.ts +40 -0
- package/src/blog/pages/cover/index.tsx +4 -4
- package/src/blog/pages/extensions/txt/index.tsx +3 -0
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/blog/app.tsx
CHANGED
|
@@ -67,14 +67,11 @@ export const App = () => {
|
|
|
67
67
|
{/*<EffectContextProvider>*/}
|
|
68
68
|
<HotKeyNav>
|
|
69
69
|
<BBContext>
|
|
70
|
-
|
|
70
|
+
{/*<PluginInit>*/}
|
|
71
71
|
<Routes>
|
|
72
72
|
<Route path="/" element={<Layout />}>
|
|
73
73
|
<Route index element={<CoverInMidCol />} />
|
|
74
74
|
|
|
75
|
-
<Route path="/projects" element={<ProjectsInMidCol />} />
|
|
76
|
-
<Route path="/projects/:id" element={<PhotoProjects />} />
|
|
77
|
-
|
|
78
75
|
<Route path="blog" element={<ContentInMidCol />} />
|
|
79
76
|
<Route path="blog/:title" element={<ArticleInMidCol />} />
|
|
80
77
|
<Route path="blog/:title/:id" element={<PhotoProjects />} />
|
|
@@ -93,7 +90,7 @@ export const App = () => {
|
|
|
93
90
|
</Route>
|
|
94
91
|
<Route path="*" element={<NotFound />} />
|
|
95
92
|
</Routes>
|
|
96
|
-
|
|
93
|
+
{/*</PluginInit>*/}
|
|
97
94
|
</BBContext>
|
|
98
95
|
</HotKeyNav>
|
|
99
96
|
{/*</EffectContextProvider>*/}
|
|
@@ -35,7 +35,7 @@ export const AppCtxMenu = (props: { children: ReactElement }) => {
|
|
|
35
35
|
<ContextMenuContent className="w-256">
|
|
36
36
|
<LoginMenuItem />
|
|
37
37
|
<ViewSourceMenuItem />
|
|
38
|
-
{showPluginEntry && <PluginsMenuItem />}
|
|
38
|
+
{/*{showPluginEntry && <PluginsMenuItem />}*/}
|
|
39
39
|
</ContextMenuContent>
|
|
40
40
|
</ContextMenu>
|
|
41
41
|
);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
export const useClipboardContent = () => {
|
|
4
|
+
const [clipboardContent, setClipboardContent] = React.useState<string | null>(null);
|
|
5
|
+
|
|
6
|
+
React.useEffect(() => {
|
|
7
|
+
const handlePaste = (event: ClipboardEvent) => {
|
|
8
|
+
if (event.clipboardData) {
|
|
9
|
+
setClipboardContent(event.clipboardData.getData("text/plain"));
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
document.addEventListener("paste", handlePaste);
|
|
14
|
+
|
|
15
|
+
return () => {
|
|
16
|
+
document.removeEventListener("paste", handlePaste);
|
|
17
|
+
};
|
|
18
|
+
}, []);
|
|
19
|
+
|
|
20
|
+
return clipboardContent;
|
|
21
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {useClipboardContent} from "@/hooks/use_clipboard_content";
|
|
2
|
+
import {useSWRConfig} from "swr";
|
|
3
|
+
import {useContext, useEffect} from "react";
|
|
4
|
+
import {GlobalLoadingContext} from "@/context/global_loading_state_provider";
|
|
5
|
+
import {usePost} from "@/hooks/use_post";
|
|
6
|
+
import {API} from "@/constants/routes";
|
|
7
|
+
|
|
8
|
+
export const useClipboardToPost = () => {
|
|
9
|
+
const clipboardContent = useClipboardContent();
|
|
10
|
+
|
|
11
|
+
const { mutate } = useSWRConfig();
|
|
12
|
+
|
|
13
|
+
const { setIsLoading } = useContext(GlobalLoadingContext);
|
|
14
|
+
|
|
15
|
+
const post = usePost();
|
|
16
|
+
|
|
17
|
+
const firstLine = clipboardContent ? clipboardContent.split("\n")[0] : "";
|
|
18
|
+
const title = firstLine ? firstLine.trim() : "";
|
|
19
|
+
|
|
20
|
+
const restContent = clipboardContent ? clipboardContent.slice(title.length).trim() : "";
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (!restContent || !title) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
setIsLoading(true);
|
|
29
|
+
|
|
30
|
+
post(title, restContent)
|
|
31
|
+
.then((r) => {
|
|
32
|
+
mutate(API.POSTS).then();
|
|
33
|
+
})
|
|
34
|
+
.finally(() => {
|
|
35
|
+
setIsLoading(false);
|
|
36
|
+
});
|
|
37
|
+
}, [title, restContent]);
|
|
38
|
+
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
@@ -13,10 +13,10 @@ export const Cover = (props: { className: string }) => {
|
|
|
13
13
|
<CenterLinkList
|
|
14
14
|
className="select-none"
|
|
15
15
|
links={[
|
|
16
|
-
{
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
},
|
|
16
|
+
// {
|
|
17
|
+
// to: "/projects",
|
|
18
|
+
// name: "cd ./projects",
|
|
19
|
+
// },
|
|
20
20
|
{
|
|
21
21
|
to: "/blog",
|
|
22
22
|
name: "cd ./blog",
|
|
@@ -7,6 +7,7 @@ import { useAuthed } from "@/hooks/use_authed";
|
|
|
7
7
|
import { useFile2Post } from "@/hooks/use_file_to_post";
|
|
8
8
|
import { DelayFadeIn } from "@/components/DelayFadeIn/DelayFadeIn";
|
|
9
9
|
import { useSafeArticleLoading } from "@/hooks/use_safe_loading";
|
|
10
|
+
import {useClipboardToPost} from "@/hooks/use_clipboard_to_post";
|
|
10
11
|
|
|
11
12
|
type TxtProps = {
|
|
12
13
|
title?: string;
|
|
@@ -40,6 +41,8 @@ export default (props: TxtProps) => {
|
|
|
40
41
|
const reader = useFile2Post();
|
|
41
42
|
const isKing = useAuthed();
|
|
42
43
|
|
|
44
|
+
useClipboardToPost();
|
|
45
|
+
|
|
43
46
|
return (
|
|
44
47
|
<DropZone onDrop={reader} disabled={!isKing}>
|
|
45
48
|
<Posts {...props} />
|