-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from FetchCV/dev
User search in global nav bar
- Loading branch information
Showing
15 changed files
with
236 additions
and
345 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
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
async function getId() { | ||
try { | ||
const response = await fetch(`https://api.github.com/users/${username}`, header); | ||
if (response.ok) { | ||
return (await response.json()).id; | ||
} | ||
} | ||
catch (error) { | ||
console.error("Failed to fetch github id. Error - ", error); | ||
} | ||
} | ||
try { | ||
const response = await fetch(`https://api.github.com/users/${username}`, header); | ||
if (response.ok) { | ||
return (await response.json()).id; | ||
} | ||
} | ||
catch (error) { | ||
console.error("Failed to fetch github id. Error - ", error); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,78 @@ | ||
// @ts-nocheck | ||
|
||
//=============================================== | ||
// Username search | ||
//=============================================== | ||
|
||
let usernameElement = document.getElementById("user-name") as HTMLInputElement; | ||
|
||
const usernameInput = document.getElementById("user-name"); | ||
if (usernameInput) { | ||
usernameInput.addEventListener("keyup", (event) => { | ||
if (usernameElement.value.length > 0) { | ||
showElement(searchResultsElement); | ||
getUpdatedSearchResults(usernameElement.value); | ||
} | ||
else { | ||
hideElement(searchResultsElement); | ||
showUpdatedSearchResults([]); | ||
} | ||
}); | ||
} | ||
|
||
async function getUpdatedSearchResults(search) { | ||
try { | ||
const response = await fetch(`/search/user/${search.replace("/", "slash")}`); | ||
if (response.ok) { | ||
let data = await response.json(); | ||
showUpdatedSearchResults(data.users); | ||
} | ||
} | ||
catch (error) { | ||
console.error("Error fetching users - ", error); // should show to user | ||
} | ||
} | ||
|
||
let searchResultsElement = document.querySelector(".search-results"); | ||
|
||
function showUpdatedSearchResults(users) { | ||
searchResultsElement.innerHTML = ""; | ||
for (let i = 0; i < users.length; i++) { | ||
let user = users[i]; | ||
let userElement = document.createElement("div"); | ||
createSearchResultElement(userElement, user.handle, user.profile.description); | ||
let divider = document.createElement("hr"); | ||
divider.classList.add("dark:border-zinc-700"); | ||
userElement.append(divider); | ||
searchResultsElement.append(userElement); | ||
} | ||
// Should only show if github username does exist | ||
if (usernameElement.value.length > 0) { | ||
let userElement = document.createElement("div"); | ||
createSearchResultElement(userElement, "github/" + usernameElement.value, "No results? Try with their GitHub username"); | ||
searchResultsElement.append(userElement); | ||
} | ||
} | ||
|
||
function createSearchResultElement(element, name, description) { | ||
element.innerHTML = ` | ||
<div class="bg-white dark:bg-zinc-900 rounded-lg my-2 px-4 py-2"> | ||
<a href="/user/${name}"> | ||
<p class="text-lg">${name}</p> | ||
<p class="font-light">${description}</p> | ||
</a> | ||
</div> | ||
`; | ||
} | ||
|
||
function showElement(element) { | ||
if (element.classList.contains("hidden")) { | ||
element.classList.remove("hidden"); | ||
} | ||
} | ||
|
||
function hideElement(element) { | ||
if (!element.classList.contains("hidden")) { | ||
element.classList.add("hidden"); | ||
} | ||
} |
Oops, something went wrong.