From b9026ad89ab2ee72a3ebfc2c3a05b5da58b0d21e Mon Sep 17 00:00:00 2001 From: Tristan Yang Date: Thu, 7 Nov 2024 11:28:26 +0800 Subject: [PATCH] refactor: widget setting --- src/routes/setting/Widget.tsx | 194 -------------------- src/routes/setting/Widget/ConfigDetails.tsx | 133 ++++++++++++++ src/routes/setting/Widget/index.tsx | 76 ++++++++ 3 files changed, 209 insertions(+), 194 deletions(-) delete mode 100644 src/routes/setting/Widget.tsx create mode 100644 src/routes/setting/Widget/ConfigDetails.tsx create mode 100644 src/routes/setting/Widget/index.tsx diff --git a/src/routes/setting/Widget.tsx b/src/routes/setting/Widget.tsx deleted file mode 100644 index 6befae0d..00000000 --- a/src/routes/setting/Widget.tsx +++ /dev/null @@ -1,194 +0,0 @@ -// import { useState, MouseEvent } from "react"; -// import dayjs from "dayjs"; -import { useTranslation } from "react-i18next"; -import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"; -import { vscDarkPlus } from "react-syntax-highlighter/dist/esm/styles/prism"; - -import IconQuestion from "@/assets/icons/question.svg"; -import { useAppSelector } from "../../app/store"; -import Button from "../../components/styled/Button"; -import Input from "../../components/styled/Input"; -import useCopy from "../../hooks/useCopy"; -import { shallowEqual } from "react-redux"; -import LinkifyText from "@/components/LinkifyText"; - -const Row = ({ - paramKey, - paramDefault, - remarks -}: { - paramKey: string; - paramDefault: string | number; - remarks: string; -}) => { - return ( - - {paramKey} - - {paramKey == "theme-color" ? ( - {paramDefault} - ) : ( - paramDefault - )} - - - - - - ); -}; -export default function Widget() { - const loginUid = useAppSelector((store) => store.authData.user?.uid, shallowEqual); - const widgetLink = `${location.origin}/widget.html?host=${loginUid}`; - const { t } = useTranslation("setting", { keyPrefix: "widget" }); - const { t: wt } = useTranslation("widget"); - const { t: ct } = useTranslation(); - const { copied, copy } = useCopy({ enableToast: false }); - const copyLink = () => { - copy(widgetLink); - }; - // const disableBtn = !reachLimit; - return ( -
-
{t("tip")}
- - - {`\n`} - -
{t("custom_style_tip")}:
- - {``} - -
{t("config")}:
-
- - - - {[t("param_key"), t("default_value"), t("remark")].map((title) => ( - - ))} - - - - {[ - { - paramKey: "id", - paramDefault: "-", - remarks: t("param_id") - }, - { - paramKey: "host-id", - paramDefault: 1, - remarks: t("param_host") - }, - { - paramKey: "auto-reg", - paramDefault: "true", - remarks: t("param_auto_reg") - }, - { - paramKey: "login-token", - paramDefault: `-`, - remarks: t("param_login_token") - }, - { - paramKey: "title", - paramDefault: `[VoceChat Name]`, - remarks: t("param_title") - }, - { - paramKey: "logo", - paramDefault: `[VoceChat Logo]`, - remarks: t("param_logo") - }, - { - paramKey: "theme-color", - paramDefault: "#1fe1f9", - remarks: t("param_theme_color") - }, - { - paramKey: "close-width", - paramDefault: `48(px)`, - remarks: t("param_close_width") - }, - { - paramKey: "close-height", - paramDefault: `48(px)`, - remarks: t("param_close_height") - }, - { - paramKey: "open-width", - paramDefault: `380(px)`, - remarks: t("param_open_width") - }, - { - paramKey: "open-height", - paramDefault: `680(px)`, - remarks: t("param_open_height") - }, - { - paramKey: "position", - paramDefault: `right`, - remarks: t("param_position") - }, - { - paramKey: "welcome", - paramDefault: wt("welcome"), - remarks: t("param_welcome") - } - ].map((row) => ( - - ))} - - - - - - -
- {title} -
- * All the parameters are optional, and prefixed by{" "} - data- -
-
-
-

- {t("share_link")}{" "} - - {t("widget_faq")} - -

