-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
157 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import { technology, codes } from "../json"; | ||
import CodeCard from "./CodeCard"; | ||
import content from "../content/content.yaml"; | ||
import tabs from "../content/tabs.yaml"; | ||
|
||
export default function SearchListing() { | ||
const [currentTab, setCurrentTab] = useState({ id: 1, title: "reactJs" }); | ||
const [code, setCode] = useState<any>([]); | ||
const [isLoading, setLoading] = useState(true); | ||
|
||
useEffect(() => { | ||
setLoading(true); | ||
fetchData(); | ||
}, [currentTab]); | ||
|
||
const fetchData = async () => { | ||
const data = content.filter((item) => { | ||
return item.technology == currentTab.title; | ||
}); | ||
setCode(data); | ||
setLoading(false); | ||
}; | ||
|
||
const returnNotFound = () => { | ||
return ( | ||
<div className="text-center"> | ||
<p className="font-thin">No Result Found</p> | ||
</div> | ||
); | ||
}; | ||
|
||
const returnLoading = () => { | ||
return ( | ||
<div className="text-center"> | ||
<p className="font-thin">Loading..</p> | ||
</div> | ||
); | ||
}; | ||
|
||
const returnResult = () => { | ||
return ( | ||
<div> | ||
{code.length > 0 ? ( | ||
<ul className="mb-8"> | ||
{code.map((item: any) => ( | ||
<CodeCard | ||
key={item.id} | ||
id={item.id} | ||
title={item.title} | ||
code={item.code} | ||
/> | ||
))} | ||
</ul> | ||
) : ( | ||
returnNotFound() | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
return ( | ||
<div className="flex flex-col justify-center items-center p-4 w-full min-h-[90vh] max-w-5xl mt-8"> | ||
<section className="mt-8 w-full"> | ||
{isLoading ? returnLoading() : returnResult()} | ||
</section> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import Link from "next/link"; | ||
import React, { useEffect, useState } from "react"; | ||
import { technology, placeholders } from "../json"; | ||
|
||
export default function SecondarySearch() { | ||
const [query, setQuery] = useState(""); | ||
const [isVisible, setVisible] = useState(false); | ||
const [placeholder, setPlaceholder] = useState(placeholders[0]); | ||
|
||
useEffect(() => { | ||
if (query.length > 2) { | ||
setVisible(true); | ||
} else { | ||
setVisible(false); | ||
} | ||
}, [query]); | ||
|
||
useEffect(() => { | ||
const timer = setTimeout(() => { | ||
if (placeholder.id < placeholders.length) { | ||
setPlaceholder(placeholders[placeholder.id]); | ||
} else { | ||
setPlaceholder(placeholders[0]); | ||
} | ||
}, 3000); | ||
return () => clearTimeout(timer); | ||
}, [placeholder]); | ||
|
||
const returnSuggestions = () => { | ||
return ( | ||
<div className="bg-black border p-2 border-slate-800 mt-1 rounded-md w-96 z-50 absolute"> | ||
<ul> | ||
{technology.map((item) => ( | ||
<li | ||
className="mt-2 text-sm font-light text-slate-400 cursor-pointer hover:text-white hover:bg-gradient-to-br from-[#FF4D4D] to-orange-500 pt-1 pb-1 pl-1 rounded-md" | ||
key={item.id} | ||
> | ||
{item.title} | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
); | ||
}; | ||
return ( | ||
<div> | ||
<div className="mt-0 flex"> | ||
<input | ||
onChange={(e) => setQuery(e.target.value)} | ||
className="bg-black border-l border-r border-t border-b rounded-l-lg p-2 border-slate-800 h-12 w-96 max-w-[75vw] text-sm" | ||
placeholder={placeholder.placeholder} | ||
/> | ||
<div className="p-2 flex items-center justify-center cursor-pointer bg-gradient-to-br from-[#FF4D4D] to-orange-500 rounded-r-lg text-sm pl-3 pr-3"> | ||
<svg | ||
className="w-6 h-6" | ||
fill="none" | ||
stroke="currentColor" | ||
viewBox="0 0 24 24" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
stroke-width="2" | ||
d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" | ||
></path> | ||
</svg> | ||
</div> | ||
</div> | ||
{isVisible && returnSuggestions()} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters