Persist tactics #23
Merged
maxime.batista
merged 6 commits from tactic/persistance
into master
1 year ago
Loading…
Reference in new issue
There is no content yet.
Delete Branch 'tactic/persistance'
Deleting a branch is permanent. It CANNOT be undone. Continue?
This pull request adds persistance to tactics.
you can now edit a tactic, place some players in the court, and refresh the page will bring back the previous court state.
53ea75f48e
toc4487c8365
1 year agoc4487c8365
toe4d908f2fb
1 year agoexport function fetchAPI(
url: string,
payload: object,
Anything is json-serializable.
import { CSSProperties, useRef, useState } from "react"
import React, { CSSProperties, useEffect, useRef, useState } from "react"
React should never be imported.
didMount.current = true
return
}
setSaveState(SaveStates.Saving)
State setters shouldn't be called in the top level scope of an
useEffect
hook.This causes avoidable re-renders because this state will always be updated after a first re-render when a dependency changes.
Then a second re-render will be triggered by this state update.
Instead, change the state directly when the
players
dependency changes: React will batch the state updates and only trigger a single re-render.So... Let's join those two states together in a custom hook (alternatively, each
setPlayers
call should also callsetSaveState
):Usage:
To go the extra mile, you may include the
useEffect
directly in this custom hook. This reduces the number of items this function returns:(p) =>
p.team === player.team &&
p.role === player.role,
)
Consider extracting this index search elsewhere (this code is very indented and repeated above).
id_team integer,
id_user integer,
role char(1) CHECK (role IN ('Coach', 'Player')),
role char(1) CHECK (role IN ('Coach', 'Player')),
Since we're here, the
CHAR
type is not valid if we see those checks.TEXT
is the only SQLite type adapted here.*/
public function saveContent(int $id, Account $account): HttpResponse {
return Control::runChecked([
"content" => [],
No
HTTP 413 Content too large
?Checking the vague structure of the JSON object also help API user to catch their mistakes.
checks about tactics in backend will be done later as the structure will evolve too much and we'll need to keep it in sync between front end definition and backend checks
While your point is valid, I would argue that since
players
is nested incontent
, it misses a free check that it is an array. Anyway, it is perfectly fine as it is for now.);
}
public function updateContent(int $id, string $json): void {
This does not check neither if the id is valid nor if the user is the owner of this tactic.
For the first point, you reach the limits of your current
Connection
class.For the second point, it may happen elsewhere.
Persist tacticsto WIP: Persist tactics 1 year agoWIP: Persist tacticsto WIP: Persist tactics 1 year agoWIP: Persist tacticsto Persist tactics 1 year agoee977a0e7b
to84965a0fad
1 year ago84965a0fad
tocb24dd53a9
1 year agoSome nitpicks, it is really qualitative otherwise!
const x = player.rightRatio
const y = player.bottomRatio
const [x, setX] = useState(player.rightRatio)
const [y, setY] = useState(player.bottomRatio)
Keep one source of truth, it is either the state or the props.
const { x, y } = calculateRatio(pieceBounds, parentBounds)
setX(x)
setY(y)
default_value={name}
on_validated={(new_name) => {
onNameChange(new_name).then((success) => {
success ? setStyle({}) : setStyle(ERROR_STYLE)
}
return state
})
}, [])
Just for exhaustiveness, does not change anything here since this hook is always called without any local capture and does not change.
"content" => [],
], function (HttpRequest $req) use ($id) {
if ($fail = $this->model->updateContent($id, json_encode($req["content"]))) {
return new JsonHttpResponse([$fail]);
3de131d112
into master 1 year agoReviewers
3de131d112
.