-
- - -
-
-
- ); -} diff --git a/src/routes/setting/Widget/ConfigDetails.tsx b/src/routes/setting/Widget/ConfigDetails.tsx new file mode 100644 index 00000000..17f402ea --- /dev/null +++ b/src/routes/setting/Widget/ConfigDetails.tsx @@ -0,0 +1,133 @@ +import LinkifyText from "@/components/LinkifyText"; +import React from "react"; +import { useTranslation } from "react-i18next"; + +const Row = ({ + paramKey, + paramDefault, + remarks +}: { + paramKey: string; + paramDefault: string | number; + remarks: string; +}) => { + return ( + + {paramKey} + + {paramKey == "theme-color" ? ( + {paramDefault} + ) : ( + paramDefault + )} + + + + + + ); +}; +type Props = {}; + +const ConfigDetails = ({}: Props) => { + const { t } = useTranslation("setting", { keyPrefix: "widget" }); + const { t: wt } = useTranslation("widget"); + return ( + + + + {[t("param_key"), t("default_value"), t("remark")].map((title) => ( + + ))} + + + + {[ + { + paramKey: "id", + paramDefault: "-", + remarks: t("param_id") + }, + { + paramKey: "host-id", + paramDefault: 1, + remarks: t("param_host") + }, + { + paramKey: "auto-reg", + paramDefault: "true", + remarks: t("param_auto_reg") + }, + { + paramKey: "login-token", + paramDefault: `-`, + remarks: t("param_login_token") + }, + { + paramKey: "title", + paramDefault: `[VoceChat Name]`, + remarks: t("param_title") + }, + { + paramKey: "logo", + paramDefault: `[VoceChat Logo]`, + remarks: t("param_logo") + }, + { + paramKey: "theme-color", + paramDefault: "#1fe1f9", + remarks: t("param_theme_color") + }, + { + paramKey: "close-width", + paramDefault: `48(px)`, + remarks: t("param_close_width") + }, + { + paramKey: "close-height", + paramDefault: `48(px)`, + remarks: t("param_close_height") + }, + { + paramKey: "open-width", + paramDefault: `380(px)`, + remarks: t("param_open_width") + }, + { + paramKey: "open-height", + paramDefault: `680(px)`, + remarks: t("param_open_height") + }, + { + paramKey: "position", + paramDefault: `right`, + remarks: t("param_position") + }, + { + paramKey: "welcome", + paramDefault: wt("welcome"), + remarks: t("param_welcome") + } + ].map((row) => ( + + ))} + + + + + + +
+ {title} +
+ * All the parameters are optional, and prefixed by{" "} + data- +
+ ); +}; + +export default ConfigDetails; diff --git a/src/routes/setting/Widget/index.tsx b/src/routes/setting/Widget/index.tsx new file mode 100644 index 00000000..72151df4 --- /dev/null +++ b/src/routes/setting/Widget/index.tsx @@ -0,0 +1,76 @@ +// import { useState, MouseEvent } from "react"; +// import dayjs from "dayjs"; +import { useTranslation } from "react-i18next"; +import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"; +import { vscDarkPlus } from "react-syntax-highlighter/dist/esm/styles/prism"; + +import IconQuestion from "@/assets/icons/question.svg"; +import { useAppSelector } from "@/app/store"; +import Button from "@/components/styled/Button"; +import Input from "@/components/styled/Input"; +import useCopy from "@/hooks/useCopy"; +import { shallowEqual } from "react-redux"; +import ConfigDetails from "./ConfigDetails"; + +export default function Widget() { + const loginUid = useAppSelector((store) => store.authData.user?.uid, shallowEqual); + const widgetLink = `${location.origin}/widget.html?host=${loginUid}`; + const { t } = useTranslation("setting", { keyPrefix: "widget" }); + const { t: ct } = useTranslation(); + const { copied, copy } = useCopy({ enableToast: false }); + const copyLink = () => { + copy(widgetLink); + }; + // const disableBtn = !reachLimit; + return ( +
+
{t("tip")}
+ + + {`\n`} + +
{t("custom_style_tip")}:
+ + {``} + +
{t("config")}:
+
+ {/* 配置说明 */} + +
+
+

+ {t("share_link")}{" "} + + {t("widget_faq")} + +

+
+ + +
+
+
+ ); +}