Skip to content

Commit dbb4c6c

Browse files
fix: new item keeps on when item selected
1 parent 5671020 commit dbb4c6c

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/pages/EditShelterSupply/EditShelterSupply.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const EditShelterSupply = () => {
3030
);
3131
const [, setSearchSupplies] = useThrottle<string>(
3232
{
33-
throttle: 400,
33+
throttle: 200,
3434
callback: (value) => {
3535
if (value) {
3636
const filteredSupplies = supplies.filter((s) =>
@@ -45,6 +45,7 @@ const EditShelterSupply = () => {
4545
},
4646
[supplies]
4747
);
48+
4849
const [, setSearch] = useThrottle<string>(
4950
{
5051
throttle: 400,

src/pages/EditShelterSupply/components/SupplySearch/SupplySearch.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const SupplySearch = ({
1313
onAddNewItem
1414
}: ISupplySearchProps) => {
1515
const [searchValue, setSearchValue] = useState<string>('');
16+
const [selectedItem, setSelectedItem] = useState<IUseSuppliesData | null>(null);
1617

1718
function onChangeInputHandler(event: React.ChangeEvent<HTMLInputElement>) {
1819
setSearchValue(event.target.value);
@@ -21,14 +22,17 @@ export const SupplySearch = ({
2122

2223
function onSelectItemHandler(item: IUseSuppliesData) {
2324
setSearchValue(item.name);
25+
setSelectedItem(item);
2426
onSelectItem(item);
2527
}
2628

2729
function onAddNewItemHandler() {
30+
setSelectedItem(null);
2831
onAddNewItem();
2932
}
3033

3134
function onClearClickHandler() {
35+
setSelectedItem(null);
3236
setSearchValue('');
3337
onSearch('');
3438
}
@@ -50,7 +54,7 @@ export const SupplySearch = ({
5054
<X className="h-4 w-4 ml-2 hover:cursor-pointer" onClick={onClearClickHandler} />
5155
</div>
5256

53-
{!!searchValue ? (
57+
{!!searchValue && !selectedItem ? (
5458
<div className="flex-col items-center rounded-md border border-input p-3 bg-slate-50 mt-1">
5559
{supplyItems.slice(0, limit).map((item) => (
5660
<div

0 commit comments

Comments
 (0)