fix(inventory): robustare dedup vid skann + borttag pa startsidan
Dedup vid /v1/scans/:id/confirm matchade bara pa exakt (skiftlageskansligt) namn eller identiskt katalog-id, sa omfotografering av samma hylla skapade dubbletter. Ny normalizeItemName (gemener, accenter, storlek bort; behaller fetthalt-siffror) + matchning pa katalog-id ELLER normaliserat namn mot aktivt hushallslager. Mobil: 'Ta bort' fanns bara i Ditt kok. Lade borttag pa startsidans lager-rader (befintlig DELETE /v1/inventory/items/:id). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WZdew6cWn1MeHqoYWFfxzo
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Pressable, View } from "react-native";
|
||||
import { Alert, Pressable, View } from "react-native";
|
||||
import { useCallback } from "react";
|
||||
import { router, useFocusEffect } from "expo-router";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { api } from "@/lib/api";
|
||||
import { useAuth } from "@/lib/auth";
|
||||
import { t } from "@/lib/i18n";
|
||||
@@ -9,6 +9,7 @@ import * as Haptics from "expo-haptics";
|
||||
import { formatMinor } from "@/lib/money";
|
||||
import {
|
||||
Body,
|
||||
Button,
|
||||
Card,
|
||||
EmptyState,
|
||||
ErrorView,
|
||||
@@ -41,6 +42,18 @@ interface BudgetSummary {
|
||||
}
|
||||
|
||||
export default function HomeScreen() {
|
||||
const queryClient = useQueryClient();
|
||||
const remove = useMutation({
|
||||
mutationFn: (id: string) => api(`/v1/inventory/items/${id}`, { method: "DELETE" }),
|
||||
onError: (err) =>
|
||||
Alert.alert(t("common.oops"), err instanceof Error ? err.message : t("common.error")),
|
||||
onSettled: () => void queryClient.invalidateQueries({ queryKey: ["inventory"] }),
|
||||
});
|
||||
const confirmRemove = (id: string, name: string) =>
|
||||
Alert.alert("Ta bort", `Ta bort ${name} ur ditt lager?`, [
|
||||
{ text: t("common.cancel"), style: "cancel" },
|
||||
{ text: "Ta bort", style: "destructive", onPress: () => remove.mutate(id) },
|
||||
]);
|
||||
const inventory = useQuery({
|
||||
queryKey: ["inventory"],
|
||||
queryFn: () =>
|
||||
@@ -160,11 +173,18 @@ export default function HomeScreen() {
|
||||
<Card key={location}>
|
||||
<Heading>{location}</Heading>
|
||||
{locationItems.slice(0, 12).map((item) => (
|
||||
<Row key={item.id} style={{ justifyContent: "space-between" }}>
|
||||
<Row key={item.id} style={{ justifyContent: "space-between", alignItems: "center" }}>
|
||||
<Body>
|
||||
{item.displayName} · {formatQuantity(item.quantity, item.unit)}
|
||||
</Body>
|
||||
<ExpiryTag expiry={item.expiry} />
|
||||
<Row style={{ alignItems: "center" }}>
|
||||
<ExpiryTag expiry={item.expiry} />
|
||||
<Button
|
||||
label="Ta bort"
|
||||
variant="ghost"
|
||||
onPress={() => confirmRemove(item.id, item.displayName)}
|
||||
/>
|
||||
</Row>
|
||||
</Row>
|
||||
))}
|
||||
{locationItems.length > 12 && (
|
||||
|
||||
Reference in New Issue
Block a user