@bbki.ng/site 1.4.2 → 1.5.0
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 +2 -0
- package/dev-dist/sw.js +1 -1
- package/package.json +1 -1
- package/src/components/Auth.tsx +17 -0
- package/src/components/ImageUploader.tsx +7 -3
- package/src/components/Img_ctx_menu/index.tsx +36 -0
- package/src/components/app_ctx_menu/LoginMenuItem.tsx +17 -1
- package/src/constants/index.ts +2 -0
- package/src/hooks/use_role.ts +19 -0
- package/src/hooks/use_supa_session.ts +1 -0
- package/src/pages/cover/index.tsx +1 -1
- package/src/pages/extensions/png/png_projects.tsx +22 -1
- package/src/types/supabase.ts +1 -0
- package/src/auth_required.tsx +0 -17
package/CHANGELOG.md
CHANGED
package/dev-dist/sw.js
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Role, useRole } from "@/hooks/use_role";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Navigate } from "react-router-dom";
|
|
4
|
+
|
|
5
|
+
export const Auth = (props: {
|
|
6
|
+
children: any;
|
|
7
|
+
shouldRedirect?: boolean;
|
|
8
|
+
role?: Role[];
|
|
9
|
+
}) => {
|
|
10
|
+
const myRole = useRole();
|
|
11
|
+
|
|
12
|
+
if (props.role && !props.role.includes(myRole)) {
|
|
13
|
+
return props.shouldRedirect ? <Navigate to={"/login"} /> : null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return props.children;
|
|
17
|
+
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import React, { useContext } from "react";
|
|
2
2
|
import { DropImage } from "@bbki.ng/components";
|
|
3
|
-
import { AuthRequired } from "@/auth_required";
|
|
4
3
|
import { useUploader } from "@/hooks/use_uploader";
|
|
5
4
|
import { ImageUploaderProps } from "@/types/upload";
|
|
6
5
|
import { GlobalLoadingContext } from "@/global_loading_state_provider";
|
|
6
|
+
import { Auth } from "@/components/Auth";
|
|
7
|
+
import { Role } from "@/hooks/use_role";
|
|
8
|
+
import { useParams } from "react-router-dom";
|
|
7
9
|
|
|
8
10
|
export const ImageUploader = (props: ImageUploaderProps) => {
|
|
9
11
|
const {
|
|
@@ -18,9 +20,11 @@ export const ImageUploader = (props: ImageUploaderProps) => {
|
|
|
18
20
|
|
|
19
21
|
const { setIsLoading } = useContext(GlobalLoadingContext);
|
|
20
22
|
const uploader = useUploader();
|
|
23
|
+
const isProjectOfQueen = projectName === "小乌鸦";
|
|
24
|
+
const role = isProjectOfQueen ? [Role.QUEEN, Role.KING] : [Role.KING];
|
|
21
25
|
|
|
22
26
|
return (
|
|
23
|
-
<
|
|
27
|
+
<Auth role={role}>
|
|
24
28
|
<DropImage
|
|
25
29
|
{...rest}
|
|
26
30
|
className="mb-256"
|
|
@@ -46,6 +50,6 @@ export const ImageUploader = (props: ImageUploaderProps) => {
|
|
|
46
50
|
>
|
|
47
51
|
{() => null}
|
|
48
52
|
</DropImage>
|
|
49
|
-
</
|
|
53
|
+
</Auth>
|
|
50
54
|
);
|
|
51
55
|
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ContextMenuItem,
|
|
3
|
+
ContextMenu,
|
|
4
|
+
ContextMenuContent,
|
|
5
|
+
ContextMenuTrigger,
|
|
6
|
+
} from "@bbki.ng/components";
|
|
7
|
+
import React, { ReactElement } from "react";
|
|
8
|
+
import { useParams } from "react-router-dom";
|
|
9
|
+
import { Auth } from "@/components/Auth";
|
|
10
|
+
import { Role } from "@/hooks/use_role";
|
|
11
|
+
import { confirm } from "@/utils";
|
|
12
|
+
|
|
13
|
+
export const ImgCtxMenu = (props: { children: ReactElement }) => {
|
|
14
|
+
const param = useParams();
|
|
15
|
+
const imgId = param.id;
|
|
16
|
+
const isImgOfQueen = imgId === "小乌鸦";
|
|
17
|
+
const role = isImgOfQueen ? [Role.QUEEN, Role.KING] : [Role.KING];
|
|
18
|
+
return (
|
|
19
|
+
<ContextMenu>
|
|
20
|
+
<ContextMenuTrigger>{props.children}</ContextMenuTrigger>
|
|
21
|
+
<Auth role={role}>
|
|
22
|
+
<ContextMenuContent>
|
|
23
|
+
<ContextMenuItem
|
|
24
|
+
onClick={() => {
|
|
25
|
+
confirm("确认删除?", () => {
|
|
26
|
+
console.log("delete");
|
|
27
|
+
});
|
|
28
|
+
}}
|
|
29
|
+
>
|
|
30
|
+
Delete
|
|
31
|
+
</ContextMenuItem>
|
|
32
|
+
</ContextMenuContent>
|
|
33
|
+
</Auth>
|
|
34
|
+
</ContextMenu>
|
|
35
|
+
);
|
|
36
|
+
};
|
|
@@ -8,13 +8,29 @@ import {
|
|
|
8
8
|
} from "@bbki.ng/components";
|
|
9
9
|
import React from "react";
|
|
10
10
|
import { useNavigate } from "react-router-dom";
|
|
11
|
+
import { supabase } from "@/constants";
|
|
12
|
+
import { toast } from "sonner";
|
|
11
13
|
|
|
12
14
|
export const LoginMenuItem = () => {
|
|
13
15
|
const sess = useSupabaseSession();
|
|
14
16
|
const nav = useNavigate();
|
|
15
17
|
|
|
16
18
|
if (sess?.user != null) {
|
|
17
|
-
return
|
|
19
|
+
return (
|
|
20
|
+
<>
|
|
21
|
+
<ContextMenuLabel inset>{sess?.user?.email ?? ""}</ContextMenuLabel>
|
|
22
|
+
<ContextMenuItem
|
|
23
|
+
inset
|
|
24
|
+
onClick={() => {
|
|
25
|
+
supabase.auth.signOut().then(() => {
|
|
26
|
+
toast.success("已退出登录");
|
|
27
|
+
});
|
|
28
|
+
}}
|
|
29
|
+
>
|
|
30
|
+
Logout
|
|
31
|
+
</ContextMenuItem>
|
|
32
|
+
</>
|
|
33
|
+
);
|
|
18
34
|
}
|
|
19
35
|
|
|
20
36
|
return (
|
package/src/constants/index.ts
CHANGED
|
@@ -8,9 +8,11 @@ export const SUPABASE: {
|
|
|
8
8
|
ANNO: string;
|
|
9
9
|
URL: string;
|
|
10
10
|
BB_KING_ID: string;
|
|
11
|
+
BB_QUEEN_ID: string;
|
|
11
12
|
} = {
|
|
12
13
|
ANNO: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImN2eHFtdXNmYXh3dXl2eXV1ZWNvIiwicm9sZSI6ImFub24iLCJpYXQiOjE2NDQ4MjkwNTEsImV4cCI6MTk2MDQwNTA1MX0.lg90OVR7s6tjbDamVaI9FR2M2fc6OVfsfGd4j9MXu3M",
|
|
13
14
|
URL: "https://cvxqmusfaxwuyvyuueco.supabase.co",
|
|
14
15
|
BB_KING_ID: "e6795b1d-7ee0-4afe-be63-796670848175",
|
|
16
|
+
BB_QUEEN_ID: "ca7d5130-2826-4bcb-86ad-6fab1fae8e3d",
|
|
15
17
|
};
|
|
16
18
|
export const supabase = createClient(SUPABASE.URL, SUPABASE.ANNO);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useSupabaseSession } from "@/hooks/use_supa_session";
|
|
2
|
+
|
|
3
|
+
export enum Role {
|
|
4
|
+
KING = "king",
|
|
5
|
+
QUEEN = "queen",
|
|
6
|
+
ANNO = "anno",
|
|
7
|
+
}
|
|
8
|
+
export const useRole = (): Role => {
|
|
9
|
+
const sess = useSupabaseSession();
|
|
10
|
+
if (sess?.isKing) {
|
|
11
|
+
return Role.KING;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (sess?.isQueen) {
|
|
15
|
+
return Role.QUEEN;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return Role.ANNO;
|
|
19
|
+
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { CenterLinkList } from "@/components";
|
|
3
|
-
import { ContextMenuDemo } from "@/demo/DemoMenu";
|
|
4
3
|
|
|
5
4
|
export const Cover = (props: { className: string }) => {
|
|
6
5
|
return (
|
|
7
6
|
<CenterLinkList
|
|
7
|
+
className="select-none"
|
|
8
8
|
links={[
|
|
9
9
|
{
|
|
10
10
|
to: "/projects",
|
|
@@ -6,6 +6,9 @@ import { imageFormatter } from "@/utils";
|
|
|
6
6
|
import { Gallery, Nav, Link } from "@bbki.ng/components";
|
|
7
7
|
import { usePaths } from "@/hooks";
|
|
8
8
|
import { ImageUploader } from "@/components/ImageUploader";
|
|
9
|
+
import classnames from "classnames";
|
|
10
|
+
import { ImageRenderer } from "@bbki.ng/components/lib";
|
|
11
|
+
import { ImgCtxMenu } from "@/components/Img_ctx_menu";
|
|
9
12
|
|
|
10
13
|
const ProjectDetail = () => {
|
|
11
14
|
const { id } = useParams();
|
|
@@ -17,6 +20,21 @@ const ProjectDetail = () => {
|
|
|
17
20
|
};
|
|
18
21
|
}, []);
|
|
19
22
|
|
|
23
|
+
const renderImage: ImageRenderer = (img, index, col) => {
|
|
24
|
+
return (
|
|
25
|
+
<ImgCtxMenu>
|
|
26
|
+
<div
|
|
27
|
+
className={classnames("mb-128", {
|
|
28
|
+
"md:mr-64": col === 0,
|
|
29
|
+
"md:ml-64": col !== 0,
|
|
30
|
+
})}
|
|
31
|
+
>
|
|
32
|
+
{img}
|
|
33
|
+
</div>
|
|
34
|
+
</ImgCtxMenu>
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
|
|
20
38
|
const renderUploader = () => (
|
|
21
39
|
<ImageUploader
|
|
22
40
|
onUploadFinish={refresh}
|
|
@@ -27,7 +45,10 @@ const ProjectDetail = () => {
|
|
|
27
45
|
|
|
28
46
|
return (
|
|
29
47
|
<>
|
|
30
|
-
<Gallery
|
|
48
|
+
<Gallery
|
|
49
|
+
images={projects.images.map(imageFormatter)}
|
|
50
|
+
imageRenderer={renderImage}
|
|
51
|
+
>
|
|
31
52
|
{renderUploader()}
|
|
32
53
|
</Gallery>
|
|
33
54
|
</>
|
package/src/types/supabase.ts
CHANGED
package/src/auth_required.tsx
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { Navigate } from "react-router-dom";
|
|
3
|
-
import { useSupabaseSession } from "@/hooks/use_supa_session";
|
|
4
|
-
|
|
5
|
-
export const AuthRequired = (props: {
|
|
6
|
-
children: any;
|
|
7
|
-
shouldRedirect?: boolean;
|
|
8
|
-
shouldBeKing?: boolean;
|
|
9
|
-
}) => {
|
|
10
|
-
const { access_token: token, isKing } = useSupabaseSession() || {};
|
|
11
|
-
|
|
12
|
-
if (!token || (props.shouldBeKing && !isKing)) {
|
|
13
|
-
return props.shouldRedirect ? <Navigate to={"/login"} /> : null;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return props.children;
|
|
17
|
-
};
|