Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
fix: search dropdown placeholder and input now update correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
IncognitoTGT committed Feb 6, 2024
1 parent 572ca32 commit af772fb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 1 addition & 3 deletions src/pages/settings/CloakSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ export default function CloakSettings() {
<SelectTrigger aria-label="Presets">
<SelectValue
placeholder={
localStorage.getItem("cloakPreset")
? localStorage.getItem("cloakPreset")
: "Select a preset"
localStorage.getItem("cloakPreset") || "Select a preset"
}
/>
<SelectContent position="popper">
Expand Down
20 changes: 11 additions & 9 deletions src/pages/settings/SearchSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRef } from "react";
import { useRef, useState } from "react";
import {
Card,
CardContent,
Expand All @@ -20,7 +20,11 @@ import { Button } from "@/components/ui/button";
import { useToast } from "@/components/ui/use-toast";
export default function SearchSettings() {
const { toast } = useToast();
const [searchUrl, setSearchUrl] = useState(
localStorage.getItem("searchUrl") || "https://google.com/search?q=",
);
const customSearchRef = useRef<HTMLInputElement>(null);
const selectRef = useRef<HTMLSelectElement>(null);
return (
<>
<Card className="h-96 w-96">
Expand All @@ -35,31 +39,26 @@ export default function SearchSettings() {
<Select
aria-label="Search Engine"
onValueChange={(value) => {
localStorage.setItem("search", value);
if (value === "Google") {
localStorage.setItem("search", "Google");
localStorage.setItem(
"searchUrl",
"https://google.com/search?q=",
);
} else if (value === "DuckDuckGo") {
localStorage.setItem("search", "DuckDuckGo");
localStorage.setItem("searchUrl", "https://duckduckgo.com/?q=");
} else if (value === "Bing") {
localStorage.setItem("search", "Bing");
localStorage.setItem("searchUrl", "https://bing.com/search?q=");
}
setSearchUrl(localStorage.getItem("searchUrl") || "");
toast({
title: "Search Engine Changed",
description: "Search Engine has been changed to " + value,
});
}}
>
<SelectTrigger aria-label="Presets">
<SelectValue
placeholder={
localStorage.getItem("search") || "Select a search engine"
}
/>
<SelectValue placeholder={localStorage.getItem("search") ||"Select a search engine"} ref={selectRef}/>
</SelectTrigger>
<SelectContent position="popper" className=" text-white">
<SelectItem value="Google">Google</SelectItem>
Expand All @@ -75,12 +74,15 @@ export default function SearchSettings() {
ref={customSearchRef}
spellCheck={false}
placeholder="Enter a valid Search Engine URL"
value={searchUrl}
onChange={(e) => setSearchUrl(e.target.value)}
/>
</CardContent>
<CardFooter>
<Button
onClick={() => {
localStorage.setItem("search", "Custom");
selectRef.current!.value = "Custom";
if (customSearchRef.current!.value === "") {
localStorage.setItem(
"searchUrl",
Expand Down

0 comments on commit af772fb

Please sign in to comment.