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

Commit

Permalink
feat: search (#947)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiejaoude committed Dec 31, 2021
1 parent 6ad757d commit 7798320
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 11 deletions.
16 changes: 16 additions & 0 deletions Components/Profile/Profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Card } from "primereact/card";

function Profile({ profile }) {
return (
<Card
className="p-mr-4 p-mb-4"
key={profile.name}
header={<img src={profile.image} alt={profile.name} />}
title={profile.name}
subTitle={profile.username}
style={{ width: "200px" }}
></Card>
);
}

export default Profile;
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"next": "12.0.7",
"primeflex": "^2.0.0",
"primeicons": "^5.0.0",
"primereact": "^7.0.1",
"react": "17.0.2",
Expand Down
1 change: 1 addition & 0 deletions pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import "../styles/globals.css";
import "primereact/resources/themes/lara-light-indigo/theme.css";
import "primereact/resources/primereact.min.css";
import "primeicons/primeicons.css";
import "primeflex/primeflex.css";

function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />;
Expand Down
59 changes: 48 additions & 11 deletions pages/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
import Head from "next/head";

import { Card } from "primereact/card";
import { useState } from "react";

import { Menubar } from "primereact/menubar";
import { InputText } from "primereact/inputtext";

import Profile from "../Components/Profile/Profile";

export async function getStaticProps() {
const res = await fetch("http://localhost:3000/api/profiles");
const data = await res.json();
const profiles = await res.json();

return {
props: { data },
props: {
profiles,
},
};
}

export default function Home({ data }) {
const card = (profile) => (
<Card header={<img src={profile.image} alt={profile.name} />}>
{profile.name}
</Card>
);
export default function Home({ profiles }) {
const [list, setList] = useState(profiles);
const items = [];

const search = (e) =>
setList(
profiles.filter(
(profile) =>
profile.name.includes(e.target.value) ||
profile.username.includes(e.target.value)
)
);

return (
<div>
Expand All @@ -26,9 +39,33 @@ export default function Home({ data }) {
</Head>

<main>
<h1>Awesome GitHub Profiles</h1>
<Menubar
className="p-mb-6"
model={items}
start={
<span>
<InputText placeholder="Search" type="text" onKeyUp={search} />{" "}
Awesome GitHub Profiles ({list.length})
</span>
}
end={
<a
href="https://github.com/EddieHubCommunity/awesome-github-profiles"
target="_blank"
>
<i className="pi pi-github"></i>
</a>
}
/>

{data && data.map((profile) => card(profile))}
<div className="p-d-flex p-flex-wrap p-m-4">
{profiles &&
list
// .slice(0, 9)
.map((profile) => (
<Profile key={profile.username} profile={profile} />
))}
</div>
</main>

<footer>
Expand Down

0 comments on commit 7798320

Please sign in to comment.