diff --git a/package-lock.json b/package-lock.json index bb0e6c4..3ecf5e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,9 +9,11 @@ "version": "0.1.0", "dependencies": { "@tauri-apps/api": "^1.1.0", + "@types/lodash": "^4.14.187", "@types/node": "18.11.9", "@types/react": "18.0.24", "@types/react-dom": "18.0.8", + "lodash": "^4.17.21", "next": "13.0.1", "react": "18.2.0", "react-dom": "18.2.0", @@ -452,6 +454,11 @@ "node": ">= 10" } }, + "node_modules/@types/lodash": { + "version": "4.14.187", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.187.tgz", + "integrity": "sha512-MrO/xLXCaUgZy3y96C/iOsaIqZSeupyTImKClHunL5GrmaiII2VwvWmLBu2hwa0Kp0sV19CsyjtrTc/Fx8rg/A==" + }, "node_modules/@types/node": { "version": "18.11.9", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.9.tgz", @@ -936,6 +943,11 @@ "node": ">=10" } }, + "node_modules/lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + }, "node_modules/loose-envify": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", @@ -1764,6 +1776,11 @@ "dev": true, "optional": true }, + "@types/lodash": { + "version": "4.14.187", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.187.tgz", + "integrity": "sha512-MrO/xLXCaUgZy3y96C/iOsaIqZSeupyTImKClHunL5GrmaiII2VwvWmLBu2hwa0Kp0sV19CsyjtrTc/Fx8rg/A==" + }, "@types/node": { "version": "18.11.9", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.9.tgz", @@ -2107,6 +2124,11 @@ "integrity": "sha512-9JROoBW7pobfsx+Sq2JsASvCo6Pfo6WWoUW79HuB1BCoBXD4PLWJPqDF6fNj67pqBYTbAHkE57M1kS/+L1neOg==", "dev": true }, + "lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + }, "loose-envify": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", diff --git a/package.json b/package.json index 425bfce..f914238 100644 --- a/package.json +++ b/package.json @@ -12,9 +12,11 @@ }, "dependencies": { "@tauri-apps/api": "^1.1.0", + "@types/lodash": "^4.14.187", "@types/node": "18.11.9", "@types/react": "18.0.24", "@types/react-dom": "18.0.8", + "lodash": "^4.17.21", "next": "13.0.1", "react": "18.2.0", "react-dom": "18.2.0", diff --git a/pages/index.tsx b/pages/index.tsx index 218edee..aff3319 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -2,26 +2,57 @@ import Head from 'next/head'; import { invoke } from '@tauri-apps/api/tauri'; import Image from 'next/image'; import styles from '../styles/Home.module.css'; -import { useEffect } from 'react'; +import React, { useEffect, useState, useMemo } from 'react'; +import { debounce } from 'lodash'; export default function Home() { + + const [search, setSearch] = useState(''); + const [cards, setCards] = useState([]); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(false); + const [queryParams, setQueryParams] = useState(''); + + const searchForCard = async (event: React.ChangeEvent) => { + event.stopPropagation(); + setSearch(event.target.value); + setLoading(true); + await fetch(`https://api.scryfall.com/cards/search?q=${encodeURIComponent(event.target.value)}`) + .then( res => res.json() ) + .then( ({data}) => { + setCards(data); + setLoading(false); + }) + .catch( err => console.log(err) ); + }; + + const debounceSearch = useMemo( () => debounce(searchForCard, 300), [search] ); + useEffect(() => { invoke('greet', { name: 'World' }).then(console.log).catch(console.error); - fetch(`https://api.scryfall.com/cards/search?order=cmc&q=c%3Ared+pow%3D3`).then( data => console.log( data ) ); }, []); + return ( -
+
Magic Card Valuator -
-

- Hello world! -

-

- Welcome to Next.js! -

+
+
+ + +
+
+ +
+
+ {loading && !cards.length ? +
+ : + cards && cards.map( (card: any) => {`${card.name} ) + } +