Add global inbox

This commit is contained in:
Sebastian Martinez
2025-01-23 22:28:00 +01:00
parent dc87d3fa84
commit d5632ed534
48 changed files with 2572 additions and 152 deletions
+1 -5
View File
@@ -1,11 +1,7 @@
<script lang="ts">
import { createIcon } from "@app/lib/blockies";
const {
publicKey,
}: {
publicKey: string;
} = $props();
const { publicKey }: { publicKey: string } = $props();
function createContainer(source: string) {
const seed = source.toLowerCase();
+1 -1
View File
@@ -4,7 +4,7 @@
import type { Modification } from "@bindings/diff/Modification";
import File from "@app/components/File.svelte";
import { escape } from "lodash";
import escape from "lodash/escape";
interface Props {
filePath: string;
+1 -3
View File
@@ -55,9 +55,7 @@
<NakedButton
variant="ghost"
onclick={() => {
void router.push({
resource: "home",
});
void router.push({ resource: "home" });
}}>
<Avatar {publicKey} />
</NakedButton>
+202
View File
@@ -0,0 +1,202 @@
<script lang="ts">
import type { HomeInboxTab, HomeReposTab } from "@app/lib/router/definitions";
import type { NotificationCount } from "@bindings/cob/inbox/NotificationCount";
import type { RepoCount } from "@bindings/repo/RepoCount";
import sum from "lodash/sum";
import * as router from "@app/lib/router";
import Border from "./Border.svelte";
import Icon from "@app/components/Icon.svelte";
import Link from "./Link.svelte";
import Settings from "@app/components/Settings.svelte";
interface Props {
activeTab:
| { type: "inbox"; repo?: HomeInboxTab }
| { type: "repos"; filter?: HomeReposTab };
notificationCount: Map<string, NotificationCount>;
repoCount: RepoCount;
}
const { notificationCount, repoCount, activeTab }: Props = $props();
</script>
<style>
.container {
display: flex;
flex-direction: column;
height: 100%;
justify-content: space-between;
}
.tab {
align-items: center;
gap: 0.5rem;
background-color: var(--color-background-float);
clip-path: var(--1px-corner-fill);
display: flex;
font-size: var(--font-size-small);
justify-content: space-between;
padding: 8px 4px 8px 8px;
width: 100%;
}
.tab:not(.active) {
color: var(--color-foreground-dim);
}
.tab:not(.active):hover {
background-color: var(--color-fill-float-hover);
}
.active {
background-color: var(--color-background-default);
font-weight: var(--font-weight-semibold);
}
.highlight {
color: var(--color-foreground-contrast);
}
</style>
<div class="container">
<div>
<div style:margin-bottom="0.5rem">
{#if activeTab.type === "inbox"}
<Border
styleCursor="pointer"
variant="ghost"
styleFlexDirection="column"
styleGap="2px"
styleBackgroundColor="var(--color-background-float)">
<!-- svelte-ignore a11y_click_events_have_key_events -->
<!-- svelte-ignore a11y_no_static_element_interactions -->
<div
class="tab"
class:active={!activeTab.repo}
onclick={() => router.push({ resource: "inbox" })}>
<div class="global-flex"><Icon name="inbox" />Inbox</div>
<div class="global-counter">
{sum(Array.from(notificationCount.values()).map(c => c.count))}
</div>
</div>
{#each notificationCount.entries() as [_, n]}
<!-- svelte-ignore a11y_click_events_have_key_events -->
<!-- svelte-ignore a11y_no_static_element_interactions -->
<div
class="tab"
onclick={() =>
router.push({
resource: "inbox",
activeTab: n,
})}
class:active={activeTab.repo?.rid === n.rid}>
<div class="global-flex">
<Icon name="repo" />{n.name}
</div>
<div
class="global-counter"
class:highlight={activeTab.repo?.rid === n.rid}>
{n.count}
</div>
</div>
{/each}
</Border>
{:else}
<!-- svelte-ignore a11y_no_static_element_interactions -->
<!-- svelte-ignore a11y_click_events_have_key_events -->
<div
class="tab"
style:cursor="pointer"
onclick={() => router.push({ resource: "inbox" })}
style:color="var(--color-foreground-contrast)"
style:padding-left="12px">
<div class="global-flex"><Icon name="inbox" />Inbox</div>
<div class="global-counter">
{sum(Array.from(notificationCount.values()).map(c => c.count))}
</div>
</div>
{/if}
</div>
{#if activeTab.type === "repos"}
<Border
styleCursor="pointer"
variant="ghost"
styleFlexDirection="column"
styleGap="2px"
styleBackgroundColor="var(--color-background-float)">
<!-- svelte-ignore a11y_click_events_have_key_events -->
<!-- svelte-ignore a11y_no_static_element_interactions -->
<div
class="tab txt-small"
class:active={!activeTab.filter}
onclick={() => router.push({ resource: "home" })}>
<div class="global-flex"><Icon name="repo" />Repositories</div>
<div class="global-counter">
{repoCount.total}
</div>
</div>
<!-- svelte-ignore a11y_click_events_have_key_events -->
<!-- svelte-ignore a11y_no_static_element_interactions -->
<div
class="tab"
class:active={activeTab.filter === "delegate"}
onclick={() =>
router.push({
resource: "home",
activeTab: "delegate",
})}>
<div class="global-flex">
<Icon name="delegate" />
<div>Delegate</div>
</div>
<div class="global-counter">{repoCount.delegate}</div>
</div>
<!-- svelte-ignore a11y_click_events_have_key_events -->
<!-- svelte-ignore a11y_no_static_element_interactions -->
<div
class="tab"
class:active={activeTab.filter === "private"}
onclick={() =>
router.push({
resource: "home",
activeTab: "private",
})}>
<div class="global-flex">
<Icon name="lock" />
<div>Private</div>
</div>
<div class="global-counter">{repoCount.private}</div>
</div>
</Border>
{:else}
<Border
styleBackgroundColor="var(--color-background-float)"
variant="float">
<Link
styleWidth="100%"
underline={false}
route={{
resource: "home",
}}>
<div
style:justify-content="space-between"
style:width="100%"
class="tab">
<div class="global-flex">
<Icon name="repo" />
Repositories
</div>
<div class="global-counter">
{repoCount.total}
</div>
</div>
</Link>
</Border>
{/if}
</div>
<Settings
compact={false}
popoverProps={{
popoverPositionBottom: "3rem",
popoverPositionLeft: "0",
}} />
</div>
+47 -3
View File
@@ -3,7 +3,7 @@
interface Props {
size?: "16" | "32";
onclick?: () => void;
onclick?: (e: MouseEvent) => void;
disabled?: boolean;
styleDisplay?: string;
styleVerticalAlign?: string;
@@ -12,6 +12,9 @@
| "arrow-right"
| "arrow-right-hollow"
| "attachment"
| "branch"
| "broom"
| "broom-double"
| "checkmark"
| "chevron-down"
| "chevron-right"
@@ -95,9 +98,9 @@
class:hoverable={onclick}
class:disabled
role="img"
onclick={() => {
onclick={e => {
if (onclick && !disabled) {
onclick();
onclick(e);
}
}}
aria-label={`icon-${name}`}
@@ -156,6 +159,47 @@
<path d="M4 8H5V9L4 9V8Z" />
<path d="M5 6H11V7H5V6Z" />
<path d="M4 7H5L5 8H4L4 7Z" />
{:else if name === "branch"}
<path d="M11 5L10 5V2L13 2V5L12 5V8L11 8V5ZM11 3H12V4H11V3Z" />
<path
d="M11 9L5 9L5 11H6L6 14H3L3 11H4L4 5H3L3 2L6 2L6 5H5L5 8H11V9ZM4 4L5 4V3H4L4 4ZM4 13V12H5L5 13H4Z" />
{:else if name === "broom"}
<path d="M11 13H12V14H11V13Z" />
<path d="M11 13H12V14H11V13Z" />
<path d="M11 12H12V13H11V12Z" />
<path d="M10 12H11V14H10V12Z" />
<path d="M8 12H9V14H8V12Z" />
<path d="M4 12H11V14H4V12Z" />
<path d="M9 12H10V13H9V12Z" />
<path d="M7 12H8V13H7V12Z" />
<path d="M4 10H12V11H4V10Z" />
<path d="M7 3H8V10H7V3Z" />
<path d="M8 3H9V10H8V3Z" />
<path d="M7 2H9V3H7V2Z" />
{:else if name === "broom-double"}
<path d="M9 13H10V14H9V13Z" />
<path d="M9 13H10V14H9V13Z" />
<path d="M9 12H10V13H9V12Z" />
<path d="M8 12H9V14H8V12Z" />
<path d="M6 12H7V14H6V12Z" />
<path d="M2 12H9V14H2V12Z" />
<path d="M7 12H8V13H7V12Z" />
<path d="M5 12H6V13H5V12Z" />
<path d="M2 10H10V11H2V10Z" />
<path d="M5 3H6V10H5V3Z" />
<path d="M6 3H7V10H6V3Z" />
<path d="M5 2H7V3H5V2Z" />
<path d="M13 13H14V14H13V13Z" />
<path d="M13 13H14V14H13V13Z" />
<path d="M13 12H14V13H13V12Z" />
<path d="M12 12H13V14H12V12Z" />
<path d="M11 12H13V14H11V12Z" />
<path d="M11 12H12V13H11V12Z" />
<path d="M9 12H10V13H9V12Z" />
<path d="M11 10H14V11H11V10Z" />
<path d="M9 3H10V9H9V3Z" />
<path d="M10 3H11V9H10V3Z" />
<path d="M9 2H11V3H9V2Z" />
{:else if name === "checkmark"}
<path d="M7 11V12H6V11H7Z" />
<path d="M8 10V11L7 11L7 10H8Z" />
+1 -1
View File
@@ -1,7 +1,7 @@
<script lang="ts">
import type { ComponentProps, Snippet } from "svelte";
import { debounce } from "lodash";
import debounce from "lodash/debounce";
import { writeToClipboard } from "@app/lib/invoke";
import { formatOid } from "@app/lib/utils";
+227
View File
@@ -0,0 +1,227 @@
<script lang="ts">
import type { ActionWithAuthor } from "@bindings/cob/inbox/ActionWithAuthor";
import type { Action as IssueAction } from "@bindings/cob/issue/Action";
import type { Action as PatchAction } from "@bindings/cob/patch/Action";
import type { ComponentProps } from "svelte";
import type { RepoRoute } from "@app/views/repo/router";
import type { NotificationItem } from "@bindings/cob/inbox/NotificationItem";
import {
authorForNodeId,
formatTimestamp,
issueStatusBackgroundColor,
issueStatusColor,
patchStatusBackgroundColor,
patchStatusColor,
} from "@app/lib/utils";
import { compressActions } from "@app/lib/notification";
import { push } from "@app/lib/router";
import uniqWith from "lodash/uniqWith";
import Icon from "./Icon.svelte";
import InlineTitle from "./InlineTitle.svelte";
import NodeId from "./NodeId.svelte";
interface Props {
rid: string;
kind: "issue" | "patch";
oid: string;
clearByIds: (rid: string, ids: string[]) => Promise<void>;
notificationItems: NotificationItem[];
selected?: boolean;
}
const {
clearByIds,
notificationItems,
rid,
oid,
kind,
selected = false,
}: Props = $props();
type Action = ActionWithAuthor<IssueAction> | ActionWithAuthor<PatchAction>;
const uniqueActions = $derived.by(() => {
return compressActions(
uniqWith(
notificationItems.flatMap<Action>(n => n.actions),
(a, b) =>
Boolean(
a.oid === b.oid &&
a.type === b.type &&
a.author.did &&
b.author.did,
),
).sort((a, b) => b.timestamp - a.timestamp),
kind,
oid,
);
});
const clearIcon = $derived(
uniqueActions.length > 1 ? "broom-double" : "broom",
);
const title = $derived.by(() => {
const lastDetail = notificationItems.at(-1);
if (lastDetail && "title" in lastDetail) {
return lastDetail.title;
}
});
const icon: ComponentProps<typeof Icon>["name"] = $derived.by(() => {
const lastDetail = notificationItems.at(-1);
if (lastDetail?.type === "issue" && lastDetail.status.status !== "open") {
return `issue-${lastDetail.status.status}` as const;
} else if (lastDetail?.type === "issue") {
return "issue" as const;
} else if (
lastDetail?.type === "patch" &&
lastDetail.status.status !== "open"
) {
return `patch-${lastDetail.status.status}` as const;
} else {
return "patch" as const;
}
});
const statusColor = $derived.by(() => {
const lastDetail = notificationItems.at(-1);
if (lastDetail?.type === "patch") {
return {
color: patchStatusColor[lastDetail.status.status],
background: patchStatusBackgroundColor[lastDetail.status.status],
};
} else if (lastDetail?.type === "issue") {
return {
color: issueStatusColor[lastDetail.status.status],
background: issueStatusBackgroundColor[lastDetail.status.status],
};
} else {
return {
color: "var(--color-foreground-dim)",
background: "var(--color-fill-ghost)",
};
}
});
const route = $derived.by(() => {
const lastDetail = notificationItems.at(-1);
switch (lastDetail?.type) {
case "patch":
return {
resource: "repo.patch",
rid,
patch: lastDetail.id,
status: undefined,
} as RepoRoute;
case "issue":
return {
resource: "repo.issue",
rid,
issue: lastDetail.id,
status: "all",
} as RepoRoute;
}
return undefined;
});
</script>
<style>
.notification-teaser {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.25rem;
min-height: 5rem;
background-color: var(--color-background-float);
padding: 1rem;
cursor: pointer;
font-size: var(--font-size-regular);
word-break: break-word;
}
.selected {
background-color: var(--color-fill-float-hover);
}
.notification-teaser:hover {
background-color: var(--color-fill-float-hover);
}
.status {
padding: 0;
margin-right: 1rem;
}
.icon {
width: 2rem;
height: 2rem;
display: flex;
justify-content: center;
align-items: center;
}
.notification-teaser:first-of-type {
clip-path: var(--3px-top-corner-fill);
}
.notification-teaser:last-of-type {
clip-path: var(--3px-bottom-corner-fill);
}
.notification-teaser:only-of-type {
clip-path: var(--3px-corner-fill);
}
</style>
<!-- svelte-ignore a11y_click_events_have_key_events -->
<div
tabindex="0"
role="button"
class:selected
class="notification-teaser"
onclick={() => {
if (route) void push(route);
}}>
<div
class="global-flex"
style:justify-content="space-between"
style:align-items="flex-start"
style:width="100%">
<div class="global-flex">
<div
class="global-counter status"
style:align-self="flex-start"
style:color={statusColor.color}
style:background-color={statusColor.background}>
<Icon name={icon} />
</div>
<div
class="global-flex"
style:flex-direction="column"
style:align-items="flex-start">
{#if title}
<InlineTitle content={title} />
{/if}
<div class="txt-small">
{#each uniqueActions as action}
<div class="global-flex" style:gap="0.25rem" style:height="2rem">
<NodeId {...authorForNodeId(action.items[0].author)} />
<span>{@html action.summary}</span>
<span>{formatTimestamp(action.items[0].timestamp)}</span>
</div>
{/each}
</div>
</div>
</div>
<div class="global-flex">
<div class="icon">
<Icon
onclick={e => {
e.stopPropagation();
void clearByIds(
rid,
notificationItems.map(n => n.rowId),
);
}}
name={clearIcon} />
</div>
</div>
</div>
</div>
+74
View File
@@ -0,0 +1,74 @@
<script lang="ts">
import type { HomeInboxTab } from "@app/lib/router/definitions";
import type { NotificationItem } from "@bindings/cob/inbox/NotificationItem";
import * as router from "@app/lib/router";
import Button from "./Button.svelte";
import NotificationTeaser from "./NotificationTeaser.svelte";
import Icon from "./Icon.svelte";
interface Props {
all?: boolean;
clearByIds: (rid: string, ids: string[]) => Promise<void>;
clearByRepo: (rid: string) => Promise<void>;
repo: HomeInboxTab;
items: Record<string, NotificationItem[]>;
more: boolean;
}
const {
all = false,
more,
clearByRepo,
clearByIds,
repo,
items,
}: Props = $props();
</script>
<style>
.header {
display: flex;
justify-content: space-between;
align-items: center;
padding-right: 1.5rem;
}
</style>
{#if Object.entries(items).length > 0}
<div class="header">
<div class="global-flex" style:margin="1rem 0">
<span class="txt-bold">
{repo.name}
</span>
{repo.count}
</div>
<Icon onclick={() => clearByRepo(repo.rid)} name="broom-double" />
</div>
{/if}
<div>
{#each Object.entries(items).sort((a, b) => b[1][0].timestamp - a[1][0].timestamp) as [_, notificationItems]}
<NotificationTeaser
{clearByIds}
rid={repo.rid}
kind={notificationItems[0].type}
oid={notificationItems[0].id}
{notificationItems} />
{/each}
</div>
{#if all === false && more}
<div style:width="100%" style:margin-top="1rem">
<div style:width="7rem" style:margin="auto">
<Button
variant="ghost"
onclick={() =>
router.push({
resource: "inbox",
activeTab: repo,
})}>
<div style:width="100%" style:text-align="center">See all</div>
</Button>
</div>
</div>
{/if}