Improve CommitVerifiedBadge UX

- debounce hover events to prevent flickering when mousing over multiple badges
- keep the card visible while hovering over it
- show verified badge on the Commit page

Signed-off-by: Rūdolfs Ošiņš <rudolfs@osins.org>
This commit is contained in:
Rūdolfs Ošiņš
2022-09-01 16:40:44 +02:00
parent da408d2a0e
commit dadd82d8e8
5 changed files with 60 additions and 38 deletions
+2 -2
View File
@@ -2,10 +2,10 @@
import * as proj from "@app/project";
import { formatCommit } from "@app/utils";
import type { Commit } from "@app/commit";
import Badge from "@app/Badge.svelte";
import Changeset from "@app/base/projects/SourceBrowser/Changeset.svelte";
import CommitAuthorship from "@app/base/projects/Commit/CommitAuthorship.svelte";
import CommitVerifiedBadge from "@app/base/projects/Commit/CommitVerifiedBadge.svelte";
export let project: proj.Project;
export let commit: Commit;
@@ -70,7 +70,7 @@
<div class="authorship">
<CommitAuthorship {commit} />
{#if commit.context?.committer}
<Badge variant="tertiary">Verified</Badge>
<CommitVerifiedBadge {commit} />
{/if}
</div>
</header>
@@ -1,14 +1,25 @@
<script lang="ts">
import type { CommitMetadata } from "@app/commit";
import CommitAuthorship from "./CommitAuthorship.svelte";
import { debounce } from "lodash";
import Badge from "@app/Badge.svelte";
import CommitAuthorship from "./CommitAuthorship.svelte";
export let commit: CommitMetadata;
let hover = false;
let visible = false;
const showDelay = 50; // ms
const setVisible = debounce((value: boolean) => {
visible = value;
}, showDelay);
</script>
<style>
.container {
cursor: default;
}
.wrapper {
position: absolute;
}
@@ -18,7 +29,7 @@
box-shadow: 16px 16px 32px 32px var(--color-shadow);
color: var(--color-foreground);
font-size: 0.75rem;
left: -1rem;
left: -10rem;
margin-top: 0.5rem;
padding: 0.5rem 0;
position: absolute;
@@ -43,35 +54,32 @@
}
</style>
<Badge
variant="tertiary"
on:mouseenter={() => {
hover = true;
}}
on:mouseleave={() => {
hover = false;
}}>
Verified
</Badge>
<div
class="container"
on:click|stopPropagation
on:mouseenter={() => setVisible(true)}
on:mouseleave={() => setVisible(false)}>
<Badge variant="tertiary">Verified</Badge>
{#if hover}
<div class="wrapper">
<div class="popup">
<div class="header">
<div class="highlight">✔</div>
<div>
This commit was <span class="highlight">signed</span>
with the committer's radicle key.
{#if visible}
<div class="wrapper">
<div class="popup">
<div class="header">
<div class="highlight">✔</div>
<div>
This commit was <span class="highlight">signed</span>
with the committer's radicle key.
</div>
</div>
<div class="committer">
<CommitAuthorship {commit} showAuthor={false} showTime={false} />
{#if commit.context.committer}
<div class="peer">
<span class="text-faded">{commit.context.committer.peer.id}</span>
</div>
{/if}
</div>
</div>
<div class="committer">
<CommitAuthorship {commit} showAuthor={false} showTime={false} />
{#if commit.context.committer}
<div class="peer">
<span class="text-faded">{commit.context.committer.peer.id}</span>
</div>
{/if}
</div>
</div>
</div>
{/if}
{/if}
</div>