-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
119 additions
and
71 deletions.
There are no files selected for viewing
25 changes: 0 additions & 25 deletions
25
apps/wish-wash/web/src/components/items/AmazonSearchButton.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { Button } from '@a-type/ui/components/button'; | ||
import { Icon } from '@a-type/ui/components/icon'; | ||
import { useLocalStorage } from '@biscuits/client'; | ||
import { Link } from '@verdant-web/react-router'; | ||
import { Item } from '@wish-wash.biscuits/verdant'; | ||
import { | ||
Select, | ||
SelectItem, | ||
SelectTrigger, | ||
SelectContent, | ||
SelectValue, | ||
SelectIcon, | ||
} from '@a-type/ui/components/select'; | ||
|
||
export interface SearchButtonProps { | ||
item: Item; | ||
} | ||
|
||
interface SearchConfig { | ||
name: string; | ||
template: string; | ||
} | ||
const searchConfigs: Record<string, SearchConfig> = { | ||
amazon: { | ||
name: 'Amazon', | ||
template: 'https://www.amazon.com/s?k=$1', | ||
}, | ||
ebay: { | ||
name: 'Ebay', | ||
template: 'https://www.ebay.com/sch/i.html?_nkw=$1', | ||
}, | ||
google: { | ||
name: 'Google', | ||
template: 'https://www.google.com/search?q=$1', | ||
}, | ||
walmart: { | ||
name: 'Walmart', | ||
template: 'https://www.walmart.com/search/?query=$1', | ||
}, | ||
target: { | ||
name: 'Target', | ||
template: 'https://www.target.com/s?searchTerm=$1', | ||
}, | ||
}; | ||
|
||
export function SearchButton({ item }: SearchButtonProps) { | ||
const [selectedProvider, setSelectedProvider] = useLocalStorage( | ||
'search-provider', | ||
'amazon', | ||
); | ||
|
||
return ( | ||
<div className="flex flex-row"> | ||
<Button asChild className="rounded-r-none relative z-1"> | ||
<Link | ||
to={searchConfigs[selectedProvider].template.replace( | ||
'$1', | ||
item.get('description'), | ||
)} | ||
> | ||
<Icon name="search" /> | ||
{searchConfigs[selectedProvider].name} | ||
</Link> | ||
</Button> | ||
<Select value={selectedProvider} onValueChange={setSelectedProvider}> | ||
<SelectTrigger className="rounded-l-none border-l-none !gap-0"> | ||
<SelectValue>{null}</SelectValue> | ||
<SelectIcon /> | ||
</SelectTrigger> | ||
<SelectContent> | ||
{Object.entries(searchConfigs).map(([key, { name }]) => ( | ||
<SelectItem key={key} value={key}> | ||
{name} | ||
</SelectItem> | ||
))} | ||
</SelectContent> | ||
</Select> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters