fix(inkopslista): visa den genererade listan (inte en gammal tom)
POST aterananvander EN aktiv lista per veckoplan (staplar inte nya), GET sorterar nyaste forst, och appen navigerar med listId. Tidigare hamnade de genererade raderna i en lista skarmen inte visade -> tomt.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { useState } from "react";
|
||||
import { Alert, Pressable, Text, View } from "react-native";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useLocalSearchParams } from "expo-router";
|
||||
import { api } from "@/lib/api";
|
||||
import { t } from "@/lib/i18n";
|
||||
import { formatMinor } from "@/lib/money";
|
||||
@@ -61,6 +62,8 @@ const sectionLabel = (id: string): string =>
|
||||
export default function ShoppingScreen() {
|
||||
const queryClient = useQueryClient();
|
||||
const [newItem, setNewItem] = useState("");
|
||||
const params = useLocalSearchParams<{ listId?: string }>();
|
||||
const paramListId = typeof params.listId === "string" ? params.listId : undefined;
|
||||
|
||||
const lists = useQuery({
|
||||
queryKey: ["shopping-lists"],
|
||||
@@ -76,7 +79,9 @@ export default function ShoppingScreen() {
|
||||
return result.lists;
|
||||
},
|
||||
});
|
||||
const listId = lists.data?.[0]?.id;
|
||||
// Prioritera listId från navigering (t.ex. nygenererad från veckoplan),
|
||||
// annars nyaste aktiva listan.
|
||||
const listId = paramListId ?? lists.data?.[0]?.id;
|
||||
|
||||
const list = useQuery({
|
||||
queryKey: ["shopping-list", listId],
|
||||
|
||||
Reference in New Issue
Block a user