-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add user PFP support and context to logo (#408)
* fix sizing of onboarding modals & lint * fix extra scrolling on mobile onboarding flow * added message to use desktop for onboarding * linting * add arrow to scroll to bottom (debounced) and fix chat scrolling to always scroll to very bottom on message history change * fix for empty chat * change mobile alert copy * WIP adding PFP upload support * WIP pfp for users * edit account menu complete with change username/password and upload profile picture * add pfp context to update all instances of usePfp hook on update * linting * add context for logo change to immediately update logo * fix div with bullet points to use list-disc instead * fix: small changes * update multer file storage locations * fix: use STORAGE_DIR for filepathing --------- Co-authored-by: timothycarambat <[email protected]>
- Loading branch information
1 parent
f48e6b1
commit fcb591d
Showing
16 changed files
with
656 additions
and
101 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,28 @@ | ||
import { createContext, useEffect, useState } from "react"; | ||
import AnythingLLM from "./media/logo/anything-llm.png"; | ||
import System from "./models/system"; | ||
|
||
export const LogoContext = createContext(); | ||
|
||
export function LogoProvider({ children }) { | ||
const [logo, setLogo] = useState(""); | ||
|
||
useEffect(() => { | ||
async function fetchInstanceLogo() { | ||
try { | ||
const logoURL = await System.fetchLogo(); | ||
logoURL ? setLogo(logoURL) : setLogo(AnythingLLM); | ||
} catch (err) { | ||
setLogo(AnythingLLM); | ||
console.error("Failed to fetch logo:", err); | ||
} | ||
} | ||
fetchInstanceLogo(); | ||
}, []); | ||
|
||
return ( | ||
<LogoContext.Provider value={{ logo, setLogo }}> | ||
{children} | ||
</LogoContext.Provider> | ||
); | ||
} |
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,30 @@ | ||
import React, { createContext, useState, useEffect } from "react"; | ||
import useUser from "./hooks/useUser"; | ||
import System from "./models/system"; | ||
|
||
export const PfpContext = createContext(); | ||
|
||
export function PfpProvider({ children }) { | ||
const [pfp, setPfp] = useState(null); | ||
const { user } = useUser(); | ||
|
||
useEffect(() => { | ||
async function fetchPfp() { | ||
if (!user?.id) return; | ||
try { | ||
const pfpUrl = await System.fetchPfp(user.id); | ||
setPfp(pfpUrl); | ||
} catch (err) { | ||
setPfp(null); | ||
console.error("Failed to fetch pfp:", err); | ||
} | ||
} | ||
fetchPfp(); | ||
}, [user?.id]); | ||
|
||
return ( | ||
<PfpContext.Provider value={{ pfp, setPfp }}> | ||
{children} | ||
</PfpContext.Provider> | ||
); | ||
} |
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,32 +1,35 @@ | ||
import React, { useRef, useEffect } from "react"; | ||
import JAZZ from "@metamask/jazzicon"; | ||
import usePfp from "../../hooks/usePfp"; | ||
|
||
export default function Jazzicon({ size = 10, user, role }) { | ||
const { pfp } = usePfp(); | ||
const divRef = useRef(null); | ||
const seed = user?.uid | ||
? toPseudoRandomInteger(user.uid) | ||
: Math.floor(100000 + Math.random() * 900000); | ||
const result = JAZZ(size, seed); | ||
|
||
useEffect(() => { | ||
if (!divRef || !divRef.current) return null; | ||
if (!divRef.current || (role === "user" && pfp)) return; | ||
|
||
const result = JAZZ(size, seed); | ||
divRef.current.appendChild(result); | ||
}, []); // eslint-disable-line react-hooks/exhaustive-deps | ||
}, [pfp, role, seed, size]); | ||
|
||
return ( | ||
<div | ||
className={`flex ${role === "user" ? "user-reply" : ""}`} | ||
ref={divRef} | ||
/> | ||
<div className="relative w-[35px] h-[35px] rounded-full flex-shrink-0 overflow-hidden"> | ||
<div ref={divRef} /> | ||
{role === "user" && pfp && ( | ||
<img | ||
src={pfp} | ||
alt="User profile picture" | ||
className="absolute top-0 left-0 w-full h-full object-cover rounded-full bg-white" | ||
/> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
function toPseudoRandomInteger(uidString = "") { | ||
var numberArray = [uidString.length]; | ||
for (var i = 0; i < uidString.length; i++) { | ||
numberArray[i] = uidString.charCodeAt(i); | ||
} | ||
|
||
return numberArray.reduce((a, b) => a + b, 0); | ||
return uidString.split("").reduce((acc, char) => acc + char.charCodeAt(0), 0); | ||
} |
Oops, something went wrong.