Pass whole updated set instead of just its id

Since we already have the whole updated set,
might as well pass it around instead of
re-fetching it.
This commit is contained in:
Brandon Presley 2023-08-29 11:25:05 +12:00
parent 103ae5587d
commit 386a9a7bb2
3 changed files with 7 additions and 6 deletions

View File

@ -105,7 +105,7 @@ export default function EditSet() {
const saved = await setRepo.save(newSet);
if (typeof set.id !== "number") return added(saved);
if (createdDirty) navigate("Sets", { reset: saved.id });
else navigate("Sets", { refresh: saved.id });
else navigate("Sets", { refresh: saved });
};
const changeImage = useCallback(async () => {

View File

@ -29,10 +29,11 @@ export default function SetList() {
const { params } = useRoute<RouteProp<HomePageParams, "Sets">>();
const [term, setTerm] = useState(params?.search || "");
const refresh = async (id: number) => {
const refresh = async (gymSet: GymSet) => {
if (!sets) return;
const set = await setRepo.findOne({ where: { id } });
let newSets = sets.map((oldSet) => (oldSet.id === id ? set : oldSet));
const newSets = sets.map((oldSet) =>
oldSet.id === gymSet.id ? gymSet : oldSet
);
setSets(newSets);
};

View File

@ -5,9 +5,9 @@ export type HomePageParams = {
search?: string;
/**
* Reload the specified set by ID.
* Update the specified set
*/
refresh?: number;
refresh?: GymSet;
/**
* Reload the list with limit = 0