mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-12 11:26:07 +03:00
c140b9c517
* 💄 The chat sidebar takes the full height * 💄 redesign of the action section and buttons in the sidebar * ✨ Sidebar header * ♻️ Refact sidebar filesystem structure * ♻️ Create a separate reusable sidebar component * 🐛 Fix sidebar quick open/close on mobile * 💄 New open/close sidebar button * fix: error message + sidebar height issue + mobile width incoherence * ♻️ Rename and move the sidebar footer * 💄 sidebar toggle: color on hover * apply sidebar to brains-management * 💄 Larger sidebar * 🚨Pass existing tests * ✅ Test the sidebar * ✅ Test the open and close buttons in the sidebar
31 lines
1001 B
TypeScript
31 lines
1001 B
TypeScript
import { createHash } from "crypto";
|
|
import { useEffect, useState } from "react";
|
|
|
|
import { useSupabase } from "@/lib/context/SupabaseProvider";
|
|
|
|
// Gravatar images may be requested just like a normal image, using an IMG tag. To get an image specific to a user, you must first calculate their email hash.
|
|
// The most basic image request URL looks like this:
|
|
// https://www.gravatar.com/avatar/HASH
|
|
|
|
const computeGravatarUrl = (email?: string) => {
|
|
const hash = createHash("md5")
|
|
.update(typeof email === "string" ? email.trim().toLowerCase() : "")
|
|
.digest("hex");
|
|
|
|
return `https://www.gravatar.com/avatar/${hash}?d=mp`;
|
|
};
|
|
|
|
export const useGravatar = (): { gravatarUrl: string } => {
|
|
const { session } = useSupabase();
|
|
const [gravatarUrl, setGravatarUrl] = useState<string>(computeGravatarUrl());
|
|
|
|
const email = session?.user.email;
|
|
|
|
useEffect(() => {
|
|
const computedUrl = computeGravatarUrl(email);
|
|
setGravatarUrl(computedUrl);
|
|
}, [email]);
|
|
|
|
return { gravatarUrl };
|
|
};
|