From 07d9649b22eb8e3da6a09dded75167e9a068222a Mon Sep 17 00:00:00 2001 From: boojack Date: Tue, 26 Jul 2022 21:24:52 +0800 Subject: [PATCH] chore: add visibility selector --- web/src/components/Memo.tsx | 4 +-- web/src/components/MemoCardDialog.tsx | 39 +++++++++++++-------------- web/src/less/memo-card-dialog.less | 3 +-- web/src/types/modules/memo.d.ts | 2 +- 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/web/src/components/Memo.tsx b/web/src/components/Memo.tsx index e6ef48f2..56fdd98c 100644 --- a/web/src/components/Memo.tsx +++ b/web/src/components/Memo.tsx @@ -175,8 +175,8 @@ const Memo: React.FC = (props: Props) => { PINNED - - PUBLIC + + {memo.visibility}
diff --git a/web/src/components/MemoCardDialog.tsx b/web/src/components/MemoCardDialog.tsx index 209b39d8..962d6e03 100644 --- a/web/src/components/MemoCardDialog.tsx +++ b/web/src/components/MemoCardDialog.tsx @@ -9,6 +9,7 @@ import { showDialog } from "./Dialog"; import Image from "./Image"; import { formatMemoContent } from "./Memo"; import "../less/memo-card-dialog.less"; +import Selector from "./common/Selector"; interface LinkedMemo extends Memo { createdAtStr: string; @@ -26,6 +27,11 @@ const MemoCardDialog: React.FC = (props: Props) => { const [linkMemos, setLinkMemos] = useState([]); const [linkedMemos, setLinkedMemos] = useState([]); const imageUrls = Array.from(memo.content.match(IMAGE_URL_REG) ?? []).map((s) => s.replace(IMAGE_URL_REG, "$1")); + const visibilityList = [ + { text: "PUBLIC", value: "PUBLIC" }, + { text: "PROTECTED", value: "PROTECTED" }, + { text: "PRIVATE", value: "PRIVATE" }, + ]; useEffect(() => { const fetchLinkedMemos = async () => { @@ -98,25 +104,16 @@ const MemoCardDialog: React.FC = (props: Props) => { setMemo(memo); }, []); - const handleEditMemoBtnClick = useCallback(() => { + const handleEditMemoBtnClick = () => { props.destroy(); editorStateService.setEditMemoWithId(memo.id); - }, [memo.id]); - - const handlePinClick = async () => { - if (memo.pinned) { - await memoService.unpinMemo(memo.id); - } else { - await memoService.pinMemo(memo.id); - } - setMemo({ - ...memo, - pinned: !memo.pinned, - }); }; - const handleVisibilityClick = async () => { - const visibility = memo.visibility === "PRIVATE" ? "PUBLIC" : "PRIVATE"; + const handleVisibilitySelectorChange = async (visibility: Visibility) => { + if (memo.visibility === visibility) { + return; + } + await memoService.patchMemo({ id: memo.id, visibility: visibility, @@ -135,12 +132,12 @@ const MemoCardDialog: React.FC = (props: Props) => {
<> - - + handleVisibilitySelectorChange(value as Visibility)} + /> diff --git a/web/src/less/memo-card-dialog.less b/web/src/less/memo-card-dialog.less index a71e07ce..29f14606 100644 --- a/web/src/less/memo-card-dialog.less +++ b/web/src/less/memo-card-dialog.less @@ -15,8 +15,7 @@ } > .header-container { - .flex(row, space-between, center); - @apply w-full h-auto pb-0 my-0; + @apply flex flex-row justify-between items-center w-full h-auto z-10 pb-0 my-0; > .time-text { @apply text-sm text-gray-500 font-mono; diff --git a/web/src/types/modules/memo.d.ts b/web/src/types/modules/memo.d.ts index 867cb794..0056fad7 100644 --- a/web/src/types/modules/memo.d.ts +++ b/web/src/types/modules/memo.d.ts @@ -1,6 +1,6 @@ type MemoId = number; -type Visibility = "PUBLIC" | "PRIVATE"; +type Visibility = "PUBLIC" | "PROTECTED" | "PRIVATE"; interface Memo { id: MemoId;