@bbki.ng/site 1.5.6 → 1.5.8

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,9 @@
1
1
  # @bbki.ng/site
2
2
 
3
+ ## 1.5.8
4
+
5
+ ## 1.5.7
6
+
3
7
  ## 1.5.6
4
8
 
5
9
  ## 1.5.5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbki.ng/site",
3
- "version": "1.5.6",
3
+ "version": "1.5.8",
4
4
  "description": "code behind bbki.ng",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -16,7 +16,7 @@
16
16
  "url": "git+https://github.com/bbbottle/bbki.ng.git"
17
17
  },
18
18
  "dependencies": {
19
- "@bbki.ng/components": "workspace:2.4.5",
19
+ "@bbki.ng/components": "workspace:2.4.7",
20
20
  "@supabase/supabase-js": "^1.35.4",
21
21
  "classnames": "2.3.1",
22
22
  "react": "^18.0.0",
@@ -28,7 +28,7 @@
28
28
  "swr": "^2.2.5"
29
29
  },
30
30
  "devDependencies": {
31
- "@bbki.ng/stylebase": "workspace:0.3.5",
31
+ "@bbki.ng/stylebase": "workspace:0.3.7",
32
32
  "@mdx-js/mdx": "2.0.0-next.9",
33
33
  "@mdx-js/react": "^1.6.22",
34
34
  "@mdx-js/rollup": "3.0.0",
@@ -3,29 +3,58 @@ import {
3
3
  ContextMenu,
4
4
  ContextMenuContent,
5
5
  ContextMenuTrigger,
6
+ ContextMenuLabel,
6
7
  } from "@bbki.ng/components";
7
- import React, { ReactElement } from "react";
8
+ import React, { ReactElement, useContext } from "react";
8
9
  import { useParams } from "react-router-dom";
9
10
  import { Auth } from "@/components/Auth";
10
11
  import { Role } from "@/hooks/use_role";
11
12
  import { confirm } from "@/utils";
13
+ import { ContextMenuSeparator } from "@bbki.ng/components";
14
+ import { useDelImg } from "@/hooks/use_del_img";
15
+ import { toast } from "sonner";
16
+ import { GlobalLoadingContext } from "@/global_loading_state_provider";
12
17
 
13
- export const ImgCtxMenu = (props: { children: ReactElement }) => {
18
+ export const ImgCtxMenu = (props: {
19
+ children: ReactElement;
20
+ name: string;
21
+ date: string;
22
+ width: number;
23
+ height: number;
24
+ id: number;
25
+ onRemoved?: () => Promise<void>;
26
+ }) => {
14
27
  const param = useParams();
28
+ const delImg = useDelImg();
15
29
  const imgId = param.id;
16
30
  const isImgOfQueen = imgId === "小乌鸦";
17
31
  const role = isImgOfQueen ? [Role.QUEEN, Role.KING] : [Role.KING];
32
+ const date = new Date(props.date).toLocaleString();
33
+ const { setIsLoading } = useContext(GlobalLoadingContext);
34
+
18
35
  return (
19
36
  <ContextMenu>
20
37
  <ContextMenuTrigger draggable={false}>
21
38
  {props.children}
22
39
  </ContextMenuTrigger>
23
40
  <Auth role={role}>
24
- <ContextMenuContent>
41
+ <ContextMenuContent className="w-256">
42
+ <ContextMenuLabel>{props.name}</ContextMenuLabel>
43
+ <ContextMenuItem disabled>
44
+ {props.width} * {props.height}
45
+ </ContextMenuItem>
46
+ <ContextMenuItem disabled>{date}</ContextMenuItem>
47
+ <ContextMenuSeparator />
25
48
  <ContextMenuItem
26
49
  onClick={() => {
27
- confirm("确认删除?", () => {
28
- console.log("delete");
50
+ confirm("确认删除?", async () => {
51
+ setIsLoading(true);
52
+ await delImg(props.id);
53
+ await props.onRemoved?.();
54
+ toast.success("删除成功", {
55
+ position: "top-center",
56
+ });
57
+ setIsLoading(false);
29
58
  });
30
59
  }}
31
60
  >
@@ -29,7 +29,7 @@ export const LoginMenuItem = () => {
29
29
  });
30
30
  }}
31
31
  >
32
- Logout
32
+ logout
33
33
  </ContextMenuItem>
34
34
  </>
35
35
  );
@@ -22,6 +22,7 @@ export const API = {
22
22
  UPLOAD_IMG: "upload",
23
23
  POST: "post",
24
24
  REMOVE_POST: "remove_post",
25
+ REMOVE_IMG: "remove_image",
25
26
  MOVIES: "movies",
26
27
  IMAGES: "images",
27
28
  BOOKS: "books",
@@ -0,0 +1,22 @@
1
+ import { useAuthedFetcher } from "@/hooks/use_authed_fetcher";
2
+ import { useCallback } from "react";
3
+ import { API } from "@/constants/routes";
4
+
5
+ export const useDelImg = () => {
6
+ const authedFetcher = useAuthedFetcher();
7
+
8
+ const req = useCallback(
9
+ async (url: string, { arg }: { arg: { id: number } }) => {
10
+ return authedFetcher(url, {
11
+ method: "POST",
12
+ body: JSON.stringify(arg),
13
+ });
14
+ },
15
+ [authedFetcher]
16
+ );
17
+
18
+ return useCallback(
19
+ (id: number) => req(API.REMOVE_IMG, { arg: { id } }),
20
+ [req]
21
+ );
22
+ };
@@ -3,8 +3,7 @@ import { MySuspense } from "@/components";
3
3
  import { useParams } from "react-router-dom";
4
4
  import { useProjects } from "@/hooks/use_projects";
5
5
  import { imageFormatter } from "@/utils";
6
- import { Gallery, Nav, Link } from "@bbki.ng/components";
7
- import { usePaths } from "@/hooks";
6
+ import { Gallery } from "@bbki.ng/components";
8
7
  import { ImageUploader } from "@/components/ImageUploader";
9
8
  import classnames from "classnames";
10
9
  import { ImageRenderer } from "@bbki.ng/components/lib";
@@ -21,8 +20,17 @@ const ProjectDetail = () => {
21
20
  }, []);
22
21
 
23
22
  const renderImage: ImageRenderer = (img, index, col) => {
23
+ const imgInfo = projects.images[index];
24
+
24
25
  return (
25
- <ImgCtxMenu>
26
+ <ImgCtxMenu
27
+ date={imgInfo.created_at}
28
+ name={imgInfo.title}
29
+ width={imgInfo.width}
30
+ height={imgInfo.height}
31
+ id={imgInfo.id}
32
+ onRemoved={refresh}
33
+ >
26
34
  <div
27
35
  className={classnames("mb-128 select-none", {
28
36
  "md:mr-64": col === 0,
package/vite.config.js CHANGED
@@ -60,7 +60,7 @@ export default defineConfig({
60
60
  "Logo.svg",
61
61
  ],
62
62
  devOptions: {
63
- enabled: true,
63
+ enabled: false,
64
64
  /* other options */
65
65
  },
66
66
  workbox: {