From d3d336fa71cc789624b10f3cdd1a2b5983053e6f Mon Sep 17 00:00:00 2001 From: towfiqi Date: Fri, 3 Nov 2023 12:47:29 +0600 Subject: [PATCH] feat: Remembers last selected coutry closes #101 --- components/keywords/AddKeywords.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/components/keywords/AddKeywords.tsx b/components/keywords/AddKeywords.tsx index b26b0ce..ee19730 100644 --- a/components/keywords/AddKeywords.tsx +++ b/components/keywords/AddKeywords.tsx @@ -21,7 +21,8 @@ type KeywordsInput = { const AddKeywords = ({ closeModal, domain, keywords }: AddKeywordsProps) => { const [error, setError] = useState(''); - const [newKeywordsData, setNewKeywordsData] = useState({ keywords: '', device: 'desktop', country: 'US', domain, tags: '' }); + const defCountry = localStorage.getItem('default_country') || 'US'; + const [newKeywordsData, setNewKeywordsData] = useState({ keywords: '', device: 'desktop', country: defCountry, domain, tags: '' }); const { mutate: addMutate, isLoading: isAdding } = useAddKeywords(() => closeModal(false)); const deviceTabStyle = 'cursor-pointer px-3 py-2 rounded mr-2'; @@ -64,7 +65,10 @@ const AddKeywords = ({ closeModal, domain, keywords }: AddKeywordsProps) => { selected={[newKeywordsData.country]} options={Object.keys(countries).map((countryISO:string) => { return { label: countries[countryISO][0], value: countryISO }; })} defaultLabel='All Countries' - updateField={(updated:string[]) => setNewKeywordsData({ ...newKeywordsData, country: updated[0] })} + updateField={(updated:string[]) => { + setNewKeywordsData({ ...newKeywordsData, country: updated[0] }); + localStorage.setItem('default_country', updated[0]); + }} rounded='rounded' maxHeight={48} flags={true}