Skip to content

Commit

Permalink
Add DEFAULT_URL
Browse files Browse the repository at this point in the history
  • Loading branch information
vpodk committed Apr 5, 2024
1 parent bfe4479 commit 1e77286
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/app/components/search/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Product } from "./types";
const API_URL_DEV = "http://localhost:3001";
const API_URL_PROD = "https://api.wiseblend.ai";
const API_ENDPOINT = "/dupes/search";
const DEFAULT_URL = "https://www.obagi.com/products/professional-c-serum-20";

export default function SearchForm() {
const inputRef = useRef<HTMLInputElement>(null);
Expand All @@ -24,26 +25,26 @@ export default function SearchForm() {
if (input) input.value = "Loading...";

const reset = () => {
if (input) input.value = "";
if (input) input.value = DEFAULT_URL;
if (image) image.value = "";
};

if (url) {
fetch(endpoint + encodeURIComponent(url))
if (img) {
const data = new FormData();
data.append("image", img);
fetch(endpoint, { method: "POST", body: data })
.then((res) => res.json())
.then((data) => {
setProducts(data.dupes || []);
reset();
input.value = url;
});
} else if (img) {
const data = new FormData();
data.append("image", img);
fetch(endpoint, { method: "POST", body: data })
} else if (url) {
fetch(endpoint + encodeURIComponent(url))
.then((res) => res.json())
.then((data) => {
setProducts(data.dupes || []);
reset();
input.value = url;
});
} else {
reset();
Expand All @@ -57,6 +58,7 @@ export default function SearchForm() {
type="url"
className="grow px-4 rounded-l-2xl"
placeholder="Enter product URL or product screenshot"
defaultValue={DEFAULT_URL}
/>
<input
ref={imageRef}
Expand Down

0 comments on commit 1e77286

Please sign in to comment.