mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-11-26 23:59:19 +03:00
fix: commit avatar loading improvement (#4335)
This commit is contained in:
parent
d0a257e745
commit
db28854983
@ -95,7 +95,7 @@ export function ghResponseToInstance(
|
||||
name: pr.user.login || undefined,
|
||||
email: pr.user.email || undefined,
|
||||
isBot: pr.user.type.toLowerCase() === 'bot',
|
||||
gravatarUrl: new URL(pr.user.avatar_url)
|
||||
gravatarUrl: pr.user.avatar_url
|
||||
}
|
||||
: null,
|
||||
labels: labels,
|
||||
|
@ -1,3 +1,3 @@
|
||||
export function gravatarUrl(id: string | undefined | null): URL | undefined {
|
||||
if (id) return new URL(`https://www.gravatar.com/avatar/${id}?s=100&r=g&d=retro`);
|
||||
export function gravatarUrl(id: string | undefined | null): string | undefined {
|
||||
if (id) return `https://www.gravatar.com/avatar/${id}?s=100&r=g&d=retro`;
|
||||
}
|
||||
|
@ -317,7 +317,7 @@ export class RemoteFile {
|
||||
export interface Author {
|
||||
email?: string;
|
||||
name?: string;
|
||||
gravatarUrl?: URL;
|
||||
gravatarUrl?: string;
|
||||
isBot?: boolean;
|
||||
}
|
||||
|
||||
|
59
packages/ui/src/lib/CommitLines/AvatarImage.svelte
Normal file
59
packages/ui/src/lib/CommitLines/AvatarImage.svelte
Normal file
@ -0,0 +1,59 @@
|
||||
<script lang="ts">
|
||||
import { tooltip } from '$lib/utils/tooltip';
|
||||
|
||||
interface Props {
|
||||
srcUrl: string;
|
||||
tooltipText: string;
|
||||
altText: string;
|
||||
}
|
||||
|
||||
let isLoaded = $state(false);
|
||||
|
||||
const { srcUrl, tooltipText, altText }: Props = $props();
|
||||
</script>
|
||||
|
||||
<div class="image-wrapper">
|
||||
<img
|
||||
class="avatar"
|
||||
alt={altText}
|
||||
src={srcUrl}
|
||||
loading="lazy"
|
||||
onload={() => (isLoaded = true)}
|
||||
width="100"
|
||||
height="100"
|
||||
class:hidden={!isLoaded}
|
||||
use:tooltip={tooltipText}
|
||||
/>
|
||||
<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t3/fODa/3vd1v952dH/d9bN/3TSyv9xzsf/bcrF/2nHxf9lxMX/YMHH/12/yv9avs3/WLzQ/1m80/9bu9b/YLvX/2a61/9uutb/drnU/3+40f+IuMz/kLfG/5i1v/+ftLj/pbOx/6qyq/+usqb/sLGi/+et3p4B1/E6AAAAAElFTkSuQmCC"
|
||||
width="100"
|
||||
height="100"
|
||||
use:tooltip={tooltipText}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<style lang="postcss">
|
||||
.image-wrapper {
|
||||
display: grid;
|
||||
place-content: center;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.image-wrapper > * {
|
||||
grid-area: 1 / 1;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
position: relative;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
</style>
|
@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import AvatarImage from './AvatarImage.svelte';
|
||||
import { tooltip } from '$lib/utils/tooltip';
|
||||
import { isDefined } from '$lib/utils/typeguards';
|
||||
import type { CommitNodeData, Color } from '$lib/CommitLines/types';
|
||||
@ -32,13 +33,10 @@
|
||||
>
|
||||
{#if commitNode.type === 'large' && commitNode.commit}
|
||||
<div class="large-node">
|
||||
<img
|
||||
class="avatar"
|
||||
alt="Gravatar for {commitNode.commit.author.email}"
|
||||
srcset="{commitNode.commit.author.gravatarUrl} 2x"
|
||||
width="100"
|
||||
height="100"
|
||||
use:tooltip={hoverText}
|
||||
<AvatarImage
|
||||
srcUrl={commitNode.commit?.author.gravatarUrl ?? ''}
|
||||
tooltipText={hoverText}
|
||||
altText={`Gravatar for ${commitNode.commit.author.email}`}
|
||||
/>
|
||||
</div>
|
||||
{:else}
|
||||
@ -102,12 +100,4 @@
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
|
||||
.avatar {
|
||||
position: relative;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
|
||||
border-radius: 6px;
|
||||
}
|
||||
</style>
|
||||
|
@ -29,7 +29,7 @@ export interface LineGroupData {
|
||||
export interface Author {
|
||||
name?: string;
|
||||
email?: string;
|
||||
gravatarUrl?: URL;
|
||||
gravatarUrl?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -11,7 +11,7 @@ type Story = StoryObj<typeof meta>;
|
||||
|
||||
const caleb: Author = {
|
||||
email: 'hello@calebowens.com',
|
||||
gravatarUrl: new URL('https://gravatar.com/avatar/f43ef760d895a84ca7bb35ff6f4c6b7c')
|
||||
gravatarUrl: 'https://gravatar.com/avatar/f43ef760d895a84ca7bb35ff6f4c6b7c'
|
||||
};
|
||||
|
||||
function author() {
|
||||
|
Loading…
Reference in New Issue
Block a user