feat(frontend): replace placeholder avatar with identicons
i don't actually know what the license on the kitten image is, and while it's very unlikely, i don't want to get into legal trouble. it was only ever supposed to be a temporary image, too. identicons aren't the prettiest but at least they have a clear license :3
This commit is contained in:
parent
71d3b42330
commit
74222ead45
10 changed files with 37 additions and 6 deletions
|
@ -1,16 +1,22 @@
|
|||
<script lang="ts">
|
||||
import { DEFAULT_AVATAR } from "$lib";
|
||||
import { minidenticon } from "minidenticons";
|
||||
|
||||
type Props = { url: string | null; alt: string; lazyLoad?: boolean; size?: number };
|
||||
let { url, alt, lazyLoad, size }: Props = $props();
|
||||
type Props = { url: string | null; alt: string; lazyLoad?: boolean; size?: number; name: string };
|
||||
let { url, alt, lazyLoad, size, name }: Props = $props();
|
||||
|
||||
let width = $derived(size || 200);
|
||||
|
||||
let identicon: string | null = $derived.by(() => {
|
||||
if (url) return null;
|
||||
return "data:image/svg+xml;utf8," + encodeURIComponent(minidenticon(name, 50, 80));
|
||||
});
|
||||
</script>
|
||||
|
||||
<img
|
||||
class="rounded-circle img-fluid"
|
||||
style="height: {width}px; width: {width}px"
|
||||
src={url || DEFAULT_AVATAR}
|
||||
class:identicon={!url}
|
||||
src={url || identicon}
|
||||
{alt}
|
||||
{width}
|
||||
loading={lazyLoad ? "lazy" : "eager"}
|
||||
|
@ -20,4 +26,12 @@
|
|||
img {
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.identicon {
|
||||
@media (prefers-color-scheme: dark) {
|
||||
background-color: var(--bs-secondary-border-subtle);
|
||||
}
|
||||
|
||||
background-color: var(--bs-light-border-subtle);
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -7,12 +7,13 @@
|
|||
import ShortNoscriptWarning from "./ShortNoscriptWarning.svelte";
|
||||
|
||||
type Props = {
|
||||
name: string;
|
||||
current: string | null;
|
||||
alt: string;
|
||||
update: (avatar: string) => Promise<void>;
|
||||
updated: boolean;
|
||||
};
|
||||
let { current, alt, update: onclick, updated }: Props = $props();
|
||||
let { name, current, alt, update: onclick, updated }: Props = $props();
|
||||
|
||||
const MAX_AVATAR_BYTES = 1_000_000;
|
||||
|
||||
|
@ -40,7 +41,7 @@
|
|||
</script>
|
||||
|
||||
<p class="text-center">
|
||||
<Avatar url={avatarExists ? avatar : current} {alt} />
|
||||
<Avatar {name} url={avatarExists ? avatar : current} {alt} />
|
||||
</p>
|
||||
|
||||
<InputGroup class="mb-2">
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
<div class="row">
|
||||
<div class="col-md-4 text-center">
|
||||
<Avatar
|
||||
name={"name" in profile ? profile.name : profile.username}
|
||||
url={profile.avatar_url}
|
||||
alt={$t("avatar-tooltip", { name })}
|
||||
lazyLoad={lazyLoadAvatar}
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
<div>
|
||||
<a href="/@{username}/{member.name}">
|
||||
<Avatar
|
||||
name={member.name}
|
||||
url={member.avatar_url}
|
||||
lazyLoad
|
||||
alt={$t("avatar-tooltip", { name: member.display_name })}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue