-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathResourceBookmark.tsx
More file actions
56 lines (52 loc) · 1.53 KB
/
ResourceBookmark.tsx
File metadata and controls
56 lines (52 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"use client";
import React from "react";
import { ResourceBookmarkable } from "./render-props/ResourceBookmarkable";
import { useSession } from "@/store/session.atom";
import { useLoginPopup } from "./app-login-popup";
import clsx from "clsx";
interface ResourceBookmarkProps {
resource_type: "ARTICLE" | "COMMENT";
resource_id: string;
}
const ResourceBookmark: React.FC<ResourceBookmarkProps> = ({
resource_type,
resource_id,
}) => {
const session = useSession();
const loginPopup = useLoginPopup();
return (
<ResourceBookmarkable
resource_type={resource_type}
resource_id={resource_id}
render={({ bookmarked, toggle }) => (
<button
onClick={() => {
if (!session?.user) {
loginPopup.show();
return;
}
toggle();
}}
className={clsx(
"transition-colors duration-300 flex cursor-pointer px-2 py-1 rounded-sm hover:bg-primary/20",
{ "bg-primary/20": bookmarked }
)}
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
strokeLinecap="round"
strokeLinejoin="round"
className={clsx("size-5 stroke-2 fill-transparent", {
"!stroke-current": !bookmarked,
"!fill-current": bookmarked,
})}
>
<path d="m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z" />
</svg>
</button>
)}
/>
);
};
export default ResourceBookmark;