@bbki.ng/site 2.0.17 → 2.0.18

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 CHANGED
@@ -1,5 +1,7 @@
1
1
  # @bbki.ng/site
2
2
 
3
+ ## 2.0.18
4
+
3
5
  ## 2.0.17
4
6
 
5
7
  ## 2.0.16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbki.ng/site",
3
- "version": "2.0.17",
3
+ "version": "2.0.18",
4
4
  "description": "code behind bbki.ng",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/blog/app.tsx CHANGED
@@ -26,6 +26,7 @@ import { PluginInit } from "@/components/plugin/PluginInit";
26
26
  import { BBContext } from "@/context/bbcontext";
27
27
  import { PluginContentPage } from "@/components/plugin/PluginContentPage";
28
28
  import { PluginRoutes } from "@/components/plugin/PluginRoutes";
29
+ import {useClipboardToPost} from "@/hooks/use_clipboard_to_post";
29
30
 
30
31
  const Layout = () => {
31
32
  const { isLoading, isFontLoading } = useContext(GlobalLoadingContext);
@@ -62,7 +63,10 @@ const TagsResultInMidCol = threeColWrapper(TagsResult);
62
63
  const CoverInMidCol = threeColWrapper(Cover);
63
64
 
64
65
  export const App = () => {
65
- return (
66
+
67
+ useClipboardToPost();
68
+
69
+ return (
66
70
  <SWR>
67
71
  {/*<EffectContextProvider>*/}
68
72
  <HotKeyNav>
@@ -0,0 +1,22 @@
1
+ import { ContextMenuItem } from "@bbki.ng/components";
2
+ import React from "react";
3
+ import {useAuthedStringPost} from "@/hooks/use_authed_string_post";
4
+
5
+ export const PostMenuItem = () => {
6
+
7
+ const post = useAuthedStringPost();
8
+
9
+ const postFromClipboard = () => {
10
+ navigator.clipboard
11
+ .readText()
12
+ .then(post);
13
+ }
14
+
15
+ return (
16
+ <ContextMenuItem onClick={postFromClipboard}
17
+ inset
18
+ >
19
+ post from clipboard
20
+ </ContextMenuItem>
21
+ );
22
+ };
@@ -13,6 +13,7 @@ import { ViewSourceMenuItem } from "@/components/app_ctx_menu/ViewSourceMenuItem
13
13
  import { PluginsMenuItem } from "@/components/plugin/PluginsMenuItem";
14
14
  import { PluginManager } from "@/plugin/PluginManager";
15
15
  import { PluginEvent } from "@/plugin/PluginEvent";
16
+ import {PostMenuItem} from "@/components/app_ctx_menu/PostMenuItem";
16
17
 
17
18
  export const AppCtxMenu = (props: { children: ReactElement }) => {
18
19
  const [showPluginEntry, setShowPluginEntry] = React.useState(false);
@@ -35,6 +36,7 @@ export const AppCtxMenu = (props: { children: ReactElement }) => {
35
36
  <ContextMenuContent className="w-256">
36
37
  <LoginMenuItem />
37
38
  <ViewSourceMenuItem />
39
+ <PostMenuItem />
38
40
  {/*{showPluginEntry && <PluginsMenuItem />}*/}
39
41
  </ContextMenuContent>
40
42
  </ContextMenu>
@@ -0,0 +1,42 @@
1
+ import {useSWRConfig} from "swr";
2
+ import {useAuthed} from "@/hooks/use_authed";
3
+ import {useContext} from "react";
4
+ import {GlobalLoadingContext} from "@/context/global_loading_state_provider";
5
+ import {usePost} from "@/hooks/use_post";
6
+ import {splitPost} from "@/utils";
7
+ import {API} from "@/constants/routes";
8
+
9
+ export const useAuthedStringPost = () => {
10
+ const { mutate } = useSWRConfig();
11
+
12
+ const isKing = useAuthed();
13
+
14
+ const { setIsLoading } = useContext(GlobalLoadingContext);
15
+
16
+ const post = usePost();
17
+
18
+ return (content: string) => {
19
+ if (!content) {
20
+ return;
21
+ }
22
+
23
+ if (!isKing) {
24
+ return;
25
+ }
26
+
27
+ const postObj = splitPost(content);
28
+ if (!postObj?.content || !postObj?.title) {
29
+ return;
30
+ }
31
+
32
+ setIsLoading(true);
33
+
34
+ post(postObj.title, postObj.content)
35
+ .then((r) => {
36
+ mutate(API.POSTS).then();
37
+ })
38
+ .finally(() => {
39
+ setIsLoading(false);
40
+ });
41
+ }
42
+ }
@@ -5,6 +5,7 @@ export const useClipboardContent = () => {
5
5
 
6
6
  React.useEffect(() => {
7
7
  const handlePaste = (event: ClipboardEvent) => {
8
+
8
9
  if (event.clipboardData) {
9
10
  setClipboardContent(event.clipboardData.getData("text/plain"));
10
11
  }
@@ -17,5 +18,7 @@ export const useClipboardContent = () => {
17
18
  };
18
19
  }, []);
19
20
 
21
+ console.log(clipboardContent);
22
+
20
23
  return clipboardContent;
21
24
  }
@@ -5,7 +5,6 @@ import { usePosts } from "@/hooks/use_posts";
5
5
  import { CenterLinkList } from "@/components";
6
6
  import { useAuthed } from "@/hooks/use_authed";
7
7
  import { useFile2Post } from "@/hooks/use_file_to_post";
8
- import { DelayFadeIn } from "@/components/DelayFadeIn/DelayFadeIn";
9
8
  import { useSafeArticleLoading } from "@/hooks/use_safe_loading";
10
9
  import {useClipboardToPost} from "@/hooks/use_clipboard_to_post";
11
10
 
@@ -41,13 +40,8 @@ export default (props: TxtProps) => {
41
40
  const reader = useFile2Post();
42
41
  const isKing = useAuthed();
43
42
 
44
- useClipboardToPost();
45
-
46
43
  return (
47
44
  <DropZone onDrop={reader} disabled={!isKing}>
48
- {isKing && (
49
- <div contentEditable={true} className="p-2 focus-visible:outline-0" />
50
- )}
51
45
  <Posts {...props} />
52
46
  </DropZone>
53
47
  );
@@ -173,6 +173,18 @@ export const confirm = (message: string, exec: () => void) => {
173
173
  });
174
174
  };
175
175
 
176
+ export const splitPost= (wholeString: string ) => {
177
+ const firstLine = wholeString ? wholeString .split("\n")[0] : "";
178
+ const title = firstLine ? firstLine.trim() : "";
179
+
180
+ const restContent = wholeString ? wholeString.slice(title.length).trim() : "";
181
+
182
+ return {
183
+ title,
184
+ content: restContent,
185
+ };
186
+ }
187
+
176
188
  export const changeFont = (type: FontType) => {
177
189
  const rootDiv = document.getElementById("root");
178
190
  if (rootDiv == null) {