diff --git a/src/App.tsx b/src/App.tsx index e31e57d..52fd02e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -9,14 +9,18 @@ import { ViewPage } from "./pages/ViewPublicationPage"; import lightTheme from "./utils/themes/light"; +const defaultQuizId = "ef836ff8-35b1-4031-9acf-af5766bac2b2"; + moment.locale("ru"); const localeText = ruRU.components.MuiLocalizationProvider.defaultProps.localeText; interface Props { widget?: boolean; + quizId?: string; } -export default function App({ widget = false }: Props) { +export default function App({ widget = false, quizId }: Props) { + quizId ??= defaultQuizId; return ( - {widget ? + {widget ? ( - + - : + ) : ( - + - } + )} diff --git a/src/pages/ViewPublicationPage/index.tsx b/src/pages/ViewPublicationPage/index.tsx index 47e9727..1ba5bab 100644 --- a/src/pages/ViewPublicationPage/index.tsx +++ b/src/pages/ViewPublicationPage/index.tsx @@ -12,19 +12,15 @@ import { ApologyPage } from "./ApologyPage"; import { Question } from "./Question"; import { StartPageViewPublication } from "./StartPageViewPublication"; - import { parseQuizData } from "@model/api/getQuizData"; import { replaceSpacesToEmptyLines } from "./tools/replaceSpacesToEmptyLines"; -const QID = - import.meta.env.PROD ? - window.location.pathname.replace(/\//g, '') - : - "ef836ff8-35b1-4031-9acf-af5766bac2b2"; +type Props = { + quizId: string; +}; - -export const ViewPage = () => { - const { isLoading, error } = useSWR(["quizData", QID], params => getQuizData(params[1]), { +export const ViewPage = ({ quizId }: Props) => { + const { isLoading, error } = useSWR(["quizData", quizId], params => getQuizData(params[1]), { onSuccess: setQuizData, }); const { settings, items, recentlyСompleted } = useQuestionsStore(); diff --git a/src/widget.tsx b/src/widget.tsx index 7e9052d..f15b706 100644 --- a/src/widget.tsx +++ b/src/widget.tsx @@ -5,15 +5,16 @@ import App from "./App"; let root: Root | undefined = undefined; const widget = { - create({ selector }: { + create({ selector, quizId }: { selector: string; + quizId: string; }) { const element = document.getElementById(selector); if (!element) throw new Error("Element for widget doesn't exist"); root = createRoot(element); - root.render(); + root.render(); }, unmount() { if (root) root.unmount(); @@ -27,7 +28,8 @@ export default widget; import widget from ".../widget.js"; widget.create({ - selector: "widget-container" + selector: "widget-container", + quizId: "...", }) */