-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currently if there is no avatar then the space header can display a broken image link. This PR adds a simple check to see if the avatar exists. If it doesn't then we don't add the DOM for it. I decided to do it outside of the 'component' rendering just to keep things cleaner + sync after the main function but I'm happy to change this. Could be optimised to make the fetches in parallel but the difference is probably minor in most cases. Screenshot: <img width="911" alt="Screenshot 2024-07-23 at 10 19 56" src="https://github.com/user-attachments/assets/29b70a51-d2a8-4352-95ab-cc29e37b7c53"> cc @enzostvs @coyotte508 @julien-c --------- Co-authored-by: enzo <[email protected]>
- Loading branch information
Showing
6 changed files
with
25 additions
and
5 deletions.
There are no files selected for viewing
6 changes: 4 additions & 2 deletions
6
packages/space-header/src/header/components/content/avatar.ts
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
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,10 @@ | ||
export const check_avatar = async (username: string, type: "user" | "org" = "user"): Promise<boolean> => { | ||
const route = type === "user" ? "users" : "organizations"; | ||
|
||
try { | ||
const response = await fetch(`https://huggingface.co/api/${route}/${username}/avatar`); | ||
return response.ok; | ||
} catch (error) { | ||
return false; | ||
} | ||
}; |
3 changes: 2 additions & 1 deletion
3
packages/space-header/src/get_space.ts → packages/space-header/src/utils/get_space.ts
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