From 10f93e96434fa65f582216b0a3f8ddbfa7c8bb88 Mon Sep 17 00:00:00 2001 From: Donkoko Date: Mon, 15 Apr 2024 12:37:04 +0300 Subject: [PATCH] changing location selector on update-location route to new DynamicSelect --- app/components/location/location-select.tsx | 139 +++++------------- .../assets.$assetId.update-location.tsx | 6 +- 2 files changed, 44 insertions(+), 101 deletions(-) diff --git a/app/components/location/location-select.tsx b/app/components/location/location-select.tsx index 7434b7218..d8f92324f 100644 --- a/app/components/location/location-select.tsx +++ b/app/components/location/location-select.tsx @@ -1,36 +1,21 @@ -import { useMemo, useState } from "react"; -import { useLoaderData } from "@remix-run/react"; +import { useState } from "react"; +import { useLoaderData, useNavigation } from "@remix-run/react"; import { Button } from "~/components/shared/button"; import type { loader } from "~/routes/_layout+/assets.$assetId.update-location"; +import { isFormProcessing } from "~/utils/form"; import { tw } from "~/utils/tw"; -import { SearchInput } from "./search-input"; -import { useLocationSearch } from "./useLocationSearch"; -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue, -} from "../forms/select"; +import DynamicSelect from "../dynamic-select/dynamic-select"; + import { XIcon } from "../icons/library"; import { Image } from "../shared/image"; export const LocationSelect = () => { - /** This takes care of the search bar inside the dropdown */ - const { - locationSearch, - refinedLocations, - isSearchingLocations, - handleLocationSearch, - clearLocationSearch, - } = useLocationSearch(); + const navigation = useNavigation(); - const hasLocations = useMemo( - () => refinedLocations.length > 0, - [refinedLocations] - ); const { asset } = useLoaderData(); + const [locationId, setLocationId] = useState(asset.locationId || undefined); + const disabled = isFormProcessing(navigation.state); return (
@@ -40,84 +25,40 @@ export const LocationSelect = () => { value={asset.locationId || ""} />
- {/* setting locationId as a key if it exists else a random string to clear select, solution based on https://github.com/radix-ui/primitives/issues/1569#issuecomment-1434801848*/} -