mirror of
https://github.com/Vikeo/LifeTrinket.git
synced 2025-11-18 08:48:00 +00:00
Compare commits
5 Commits
1.0.5
...
chore/pack
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6dd0bc777 | ||
|
|
55c02385b5 | ||
|
|
6690a3b256 | ||
|
|
c5bb7eb04b | ||
|
|
de99c0b7e9 |
@@ -1,18 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
root: true,
|
|
||||||
env: { browser: true, es2020: true },
|
|
||||||
extends: [
|
|
||||||
'eslint:recommended',
|
|
||||||
'plugin:@typescript-eslint/recommended',
|
|
||||||
'plugin:react-hooks/recommended',
|
|
||||||
],
|
|
||||||
ignorePatterns: ['dist', '.eslintrc.cjs'],
|
|
||||||
parser: '@typescript-eslint/parser',
|
|
||||||
plugins: ['react-refresh'],
|
|
||||||
rules: {
|
|
||||||
'react-refresh/only-export-components': [
|
|
||||||
'warn',
|
|
||||||
{ allowConstantExport: true },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
18
.github/workflows/firebase-release.yml
vendored
18
.github/workflows/firebase-release.yml
vendored
@@ -13,14 +13,22 @@ jobs:
|
|||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Setup bun
|
- name: Setup pnpm
|
||||||
uses: oven-sh/setup-bun@v1
|
uses: pnpm/action-setup@v4
|
||||||
|
with:
|
||||||
|
version: 9
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: 20
|
||||||
|
cache: 'pnpm'
|
||||||
|
|
||||||
- name: Build, lint, and deploy
|
- name: Build, lint, and deploy
|
||||||
run: |
|
run: |
|
||||||
bun install
|
pnpm install
|
||||||
bun run build
|
pnpm run build
|
||||||
bun run lint
|
pnpm run lint
|
||||||
- name: Deploy to Firebase Hosting
|
- name: Deploy to Firebase Hosting
|
||||||
uses: FirebaseExtended/action-hosting-deploy@v0
|
uses: FirebaseExtended/action-hosting-deploy@v0
|
||||||
with:
|
with:
|
||||||
|
|||||||
22
.github/workflows/lint_and_build.yml
vendored
22
.github/workflows/lint_and_build.yml
vendored
@@ -14,22 +14,24 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Node.js
|
|
||||||
uses: actions/setup-node@v2
|
|
||||||
|
|
||||||
|
- name: Setup pnpm
|
||||||
|
uses: pnpm/action-setup@v4
|
||||||
with:
|
with:
|
||||||
node-version: 18
|
version: 9
|
||||||
|
|
||||||
- name: Set up bun
|
- name: Setup Node.js
|
||||||
uses: oven-sh/setup-bun@v1
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: 20
|
||||||
|
cache: 'pnpm'
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: bun install
|
run: pnpm install
|
||||||
|
|
||||||
- name: Run lint
|
- name: Run lint
|
||||||
run: bun run lint
|
run: pnpm run lint
|
||||||
|
|
||||||
- name: Build project
|
- name: Build project
|
||||||
run: bun run build
|
run: pnpm run build
|
||||||
|
|||||||
26
eslint.config.mjs
Normal file
26
eslint.config.mjs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import js from '@eslint/js';
|
||||||
|
import reactHooks from 'eslint-plugin-react-hooks';
|
||||||
|
import reactRefresh from 'eslint-plugin-react-refresh';
|
||||||
|
import tseslint from 'typescript-eslint';
|
||||||
|
|
||||||
|
export default tseslint.config(
|
||||||
|
{ ignores: ['dist'] },
|
||||||
|
{
|
||||||
|
extends: [js.configs.recommended, ...tseslint.configs.recommended],
|
||||||
|
files: ['**/*.{ts,tsx}'],
|
||||||
|
languageOptions: {
|
||||||
|
ecmaVersion: 2020,
|
||||||
|
},
|
||||||
|
plugins: {
|
||||||
|
'react-hooks': reactHooks,
|
||||||
|
'react-refresh': reactRefresh,
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
...reactHooks.configs.recommended.rules,
|
||||||
|
'react-refresh/only-export-components': [
|
||||||
|
'warn',
|
||||||
|
{ allowConstantExport: true },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
53
package.json
53
package.json
@@ -11,46 +11,45 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "tsc && vite build",
|
"build": "tsc && vite build",
|
||||||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
"lint": "eslint . --report-unused-disable-directives --max-warnings 0",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"generate-icons": "npx @svgr/cli src/Icons/svgs",
|
"generate-icons": "npx @svgr/cli src/Icons/svgs",
|
||||||
"deploy": "bun run build && firebase deploy --only hosting",
|
"force-deploy": "pnpm run build && firebase deploy --only hosting",
|
||||||
"release": "bash scripts/create-release.sh"
|
"release": "bash scripts/create-release.sh"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"firebase": "^10.14.1",
|
"firebase": "^12.6.0",
|
||||||
"ga-4-react": "^0.1.281",
|
"react": "^19.2.0",
|
||||||
"react": "^18.3.1",
|
"react-dom": "^19.2.0",
|
||||||
"react-dom": "^18.3.1",
|
"react-screen-wake-lock": "^3.1.1",
|
||||||
"react-screen-wake-lock": "^3.0.2",
|
|
||||||
"react-swipeable": "^7.0.2",
|
"react-swipeable": "^7.0.2",
|
||||||
"react-twc": "^1.4.2",
|
"react-twc": "^1.5.1",
|
||||||
"semver": "^7.7.1",
|
"semver": "^7.7.3",
|
||||||
"zod": "^3.24.2"
|
"zod": "^4.1.12"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@emotion/react": "^11.14.0",
|
"@eslint/js": "^9.39.1",
|
||||||
"@emotion/styled": "^11.14.0",
|
|
||||||
"@svgr/cli": "^8.1.0",
|
"@svgr/cli": "^8.1.0",
|
||||||
"@tailwindcss/postcss": "^4.1.17",
|
"@tailwindcss/postcss": "^4.1.17",
|
||||||
"@types/react": "^18.3.18",
|
"@types/prop-types": "^15.7.15",
|
||||||
"@types/react-dom": "^18.3.5",
|
"@types/react": "^19.2.5",
|
||||||
"@types/semver": "^7.5.8",
|
"@types/react-dom": "^19.2.3",
|
||||||
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
"@types/semver": "^7.7.1",
|
||||||
"@typescript-eslint/parser": "^7.18.0",
|
"@typescript-eslint/eslint-plugin": "^8.47.0",
|
||||||
"@vitejs/plugin-react-swc": "^3.8.0",
|
"@typescript-eslint/parser": "^8.47.0",
|
||||||
|
"@vitejs/plugin-react-swc": "^4.2.2",
|
||||||
"autoprefixer": "^10.4.22",
|
"autoprefixer": "^10.4.22",
|
||||||
"eslint": "^8.57.1",
|
"eslint": "^9.39.1",
|
||||||
"eslint-plugin-react-hooks": "^4.6.2",
|
"eslint-plugin-react-hooks": "^7.0.1",
|
||||||
"eslint-plugin-react-refresh": "^0.4.19",
|
"eslint-plugin-react-refresh": "^0.4.24",
|
||||||
"firebase-tools": "^13.31.2",
|
"firebase-tools": "^14.25.0",
|
||||||
"install": "^0.13.0",
|
|
||||||
"postcss": "^8.5.6",
|
"postcss": "^8.5.6",
|
||||||
"prettier": "2.8.8",
|
"prettier": "3.6.2",
|
||||||
"prop-types": "^15.8.1",
|
"prop-types": "^15.8.1",
|
||||||
"tailwindcss": "^4.1.17",
|
"tailwindcss": "^4.1.17",
|
||||||
"typescript": "^5.7.3",
|
"typescript": "^5.9.3",
|
||||||
"vite": "^5.4.14",
|
"typescript-eslint": "^8.47.0",
|
||||||
"vite-plugin-pwa": "^0.20.5"
|
"vite": "^7.2.2",
|
||||||
|
"vite-plugin-pwa": "^1.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
5635
pnpm-lock.yaml
generated
5635
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -41,8 +41,8 @@ const MatchScoreBadge = twc.div<MatchScoreBadgeProps>((props) => [
|
|||||||
props.$rotation === Rotation.Side || props.$rotation === Rotation.SideFlipped
|
props.$rotation === Rotation.Side || props.$rotation === Rotation.SideFlipped
|
||||||
? `left-[6.5vmax] bottom-[1vmax]`
|
? `left-[6.5vmax] bottom-[1vmax]`
|
||||||
: props.$useCommanderDamage
|
: props.$useCommanderDamage
|
||||||
? 'left-[0.5vmax] top-[11.5vmin]'
|
? 'left-[0.5vmax] top-[11.5vmin]'
|
||||||
: 'left-[0.5vmax] top-[1vmax]',
|
: 'left-[0.5vmax] top-[1vmax]',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
type SettingsButtonProps = {
|
type SettingsButtonProps = {
|
||||||
@@ -195,9 +195,6 @@ const LifeCounter = ({ player, opponents, matchScore }: LifeCounterProps) => {
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [document.body.clientHeight, document.body.clientWidth]);
|
}, [document.body.clientHeight, document.body.clientWidth]);
|
||||||
|
|
||||||
player.settings.rotation === Rotation.SideFlipped ||
|
|
||||||
player.settings.rotation === Rotation.Side;
|
|
||||||
|
|
||||||
const handleLifeChange = (updatedLifeTotal: number) => {
|
const handleLifeChange = (updatedLifeTotal: number) => {
|
||||||
const difference = updateLifeTotal(player, updatedLifeTotal);
|
const difference = updateLifeTotal(player, updatedLifeTotal);
|
||||||
setRecentDifference(recentDifference + difference);
|
setRecentDifference(recentDifference + difference);
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { ReactElement } from 'react';
|
||||||
|
|
||||||
export const IconCheckbox = ({
|
export const IconCheckbox = ({
|
||||||
name,
|
name,
|
||||||
icon,
|
icon,
|
||||||
@@ -7,14 +9,14 @@ export const IconCheckbox = ({
|
|||||||
className,
|
className,
|
||||||
}: {
|
}: {
|
||||||
name: string;
|
name: string;
|
||||||
icon: JSX.Element;
|
icon: ReactElement;
|
||||||
checkedIcon: JSX.Element;
|
checkedIcon: ReactElement;
|
||||||
checked: boolean;
|
checked: boolean;
|
||||||
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
||||||
className?: string;
|
className?: string;
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<div className={className} >
|
<div className={className}>
|
||||||
<label>
|
<label>
|
||||||
<input
|
<input
|
||||||
name={name}
|
name={name}
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { BeforeInstallPromptEvent } from '../../global';
|
import { BeforeInstallPromptEvent } from '../../global';
|
||||||
import { useAnalytics } from '../../Hooks/useAnalytics';
|
import { useAnalytics } from '../../Hooks/useAnalytics';
|
||||||
|
|
||||||
export const InstallPWAButton = () => {
|
export const InstallPWAButton = () => {
|
||||||
const supportsPWARef = useRef<boolean>(false);
|
|
||||||
const [promptInstall, setPromptInstall] =
|
const [promptInstall, setPromptInstall] =
|
||||||
useState<BeforeInstallPromptEvent | null>(null);
|
useState<BeforeInstallPromptEvent | null>(null);
|
||||||
|
|
||||||
@@ -11,7 +10,6 @@ export const InstallPWAButton = () => {
|
|||||||
|
|
||||||
const handler = (e: BeforeInstallPromptEvent) => {
|
const handler = (e: BeforeInstallPromptEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
supportsPWARef.current = true;
|
|
||||||
setPromptInstall(e);
|
setPromptInstall(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -21,7 +19,7 @@ export const InstallPWAButton = () => {
|
|||||||
return () => window.removeEventListener('transitionend', handler);
|
return () => window.removeEventListener('transitionend', handler);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
if (!supportsPWARef.current) {
|
if (!promptInstall) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ export const Trivia = () => {
|
|||||||
const { setPlaying, goToStart } = useGlobalSettings();
|
const { setPlaying, goToStart } = useGlobalSettings();
|
||||||
|
|
||||||
const [randomQuestion, setRandomQuestion] = useState(
|
const [randomQuestion, setRandomQuestion] = useState(
|
||||||
questions[Math.floor(Math.random() * questions.length)]
|
() => questions[Math.floor(Math.random() * questions.length)]
|
||||||
);
|
);
|
||||||
|
|
||||||
const setUniqueRandomQuestion = () => {
|
const setUniqueRandomQuestion = () => {
|
||||||
|
|||||||
@@ -62,14 +62,20 @@ export const GlobalSettingsProvider = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const savedSettings = localStorage.getItem('settings');
|
const savedSettings = localStorage.getItem('settings');
|
||||||
const [randomizingPlayer, setRandomizingPlayer] = useState<boolean>(
|
const [randomizingPlayer, setRandomizingPlayer] = useState<boolean>(() => {
|
||||||
savedSettings
|
if (!savedSettings) return true;
|
||||||
? Boolean(JSON.parse(savedSettings).preStartMode === 'random-king')
|
const parsed = JSON.parse(savedSettings);
|
||||||
: true
|
return Boolean(parsed.preStartMode === 'random-king');
|
||||||
);
|
});
|
||||||
const [settings, setSettings] = useState<Settings>(
|
const [settings, setSettings] = useState<Settings>(() => {
|
||||||
savedSettings ? JSON.parse(savedSettings) : defaultSettings
|
if (!savedSettings) return defaultSettings;
|
||||||
);
|
const parsed = settingsSchema.safeParse(JSON.parse(savedSettings));
|
||||||
|
if (!parsed.success) {
|
||||||
|
console.error('invalid settings, using default settings');
|
||||||
|
return defaultSettings;
|
||||||
|
}
|
||||||
|
return parsed.data;
|
||||||
|
});
|
||||||
|
|
||||||
const setSettingsAndLocalStorage = (settings: Settings) => {
|
const setSettingsAndLocalStorage = (settings: Settings) => {
|
||||||
setSettings(settings);
|
setSettings(settings);
|
||||||
@@ -79,11 +85,17 @@ export const GlobalSettingsProvider = ({
|
|||||||
const savedGameSettings = localStorage.getItem('initialGameSettings');
|
const savedGameSettings = localStorage.getItem('initialGameSettings');
|
||||||
|
|
||||||
const [initialGameSettings, setInitialGameSettings] =
|
const [initialGameSettings, setInitialGameSettings] =
|
||||||
useState<InitialGameSettings>(
|
useState<InitialGameSettings>(() => {
|
||||||
savedGameSettings
|
if (!savedGameSettings) return defaultInitialGameSettings;
|
||||||
? JSON.parse(savedGameSettings)
|
const parsed = initialGameSettingsSchema.safeParse(
|
||||||
: defaultInitialGameSettings
|
JSON.parse(savedGameSettings)
|
||||||
);
|
);
|
||||||
|
if (!parsed.success) {
|
||||||
|
console.error('invalid game settings, using default settings');
|
||||||
|
return defaultInitialGameSettings;
|
||||||
|
}
|
||||||
|
return parsed.data;
|
||||||
|
});
|
||||||
|
|
||||||
const setInitialGameSettingsAndLocalStorage = (
|
const setInitialGameSettingsAndLocalStorage = (
|
||||||
initialGameSettings: InitialGameSettings
|
initialGameSettings: InitialGameSettings
|
||||||
@@ -108,48 +120,6 @@ export const GlobalSettingsProvider = ({
|
|||||||
localStorage.removeItem('gameScore');
|
localStorage.removeItem('gameScore');
|
||||||
};
|
};
|
||||||
|
|
||||||
// Set settings if they are not valid
|
|
||||||
useEffect(() => {
|
|
||||||
// If there are no saved settings, set default settings
|
|
||||||
if (!savedSettings) {
|
|
||||||
setSettingsAndLocalStorage(defaultSettings);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const parsedSettings = settingsSchema.safeParse(JSON.parse(savedSettings));
|
|
||||||
|
|
||||||
// If saved settings are not valid, remove them
|
|
||||||
if (!parsedSettings.success) {
|
|
||||||
console.error('invalid settings, resetting to default settings');
|
|
||||||
setSettingsAndLocalStorage(defaultSettings);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
localStorage.setItem('settings', JSON.stringify(parsedSettings.data));
|
|
||||||
}, [settings, savedSettings]);
|
|
||||||
|
|
||||||
// Set initial game settings if they are not valid
|
|
||||||
useEffect(() => {
|
|
||||||
if (!savedGameSettings) {
|
|
||||||
setInitialGameSettingsAndLocalStorage(defaultInitialGameSettings);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//parse existing game settings with zod schema
|
|
||||||
const parsedInitialGameSettings =
|
|
||||||
initialGameSettingsSchema.safeParse(initialGameSettings);
|
|
||||||
|
|
||||||
if (!parsedInitialGameSettings.success) {
|
|
||||||
console.error('invalid game settings, resetting to default settings');
|
|
||||||
setInitialGameSettingsAndLocalStorage(defaultInitialGameSettings);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
localStorage.setItem(
|
|
||||||
'initialGameSettings',
|
|
||||||
JSON.stringify(parsedInitialGameSettings.data)
|
|
||||||
);
|
|
||||||
}, [initialGameSettings, savedGameSettings]);
|
|
||||||
|
|
||||||
const [isFullscreen, setIsFullscreen] = useState(false);
|
const [isFullscreen, setIsFullscreen] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -240,17 +210,20 @@ export const GlobalSettingsProvider = ({
|
|||||||
|
|
||||||
async function checkForNewVersion(source: 'settings' | 'start_menu') {
|
async function checkForNewVersion(source: 'settings' | 'start_menu') {
|
||||||
try {
|
try {
|
||||||
|
const token = import.meta.env.VITE_REPO_READ_ACCESS_TOKEN;
|
||||||
|
const headers: HeadersInit = {
|
||||||
|
Accept: 'application/vnd.github+json',
|
||||||
|
'X-GitHub-Api-Version': '2022-11-28',
|
||||||
|
};
|
||||||
|
|
||||||
|
// Only add authorization if token is available
|
||||||
|
if (token) {
|
||||||
|
headers.Authorization = `Bearer ${token}`;
|
||||||
|
}
|
||||||
|
|
||||||
const result = await fetch(
|
const result = await fetch(
|
||||||
'https://api.github.com/repos/Vikeo/LifeTrinket/releases/latest',
|
'https://api.github.com/repos/Vikeo/LifeTrinket/releases/latest',
|
||||||
{
|
{ headers }
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${
|
|
||||||
import.meta.env.VITE_REPO_READ_ACCESS_TOKEN
|
|
||||||
}`,
|
|
||||||
Accept: 'application/vnd.github+json',
|
|
||||||
'X-GitHub-Api-Version': '2022-11-28',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
const data = await result.json();
|
const data = await result.json();
|
||||||
|
|
||||||
@@ -299,7 +272,7 @@ export const GlobalSettingsProvider = ({
|
|||||||
playing,
|
playing,
|
||||||
setPlaying: setPlayingAndLocalStorage,
|
setPlaying: setPlayingAndLocalStorage,
|
||||||
initialGameSettings,
|
initialGameSettings,
|
||||||
setInitialGameSettings,
|
setInitialGameSettings: setInitialGameSettingsAndLocalStorage,
|
||||||
settings,
|
settings,
|
||||||
setSettings: setSettingsAndLocalStorage,
|
setSettings: setSettingsAndLocalStorage,
|
||||||
randomizingPlayer,
|
randomizingPlayer,
|
||||||
@@ -331,6 +304,7 @@ export const GlobalSettingsProvider = ({
|
|||||||
initialGameSettings,
|
initialGameSettings,
|
||||||
settings,
|
settings,
|
||||||
randomizingPlayer,
|
randomizingPlayer,
|
||||||
|
setRandomizingPlayer,
|
||||||
preStartCompleted,
|
preStartCompleted,
|
||||||
savedGame,
|
savedGame,
|
||||||
remoteVersion,
|
remoteVersion,
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { ReactNode, useEffect } from 'react';
|
import { ReactNode, useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import { Player } from '../Types/Player';
|
import { Player } from '../Types/Player';
|
||||||
import { useMemo, useState } from 'react';
|
|
||||||
import { PlayersContextType, PlayersContext } from '../Contexts/PlayersContext';
|
import { PlayersContextType, PlayersContext } from '../Contexts/PlayersContext';
|
||||||
import { InitialGameSettings } from '../Types/Settings';
|
import { InitialGameSettings } from '../Types/Settings';
|
||||||
|
|
||||||
@@ -13,10 +12,10 @@ export const PlayersProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
savedStartingPlayerIndex ? parseInt(savedStartingPlayerIndex) : -1
|
savedStartingPlayerIndex ? parseInt(savedStartingPlayerIndex) : -1
|
||||||
);
|
);
|
||||||
|
|
||||||
const setStartingPlayerIndexAndLocalStorage = (index: number) => {
|
const setStartingPlayerIndexAndLocalStorage = useCallback((index: number) => {
|
||||||
setStartingPlayerIndex(index);
|
setStartingPlayerIndex(index);
|
||||||
localStorage.setItem('startingPlayerIndex', String(index));
|
localStorage.setItem('startingPlayerIndex', String(index));
|
||||||
};
|
}, []);
|
||||||
|
|
||||||
const [players, setPlayers] = useState<Player[]>(
|
const [players, setPlayers] = useState<Player[]>(
|
||||||
savedPlayers ? JSON.parse(savedPlayers) : []
|
savedPlayers ? JSON.parse(savedPlayers) : []
|
||||||
@@ -96,7 +95,7 @@ export const PlayersProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
startingPlayerIndex,
|
startingPlayerIndex,
|
||||||
setStartingPlayerIndex: setStartingPlayerIndexAndLocalStorage,
|
setStartingPlayerIndex: setStartingPlayerIndexAndLocalStorage,
|
||||||
};
|
};
|
||||||
}, [players, startingPlayerIndex]);
|
}, [players, startingPlayerIndex, setStartingPlayerIndexAndLocalStorage]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PlayersContext.Provider value={ctxValue}>
|
<PlayersContext.Provider value={ctxValue}>
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/* eslint-disable no-undef */
|
|
||||||
/* eslint-disable-next-line no-undef */
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
template: require('./template'),
|
template: require('./template'),
|
||||||
titleProp: true,
|
titleProp: true,
|
||||||
|
|||||||
@@ -34,7 +34,5 @@ const propTypesTemplate = (
|
|||||||
export default ${title}`;
|
export default ${title}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-undef
|
|
||||||
module.exports = propTypesTemplate;
|
module.exports = propTypesTemplate;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user