From 04c0f4755929bfe02ec09e7a2dc9db91e9fe186b Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 21 Jul 2023 21:27:26 +0800 Subject: [PATCH] feat: add inputs for og metadata --- web/src/components/CreateShortcutDialog.tsx | 151 ++++++++++++++++---- web/src/types/modules/shortcut.d.ts | 9 ++ 2 files changed, 129 insertions(+), 31 deletions(-) diff --git a/web/src/components/CreateShortcutDialog.tsx b/web/src/components/CreateShortcutDialog.tsx index 8099a25..5f6f3c6 100644 --- a/web/src/components/CreateShortcutDialog.tsx +++ b/web/src/components/CreateShortcutDialog.tsx @@ -29,9 +29,15 @@ const CreateShortcutDialog: React.FC = (props: Props) => { description: "", visibility: "PRIVATE", tags: [], + openGraphMetadata: { + title: "", + description: "", + image: "", + }, }, }); const [showDescriptionAndTag, setShowDescriptionAndTag] = useState(false); + const [showOpenGraphMetadata, setShowOpenGraphMetadata] = useState(false); const [tag, setTag] = useState(""); const requestState = useLoading(false); const isCreating = isUndefined(shortcutId); @@ -47,12 +53,10 @@ const CreateShortcutDialog: React.FC = (props: Props) => { link: shortcut.link, description: shortcut.description, visibility: shortcut.visibility, + openGraphMetadata: shortcut.openGraphMetadata, }), }); setTag(shortcut.tags.join(" ")); - if (shortcut.description !== "" || shortcut.tags.length > 0) { - setShowDescriptionAndTag(true); - } } } }, [shortcutId]); @@ -80,6 +84,14 @@ const CreateShortcutDialog: React.FC = (props: Props) => { }); }; + const handleVisibilityInputChange = (e: React.ChangeEvent) => { + setPartialState({ + shortcutCreate: Object.assign(state.shortcutCreate, { + visibility: e.target.value, + }), + }); + }; + const handleDescriptionInputChange = (e: React.ChangeEvent) => { setPartialState({ shortcutCreate: Object.assign(state.shortcutCreate, { @@ -93,10 +105,35 @@ const CreateShortcutDialog: React.FC = (props: Props) => { setTag(text); }; - const handleVisibilityInputChange = (e: React.ChangeEvent) => { + const handleOpenGraphMetadataImageChange = (e: React.ChangeEvent) => { setPartialState({ shortcutCreate: Object.assign(state.shortcutCreate, { - visibility: e.target.value, + openGraphMetadata: { + ...state.shortcutCreate.openGraphMetadata, + image: e.target.value, + }, + }), + }); + }; + + const handleOpenGraphMetadataTitleChange = (e: React.ChangeEvent) => { + setPartialState({ + shortcutCreate: Object.assign(state.shortcutCreate, { + openGraphMetadata: { + ...state.shortcutCreate.openGraphMetadata, + title: e.target.value, + }, + }), + }); + }; + + const handleOpenGraphMetadataDescriptionChange = (e: React.ChangeEvent) => { + setPartialState({ + shortcutCreate: Object.assign(state.shortcutCreate, { + openGraphMetadata: { + ...state.shortcutCreate.openGraphMetadata, + description: e.target.value, + }, }), }); }; @@ -116,6 +153,7 @@ const CreateShortcutDialog: React.FC = (props: Props) => { description: state.shortcutCreate.description, visibility: state.shortcutCreate.visibility, tags: tag.split(" "), + openGraphMetadata: state.shortcutCreate.openGraphMetadata, }); } else { await shortcutService.createShortcut({ @@ -144,7 +182,7 @@ const CreateShortcutDialog: React.FC = (props: Props) => { -
+
Name * @@ -187,33 +225,84 @@ const CreateShortcutDialog: React.FC = (props: Props) => {

Optional -
setShowDescriptionAndTag(!showDescriptionAndTag)} - > - Description and tags - +
+
setShowDescriptionAndTag(!showDescriptionAndTag)} + > + Description and tags + +
+ {showDescriptionAndTag && ( +
+
+ Description + +
+
+ Tags + +
+
+ )}
- {showDescriptionAndTag && ( - <> -
- Description - +
+
setShowOpenGraphMetadata(!showOpenGraphMetadata)} + > + Social media metadata + +
+ {showOpenGraphMetadata && ( +
+
+ Image URL + +
+
+ Title + +
+
+ Description + +
-
- Tags - -
- - )} + )} +