diff --git a/src/app/embeds/session/page.tsx b/src/app/embeds/session/page.tsx index c60c1db84..b73fef64a 100644 --- a/src/app/embeds/session/page.tsx +++ b/src/app/embeds/session/page.tsx @@ -18,6 +18,7 @@ import { useSession } from '../../../stores/session'; import { IndividualTankStats, TanksStats } from '../../../types/tanksStats'; import { CustomColumnDisplay } from '../../tools/session/components/CustomColumn'; import { Menu } from '../../tools/session/components/Menu'; +import { resetSession } from '../../tools/session/page'; const REFRESH_RATE = 1 / 5; @@ -324,7 +325,7 @@ export default function SessionPage() { - + ); } diff --git a/src/app/tools/session/components/Menu.tsx b/src/app/tools/session/components/Menu.tsx index f5f66e815..c2480217c 100644 --- a/src/app/tools/session/components/Menu.tsx +++ b/src/app/tools/session/components/Menu.tsx @@ -4,9 +4,10 @@ import { CustomColumn } from './CustomColumn'; interface ContextMenuProps { Builder: typeof DropdownMenu | typeof ContextMenu; + reset: () => void; } -export function Menu({ Builder }: ContextMenuProps) { +export function Menu({ Builder, reset }: ContextMenuProps) { const session = useSession(); return ( @@ -34,6 +35,12 @@ export function Menu({ Builder }: ContextMenuProps) { > Show career + + + + + Reset + ); } diff --git a/src/app/tools/session/page.tsx b/src/app/tools/session/page.tsx index c738f836f..e89c25a64 100644 --- a/src/app/tools/session/page.tsx +++ b/src/app/tools/session/page.tsx @@ -14,10 +14,9 @@ import { Flex, Text, TextField, - Tooltip, } from '@radix-ui/themes'; import { debounce } from 'lodash'; -import { ChangeEvent, useRef, useState } from 'react'; +import { ChangeEvent, useEffect, useRef, useState } from 'react'; import PageWrapper from '../../../components/PageWrapper'; import { REGION_NAMES, Region } from '../../../constants/regions'; import { WARGAMING_APPLICATION_ID } from '../../../constants/wargamingApplicationID'; @@ -31,6 +30,36 @@ import SessionPage from '../../embeds/session/page'; import { Menu } from './components/Menu'; import * as styles from './page.css'; +export async function setSession(region: Region, id: number, nickname: string) { + const rawTankStats = ( + await fetchBlitz( + `https://api.wotblitz.${region}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`, + ) + )[id]; + const tankStats = rawTankStats.reduce( + (accumulator, tank) => ({ + ...accumulator, + [tank.tank_id]: tank, + }), + {}, + ); + + useSession.setState({ + isTracking: true, + id, + region, + nickname, + tankStats, + time: Date.now(), + }); +} + +export function resetSession() { + const session = useSession.getState(); + if (!session.isTracking) return; + setSession(session.region, session.id, session.nickname); +} + export default function Page() { const input = useRef(null); const [searchResults, setSearchResults] = useState< @@ -50,37 +79,9 @@ export default function Page() { ); const session = useSession(); - async function setSession(region: Region, id: number, nickname: string) { - input.current!.value = nickname; - - const rawTankStats = ( - await fetchBlitz( - `https://api.wotblitz.${region}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`, - ) - )[id]; - const tankStats = rawTankStats.reduce( - (accumulator, tank) => ({ - ...accumulator, - [tank.tank_id]: tank, - }), - {}, - ); - - useSession.setState({ - isTracking: true, - id, - region, - nickname, - tankStats, - time: Date.now(), - }); - } - - function reset() { - const session = useSession.getState(); - if (!session.isTracking) return; - setSession(session.region, session.id, session.nickname); - } + useEffect(() => { + if (session.isTracking) input.current!.value = session.nickname; + }, [session]); return ( @@ -158,7 +159,7 @@ export default function Page() { onClick={(event) => { if (!session.promptBeforeReset) { event.preventDefault(); - reset(); + resetSession(); } }} className={styles.toolbarButton} @@ -201,7 +202,7 @@ export default function Page() { - @@ -209,19 +210,60 @@ export default function Page() { - - - + + + + + + + + Copied link to your clipboard + + + Keep in mind: +
    +
  • Paste this link into your browser to view the embed
  • +
  • Embeds abide your custom options
  • +
  • + Options do not transfer across websites/streaming softwares +
  • +
+
+ + + + useSession.setState({ + showEmbedPrompt: !checked, + }) + } + /> + Don't show this again + + + + + + + +
+
@@ -231,7 +273,7 @@ export default function Page() { - + diff --git a/src/stores/session.ts b/src/stores/session.ts index e6db63fac..c66688ef1 100644 --- a/src/stores/session.ts +++ b/src/stores/session.ts @@ -20,6 +20,7 @@ type Session = ( } ) & { promptBeforeReset: boolean; + showEmbedPrompt: boolean; customColumns: { display: CustomColumnDisplay; showDelta: boolean; @@ -36,6 +37,7 @@ export const useSession = create()( promptBeforeReset: true, showTotal: true, showCareer: true, + showEmbedPrompt: true, customColumns: [ { display: 'battles', showDelta: false },