import { Button, Modal, Switch } from '@mui/material'; import { useEffect, useState } from 'react'; import { twc } from 'react-twc'; import { useGlobalSettings } from '../../Hooks/useGlobalSettings'; import { Cross } from '../../Icons/generated'; import { PreStartMode } from '../../Types/Settings'; import { ModalWrapper } from './InfoModal'; import { Separator } from './Separator'; import { Paragraph } from './TextComponents'; const SettingContainer = twc.div`w-full flex flex-col mb-2`; const ToggleContainer = twc.div`flex flex-row justify-between items-center -mb-1`; const Container = twc.div`flex flex-col items-center w-full`; const Description = twc.p`mr-16 text-xs text-left text-text-secondary`; type SettingsModalProps = { isOpen: boolean; closeModal: () => void; }; export const SettingsModal = ({ isOpen, closeModal }: SettingsModalProps) => { const { settings, setSettings, isPWA } = useGlobalSettings(); const [isLatestVersion, setIsLatestVersion] = useState(false); const [newVersion, setNewVersion] = useState(undefined); useEffect(() => { if (!isOpen) { return; } async function checkIfLatestVersion() { try { const result = await fetch( 'https://api.github.com/repos/Vikeo/LifeTrinket/releases/latest', { headers: { /* @ts-expect-error is defined in vite.config.ts*/ Authorization: `Bearer ${REPO_READ_ACCESS_TOKEN}`, Accept: 'application/vnd.github+json', 'X-GitHub-Api-Version': '2022-11-28', }, } ); const data = await result.json(); if (!data.name) { setNewVersion(undefined); setIsLatestVersion(false); return; } setNewVersion(data.name); /* @ts-expect-error is defined in vite.config.ts*/ if (data.name === APP_VERSION) { setIsLatestVersion(true); return; } setIsLatestVersion(false); } catch (error) { console.error('error getting latest version string', error); } } checkIfLatestVersion(); }, [isOpen]); return ( <>

⚙️ Settings ⚙️

{/* @ts-expect-error is defined in vite.config.ts*/} Current version: {APP_VERSION}{' '} {isLatestVersion && ( (latest) )} {!isLatestVersion && newVersion && ( New version ({newVersion}) is available!{' '} )} {!isLatestVersion && newVersion && ( )} { setSettings({ ...settings, showPlayerMenuCog: !settings.showPlayerMenuCog, }); }} /> A cog on the top right of each player's card will be shown if this is enabled. { setSettings({ ...settings, showStartingPlayer: !settings.showStartingPlayer, }); }} /> On start or reset of game, will pick a random starting player, according to the Pre-Start mode
Different ways to determine the starting player before the game starts.
{settings.preStartMode === PreStartMode.None && (
None: The starting player will simply be shown.
)} {settings.preStartMode === PreStartMode.RandomKing && (
Random King:{' '} Randomly pass a crown between all players, press the screen to stop it. The player who has the crown when it stops gets to start.
)} {settings.preStartMode === PreStartMode.FingerGame && (
Finger Game: All players put a finger on the screen, one will be chosen at random.
)}
{ setSettings({ ...settings, keepAwake: !settings.keepAwake, }); }} /> Will prevent device from going to sleep while this app is open if this is enabled. { setSettings({ ...settings, goFullscreenOnStart: !settings.goFullscreenOnStart, }); }} /> Will enter fullscreen mode when starting a game if this is enabled. {!isPWA && ( <> Tip: You can{' '} add this webapp to your home page on iOS or{' '} install it on Android to have it act just like a normal app! If you do, this app will work offline and the toolbar will be automatically hidden. )}
); };