From 71c9d1461f34abc40e8826ab23b9fbd0279c7546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Sat, 26 Oct 2024 15:24:56 -0500 Subject: [PATCH] feat: login with wargaming to generate url --- .../src/pages/tools/embed/[embed]/_index.tsx | 13 ++++- .../website/src/pages/tools/embed/_index.tsx | 51 +++++++++++++++++++ .../website/src/pages/tools/embed/index.astro | 11 +--- packages/website/src/stores/app/index.ts | 8 ++- 4 files changed, 72 insertions(+), 11 deletions(-) create mode 100644 packages/website/src/pages/tools/embed/_index.tsx diff --git a/packages/website/src/pages/tools/embed/[embed]/_index.tsx b/packages/website/src/pages/tools/embed/[embed]/_index.tsx index 3c9423d10..95a277108 100644 --- a/packages/website/src/pages/tools/embed/[embed]/_index.tsx +++ b/packages/website/src/pages/tools/embed/[embed]/_index.tsx @@ -25,6 +25,7 @@ import { SizeWithout0 } from '../../../../components/Embeds/SizeWithout0'; import { Slider } from '../../../../components/Embeds/Slider'; import { TextController } from '../../../../components/Embeds/TextController'; import { PageWrapper } from '../../../../components/PageWrapper'; +import { WargamingLoginButton } from '../../../../components/WargamingLoginButton'; import { configurations, extractEmbedConfigDefaults, @@ -59,6 +60,10 @@ export function Page({ embed }: PageProps) { } function Content({ embed }: PageProps) { + const wargaming = App.useDeferred( + (state) => state.logins.wargaming, + undefined, + ); const embedStateStore = EmbedState.useStore(); const appStore = App.useStore(); const config = configurations[embed] as EmbedConfig; @@ -96,6 +101,7 @@ function Content({ embed }: PageProps) { { const { wargaming } = appStore.getState().logins; @@ -120,8 +126,13 @@ function Content({ embed }: PageProps) { }} > - Copy URL + {wargaming ? 'Copy URL' : 'Log in to general URL'} + {!wargaming && ( + + Log in with Wargaming + + )} diff --git a/packages/website/src/pages/tools/embed/_index.tsx b/packages/website/src/pages/tools/embed/_index.tsx new file mode 100644 index 000000000..a2a983d1f --- /dev/null +++ b/packages/website/src/pages/tools/embed/_index.tsx @@ -0,0 +1,51 @@ +import { ExclamationTriangleIcon } from '@radix-ui/react-icons'; +import { Callout, Flex, Link } from '@radix-ui/themes'; +import { PageWrapper } from '../../../components/PageWrapper'; +import { WargamingLoginButton } from '../../../components/WargamingLoginButton'; +import { configurations } from '../../../constants/embeds'; +import { App, type WargamingLogin } from '../../../stores/app'; + +export function Page() { + return ( + + + + ); +} + +function Content() { + const wargaming = App.useDeferred((state) => state.logins.wargaming, { + expires: 0, + id: 0, + token: '', + } satisfies WargamingLogin); + + return ( + + {!wargaming && ( + <> + + + + + + + + You must be logged in with your Wargaming account to export + embeds. + + + + + + Log in with Wargaming + + + )} + + {Object.entries(configurations).map(([embed, config]) => ( + {embed} + ))} + + ); +} diff --git a/packages/website/src/pages/tools/embed/index.astro b/packages/website/src/pages/tools/embed/index.astro index d1c9cb0e0..1eb609380 100644 --- a/packages/website/src/pages/tools/embed/index.astro +++ b/packages/website/src/pages/tools/embed/index.astro @@ -1,16 +1,9 @@ --- -import { PageWrapper } from '../../../components/PageWrapper'; -import { configurations } from '../../../constants/embeds'; import { embedTool } from '../../../constants/tools'; import ToolLayout from '../../../layouts/ToolLayout.astro'; +import { Page } from './_index'; --- - - { - Object.entries(configurations).map(([embed, config]) => ( - {embed} - )) - } - + diff --git a/packages/website/src/stores/app/index.ts b/packages/website/src/stores/app/index.ts index bf61e2489..d6e044e1d 100644 --- a/packages/website/src/stores/app/index.ts +++ b/packages/website/src/stores/app/index.ts @@ -3,11 +3,17 @@ import { create } from 'zustand'; import { persist, subscribeWithSelector } from 'zustand/middleware'; import { createContextualStore } from '../../core/zustand/createContextualStore'; +export interface WargamingLogin { + token: string; + id: number; + expires: number; +} + interface AppStore { developerMode: boolean; policiesAgreementIndex: number; logins: { - wargaming?: { token: string; id: number; expires: number }; + wargaming?: WargamingLogin; }; }