-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #328 from TaloDev/develop
Release 0.43.0
- Loading branch information
Showing
11 changed files
with
164 additions
and
29 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { MouseEvent, useState } from 'react' | ||
import Modal from '../components/Modal' | ||
import TextInput from '../components/TextInput' | ||
import Button from '../components/Button' | ||
import buildError from '../utils/buildError' | ||
import ErrorMessage, { TaloError } from '../components/ErrorMessage' | ||
import { LeaderboardEntry } from '../entities/leaderboardEntry' | ||
import { useRecoilValue } from 'recoil' | ||
import activeGameState, { SelectedActiveGame } from '../state/activeGameState' | ||
import updateLeaderboardEntry from '../api/updateLeaderboardEntry' | ||
import { Leaderboard } from '../entities/leaderboard' | ||
import { upperFirst } from 'lodash-es' | ||
import { KeyedMutator } from 'swr' | ||
|
||
type UpdateEntryScoreProps = { | ||
modalState: [boolean, (open: boolean) => void] | ||
mutate: KeyedMutator<{ entries: LeaderboardEntry[] }> | ||
editingEntry: LeaderboardEntry | ||
leaderboard: Leaderboard | ||
} | ||
|
||
export default function UpdateEntryScore({ modalState, mutate, editingEntry, leaderboard }: UpdateEntryScoreProps) { | ||
const [, setOpen] = modalState | ||
const [score, setScore] = useState(editingEntry.score.toString()) | ||
const [isLoading, setLoading] = useState(false) | ||
const [error, setError] = useState<TaloError | null>(null) | ||
|
||
const activeGame = useRecoilValue(activeGameState) as SelectedActiveGame | ||
|
||
const onUpdateClick = async (e: MouseEvent<HTMLElement>) => { | ||
e.preventDefault() | ||
setLoading(true) | ||
setError(null) | ||
|
||
try { | ||
const { entry } = await updateLeaderboardEntry(activeGame.id, leaderboard.id, editingEntry.id, { newScore: Number(score) }) | ||
mutate((data) => { | ||
return { | ||
...data, | ||
entries: [...data!.entries.filter((e) => e.id !== editingEntry.id), entry] | ||
} | ||
}, true) | ||
setOpen(false) | ||
} catch (err) { | ||
setError(buildError(err)) | ||
setLoading(false) | ||
} | ||
} | ||
|
||
return ( | ||
<Modal | ||
id='update-entry-score' | ||
title={upperFirst(editingEntry.leaderboardName)} | ||
modalState={modalState} | ||
> | ||
<form> | ||
<div className='p-4 space-y-4'> | ||
<div> | ||
<p className='font-semibold'>Current score</p> | ||
<p>{editingEntry.score}</p> | ||
</div> | ||
|
||
<TextInput | ||
id='score' | ||
variant='light' | ||
type='number' | ||
label='New score' | ||
placeholder='Enter new score' | ||
onChange={setScore} | ||
value={score} | ||
inputClassName='border border-gray-200 focus:border-opacity-0' | ||
/> | ||
|
||
{error && <ErrorMessage error={error} />} | ||
</div> | ||
|
||
<div className='flex flex-col md:flex-row-reverse md:justify-between space-y-4 md:space-y-0 p-4 border-t border-gray-200'> | ||
<div className='w-full md:w-32'> | ||
<Button | ||
disabled={!score} | ||
isLoading={isLoading} | ||
onClick={onUpdateClick} | ||
> | ||
Update | ||
</Button> | ||
</div> | ||
<div className='w-full md:w-32'> | ||
<Button type='button' variant='grey' onClick={() => setOpen(false)}>Cancel</Button> | ||
</div> | ||
</div> | ||
</form> | ||
</Modal> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters