mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-28 21:19:52 +01:00
feat: added reset in options
This commit is contained in:
1 parent
d3bbc7f2b0
commit
630a37025e
4 files changed
+103
-51
No files matched your search
@@ -18,6 +18,7 @@ import { useSession } from '../../../stores/session';
|
|||||||
import { IndividualTankStats, TanksStats } from '../../../types/tanksStats';
|
import { IndividualTankStats, TanksStats } from '../../../types/tanksStats';
|
||||||
import { CustomColumnDisplay } from '../../tools/session/components/CustomColumn';
|
import { CustomColumnDisplay } from '../../tools/session/components/CustomColumn';
|
||||||
import { Menu } from '../../tools/session/components/Menu';
|
import { Menu } from '../../tools/session/components/Menu';
|
||||||
|
import { resetSession } from '../../tools/session/page';
|
||||||
|
|
||||||
const REFRESH_RATE = 1 / 5;
|
const REFRESH_RATE = 1 / 5;
|
||||||
|
|
||||||
@@ -324,7 +325,7 @@ export default function SessionPage() {
|
|||||||
</div>
|
</div>
|
||||||
</ContextMenu.Trigger>
|
</ContextMenu.Trigger>
|
||||||
|
|
||||||
<Menu Builder={ContextMenu} />
|
<Menu reset={resetSession} Builder={ContextMenu} />
|
||||||
</ContextMenu.Root>
|
</ContextMenu.Root>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -4,9 +4,10 @@ import { CustomColumn } from './CustomColumn';
|
|||||||
|
|
||||||
interface ContextMenuProps {
|
interface ContextMenuProps {
|
||||||
Builder: typeof DropdownMenu | typeof ContextMenu;
|
Builder: typeof DropdownMenu | typeof ContextMenu;
|
||||||
|
reset: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Menu({ Builder }: ContextMenuProps) {
|
export function Menu({ Builder, reset }: ContextMenuProps) {
|
||||||
const session = useSession();
|
const session = useSession();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -34,6 +35,12 @@ export function Menu({ Builder }: ContextMenuProps) {
|
|||||||
>
|
>
|
||||||
Show career
|
Show career
|
||||||
</Builder.CheckboxItem>
|
</Builder.CheckboxItem>
|
||||||
|
|
||||||
|
<Builder.Separator />
|
||||||
|
|
||||||
|
<Builder.Item color="red" onClick={reset}>
|
||||||
|
Reset
|
||||||
|
</Builder.Item>
|
||||||
</Builder.Content>
|
</Builder.Content>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -14,10 +14,9 @@ import {
|
|||||||
Flex,
|
Flex,
|
||||||
Text,
|
Text,
|
||||||
TextField,
|
TextField,
|
||||||
Tooltip,
|
|
||||||
} from '@radix-ui/themes';
|
} from '@radix-ui/themes';
|
||||||
import { debounce } from 'lodash';
|
import { debounce } from 'lodash';
|
||||||
import { ChangeEvent, useRef, useState } from 'react';
|
import { ChangeEvent, useEffect, useRef, useState } from 'react';
|
||||||
import PageWrapper from '../../../components/PageWrapper';
|
import PageWrapper from '../../../components/PageWrapper';
|
||||||
import { REGION_NAMES, Region } from '../../../constants/regions';
|
import { REGION_NAMES, Region } from '../../../constants/regions';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../../../constants/wargamingApplicationID';
|
import { WARGAMING_APPLICATION_ID } from '../../../constants/wargamingApplicationID';
|
||||||
@@ -31,6 +30,36 @@ import SessionPage from '../../embeds/session/page';
|
|||||||
import { Menu } from './components/Menu';
|
import { Menu } from './components/Menu';
|
||||||
import * as styles from './page.css';
|
import * as styles from './page.css';
|
||||||
|
|
||||||
|
export async function setSession(region: Region, id: number, nickname: string) {
|
||||||
|
const rawTankStats = (
|
||||||
|
await fetchBlitz<TanksStats>(
|
||||||
|
`https://api.wotblitz.${region}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||||
|
)
|
||||||
|
)[id];
|
||||||
|
const tankStats = rawTankStats.reduce<NormalizedTankStats>(
|
||||||
|
(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() {
|
export default function Page() {
|
||||||
const input = useRef<HTMLInputElement>(null);
|
const input = useRef<HTMLInputElement>(null);
|
||||||
const [searchResults, setSearchResults] = useState<
|
const [searchResults, setSearchResults] = useState<
|
||||||
@@ -50,37 +79,9 @@ export default function Page() {
|
|||||||
);
|
);
|
||||||
const session = useSession();
|
const session = useSession();
|
||||||
|
|
||||||
async function setSession(region: Region, id: number, nickname: string) {
|
useEffect(() => {
|
||||||
input.current!.value = nickname;
|
if (session.isTracking) input.current!.value = session.nickname;
|
||||||
|
}, [session]);
|
||||||
const rawTankStats = (
|
|
||||||
await fetchBlitz<TanksStats>(
|
|
||||||
`https://api.wotblitz.${region}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
|
||||||
)
|
|
||||||
)[id];
|
|
||||||
const tankStats = rawTankStats.reduce<NormalizedTankStats>(
|
|
||||||
(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);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageWrapper>
|
<PageWrapper>
|
||||||
@@ -158,7 +159,7 @@ export default function Page() {
|
|||||||
onClick={(event) => {
|
onClick={(event) => {
|
||||||
if (!session.promptBeforeReset) {
|
if (!session.promptBeforeReset) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
reset();
|
resetSession();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
className={styles.toolbarButton}
|
className={styles.toolbarButton}
|
||||||
@@ -201,7 +202,7 @@ export default function Page() {
|
|||||||
</AlertDialog.Cancel>
|
</AlertDialog.Cancel>
|
||||||
|
|
||||||
<AlertDialog.Action>
|
<AlertDialog.Action>
|
||||||
<Button variant="solid" color="red" onClick={reset}>
|
<Button variant="solid" color="red" onClick={resetSession}>
|
||||||
Reset
|
Reset
|
||||||
</Button>
|
</Button>
|
||||||
</AlertDialog.Action>
|
</AlertDialog.Action>
|
||||||
@@ -209,19 +210,60 @@ export default function Page() {
|
|||||||
</AlertDialog.Content>
|
</AlertDialog.Content>
|
||||||
</AlertDialog.Root>
|
</AlertDialog.Root>
|
||||||
|
|
||||||
<Tooltip content="Copy to clipboard">
|
<AlertDialog.Root>
|
||||||
<Button
|
<AlertDialog.Trigger>
|
||||||
variant="soft"
|
<Button
|
||||||
className={styles.toolbarButton}
|
variant="soft"
|
||||||
onClick={() =>
|
className={styles.toolbarButton}
|
||||||
navigator.clipboard.writeText(
|
onClick={(event) => {
|
||||||
`${location.origin}/embeds/session`,
|
if (!session.showEmbedPrompt) {
|
||||||
)
|
event.preventDefault();
|
||||||
}
|
resetSession();
|
||||||
>
|
}
|
||||||
<CopyIcon width="16" height="16" /> Embed
|
|
||||||
</Button>
|
navigator.clipboard.writeText(
|
||||||
</Tooltip>
|
`${location.origin}/embeds/session`,
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<CopyIcon width="16" height="16" /> Embed
|
||||||
|
</Button>
|
||||||
|
</AlertDialog.Trigger>
|
||||||
|
|
||||||
|
<AlertDialog.Content>
|
||||||
|
<AlertDialog.Title>
|
||||||
|
Copied link to your clipboard
|
||||||
|
</AlertDialog.Title>
|
||||||
|
<AlertDialog.Description>
|
||||||
|
Keep in mind:
|
||||||
|
<ul>
|
||||||
|
<li>Paste this link into your browser to view the embed</li>
|
||||||
|
<li>Embeds abide your custom options</li>
|
||||||
|
<li>
|
||||||
|
Options do not transfer across websites/streaming softwares
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</AlertDialog.Description>
|
||||||
|
|
||||||
|
<Text size="2">
|
||||||
|
<Checkbox
|
||||||
|
mr="1"
|
||||||
|
onCheckedChange={(checked) =>
|
||||||
|
useSession.setState({
|
||||||
|
showEmbedPrompt: !checked,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
Don't show this again
|
||||||
|
</Text>
|
||||||
|
|
||||||
|
<Flex gap="3" mt="4">
|
||||||
|
<AlertDialog.Cancel>
|
||||||
|
<Button variant="soft">Got it!</Button>
|
||||||
|
</AlertDialog.Cancel>
|
||||||
|
</Flex>
|
||||||
|
</AlertDialog.Content>
|
||||||
|
</AlertDialog.Root>
|
||||||
|
|
||||||
<DropdownMenu.Root>
|
<DropdownMenu.Root>
|
||||||
<DropdownMenu.Trigger>
|
<DropdownMenu.Trigger>
|
||||||
@@ -231,7 +273,7 @@ export default function Page() {
|
|||||||
</Button>
|
</Button>
|
||||||
</DropdownMenu.Trigger>
|
</DropdownMenu.Trigger>
|
||||||
|
|
||||||
<Menu Builder={DropdownMenu} />
|
<Menu Builder={DropdownMenu} reset={resetSession} />
|
||||||
</DropdownMenu.Root>
|
</DropdownMenu.Root>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ type Session = (
|
|||||||
}
|
}
|
||||||
) & {
|
) & {
|
||||||
promptBeforeReset: boolean;
|
promptBeforeReset: boolean;
|
||||||
|
showEmbedPrompt: boolean;
|
||||||
customColumns: {
|
customColumns: {
|
||||||
display: CustomColumnDisplay;
|
display: CustomColumnDisplay;
|
||||||
showDelta: boolean;
|
showDelta: boolean;
|
||||||
@@ -36,6 +37,7 @@ export const useSession = create<Session>()(
|
|||||||
promptBeforeReset: true,
|
promptBeforeReset: true,
|
||||||
showTotal: true,
|
showTotal: true,
|
||||||
showCareer: true,
|
showCareer: true,
|
||||||
|
showEmbedPrompt: true,
|
||||||
|
|
||||||
customColumns: [
|
customColumns: [
|
||||||
{ display: 'battles', showDelta: false },
|
{ display: 'battles', showDelta: false },
|
||||||
|
|||||||
Reference in new issue
Block a user