Skip to content

Commit

Permalink
feat: add searchbar for villagers
Browse files Browse the repository at this point in the history
  • Loading branch information
sheidiz committed Dec 8, 2023
1 parent b3cb7be commit fc7c00a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const links = [
] as const;

const api = 'https://api.nookipedia.com/';
const apiKey = process.env.NEXT_NOOKIPEDIA_API_KEY; /*hard coding bc it doesnt work */
const apiKey = ""; /*hard coding bc it doesnt work */

/* Api Fetch Internal Function */
async function getData(path) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/(pages)/events/page.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React from "react"

export default function page() {
return (
Expand Down
2 changes: 1 addition & 1 deletion src/app/(pages)/selling-items/page.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React from "react"

export default function page() {
return (
Expand Down
17 changes: 17 additions & 0 deletions src/app/(pages)/villagers/(filters)/search.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from "react"

export default function Search({ setSearch, setCurrentPage }) {
return (
<form className="mt-1 mb-3 mx-0 md:mx-5 text-center">
<input
placeholder="Search for a villager..."
type="text"
className="w-[50vw] border border-red-300 p-2 rounded-lg shadow-lg"
onChange={ e => {
setSearch(e.target.value);
setCurrentPage(0);
} }
/>
</form>
)
}
28 changes: 15 additions & 13 deletions src/app/(pages)/villagers/page.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"use client";

import React, { useEffect, useState } from 'react'
import { getVillagers } from '../../../../lib/data.ts'
import Loading from '@/components/loading.jsx';
import VillagerCard from './villagerCard.jsx';
import React, { useEffect, useState } from "react"
import { getVillagers } from "../../../../lib/data.ts"
import Loading from "@/components/loading.jsx";
import VillagerCard from "./villagerCard.jsx";
import Search from "./(filters)/search.jsx";

export default function Villagers() {

Expand All @@ -12,10 +13,10 @@ export default function Villagers() {
const [pages, setPages] = useState();
const [currentPage, setCurrentPage] = useState(0);

const [search, setSearch] = useState('');
const [gender, setGender] = useState('');
const [species, setSpecies] = useState('');
const [sign, setSign] = useState('');
const [search, setSearch] = useState("");
const [gender, setGender] = useState("");
const [species, setSpecies] = useState("");
const [sign, setSign] = useState("");

useEffect(() => {
const getData = async () => {
Expand All @@ -27,19 +28,20 @@ export default function Villagers() {
const pages = Math.ceil(totalItems / 10);
setPages(pages);
} catch (error) {
console.error('Error fetching villagers:', error);
console.error("Error fetching villagers:", error);
}
setLoading(false);
};
getData();
}, [search, gender, species, sign]);

return (
<div className='my-3 md:my-6'>
<div id="title" className='text-red-300 text-center text-5xl font-bold mb-5'>
<h1>Villagers</h1>
<div className="my-3 md:my-6">
<div>
<h1 className="text-red-300 text-center text-5xl font-bold mb-5">Villagers</h1>
<Search setSearch={setSearch} setCurrentPage={setCurrentPage} />
</div>
<div className='grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-5'>
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-5">
{
loading ? (<Loading />) : (<VillagerCard results={data[currentPage]} />)
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/loading.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React from "react"

export default function Loading() {
return (
Expand Down

0 comments on commit fc7c00a

Please sign in to comment.