From c857a18619c1036ec81359b0389f52645b1511fe Mon Sep 17 00:00:00 2001 From: april Date: Wed, 3 Jan 2024 15:40:18 -0600 Subject: [PATCH] Reload flight list when new flight is added --- web/app/root.tsx | 2 +- web/app/routes/logbook.flights.new/route.tsx | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/web/app/root.tsx b/web/app/root.tsx index ad40614..12280d9 100644 --- a/web/app/root.tsx +++ b/web/app/root.tsx @@ -45,7 +45,7 @@ export const links: LinksFunction = () => [ }, { rel: "icon", - href: "/favicon/favicon-16x1166.png", + href: "/favicon/favicon-16x16.png", type: "image/png", sizes: "16x16", }, diff --git a/web/app/routes/logbook.flights.new/route.tsx b/web/app/routes/logbook.flights.new/route.tsx index 191db4a..c7cedb5 100644 --- a/web/app/routes/logbook.flights.new/route.tsx +++ b/web/app/routes/logbook.flights.new/route.tsx @@ -21,7 +21,7 @@ import { FlightFormSchema, flightCreateHelper } from "@/util/types"; import { HourInput, ZeroHourInput } from "@/ui/form/hour-input"; import { ZeroIntInput } from "@/ui/form/int-input"; import ListInput from "@/ui/form/list-input"; -import { useMutation } from "@tanstack/react-query"; +import { useMutation, useQueryClient } from "@tanstack/react-query"; import { client } from "@/util/api"; import { useNavigate } from "@remix-run/react"; @@ -77,16 +77,22 @@ export default function NewFlight() { }); const navigate = useNavigate(); + const queryClient = useQueryClient(); const createFlight = useMutation({ mutationFn: async (values: FlightFormSchema) => { const newFlight = flightCreateHelper(values); const res = await client.post("/flights", newFlight); - navigate(`/logbook/flights/${res.data.id}`); + console.log(res); + return res.data; }, onError: (error) => { console.log(error); }, + onSuccess: async (data: { id: string }) => { + await queryClient.invalidateQueries({ queryKey: ["flights-list"] }); + navigate(`/logbook/flights/${data.id}`); + }, }); return (