-
Notifications
You must be signed in to change notification settings - Fork 793
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 #263 from mfts/feat/avatar
feat: add avatar for visitors
- Loading branch information
Showing
8 changed files
with
108 additions
and
42 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 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,64 @@ | ||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; | ||
import { generateGravatarHash } from "@/lib/utils"; | ||
|
||
export const VisitorAvatar = ({ | ||
viewerEmail, | ||
}: { | ||
viewerEmail: string | null; | ||
}) => { | ||
// Convert email string to a simple hash | ||
const hashString = (str: string) => { | ||
let hash = 0; | ||
|
||
for (let i = 0; i < str.length; i++) { | ||
const char = str.charCodeAt(i); | ||
hash = (hash << 5) - hash + char; | ||
hash |= 0; // Convert to 32bit integer | ||
} | ||
return hash; | ||
}; | ||
|
||
// Get the background color from the email number hash | ||
const getColorFromHash = (hash: number): string => { | ||
// An array of colors you want to choose from | ||
const colors = [ | ||
"bg-gray-200/50", | ||
"bg-gray-300/50", | ||
"bg-gray-400/50", | ||
"bg-gray-500/50", | ||
"bg-gray-600/50", | ||
]; | ||
|
||
// Use the hash to get an index for the colors array | ||
const index = Math.abs(hash) % colors.length; | ||
return colors[index]; | ||
}; | ||
|
||
if (!viewerEmail) { | ||
return ( | ||
<Avatar className="flex-shrink-0 hidden sm:inline-flex"> | ||
<AvatarFallback className="bg-gray-200/50 dark:bg-gray-200/50"> | ||
AN | ||
</AvatarFallback> | ||
</Avatar> | ||
); | ||
} | ||
|
||
return ( | ||
<Avatar className="flex-shrink-0 hidden sm:inline-flex"> | ||
<AvatarImage | ||
src={`https://gravatar.com/avatar/${generateGravatarHash( | ||
viewerEmail, | ||
)}?s=80&d=404`} | ||
/> | ||
|
||
<AvatarFallback | ||
className={`${getColorFromHash( | ||
hashString(viewerEmail), | ||
)} dark:${getColorFromHash(hashString(viewerEmail))}`} | ||
> | ||
{viewerEmail?.slice(0, 2).toUpperCase()} | ||
</AvatarFallback> | ||
</Avatar> | ||
); | ||
}; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
9aec523
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
papermark – ./
opp-share.com
senas.xyz
docs.mfts.io
omni.day
doc.lebane.app
deck.awaire.io
docs.kouam.co
docs.awaire.io
memo.mfts.io
papermark.pro
docs.cilabs.ai
sign.ineris.pl
docs.codify.in
docs.jekyll.com
ppm.horcery.com
unbookables.com
docs.energize.de
doc.kalman.co.il
docs.londonos.uk
docs.florazu.com
docs.sibrahim.io
docs.backtrace.vc
www.papermark.io
docs.automized.com
docs.gamefolio.ioo
docs.myunihealth.co
share-prod.mfts.io
doc.dottedcircle.com
docs.trackchain.io
docs.verbaleaze.com
papermark.vercel.app
docs.indehealth.care
share-prod-2.mfts.io
docs.semanticlayer.io
docs.wedigistudio.com
contracts.founders.com
pitch.onarrival.travel
whitepaper.mede.network
pitchdeck.skyello.com
docs.anthillventures.com
docs.worldwide-casting.com
pitch.fortunasentinel.com
pitchdeck.dexioprotocol.com
docs.fundraising-bootcamp.com
papermark-git-main-mftsio.vercel.app
papermark-mftsio.vercel.app
papermark.io