mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 22:30:41 +08:00
Add global inbox
This commit is contained in:
+5
-2
@@ -13,11 +13,12 @@
|
||||
|
||||
import AuthenticationError from "@app/views/AuthenticationError.svelte";
|
||||
import CreateIssue from "@app/views/repo/CreateIssue.svelte";
|
||||
import Home from "@app/views/Home.svelte";
|
||||
import Inbox from "./views/home/Inbox.svelte";
|
||||
import Issue from "@app/views/repo/Issue.svelte";
|
||||
import Issues from "@app/views/repo/Issues.svelte";
|
||||
import Patch from "@app/views/repo/Patch.svelte";
|
||||
import Patches from "@app/views/repo/Patches.svelte";
|
||||
import Repos from "./views/home/Repos.svelte";
|
||||
import { dynamicInterval, checkAuth } from "./lib/auth";
|
||||
|
||||
const activeRouteStore = router.activeRouteStore;
|
||||
@@ -71,7 +72,9 @@
|
||||
{#if $activeRouteStore.resource === "booting"}
|
||||
<!-- Don't show anything -->
|
||||
{:else if $activeRouteStore.resource === "home"}
|
||||
<Home {...$activeRouteStore.params} />
|
||||
<Repos {...$activeRouteStore.params} />
|
||||
{:else if $activeRouteStore.resource === "inbox"}
|
||||
<Inbox {...$activeRouteStore.params} />
|
||||
{:else if $activeRouteStore.resource === "repo.createIssue"}
|
||||
<CreateIssue {...$activeRouteStore.params} />
|
||||
{:else if $activeRouteStore.resource === "repo.issue"}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -55,9 +55,7 @@
|
||||
<NakedButton
|
||||
variant="ghost"
|
||||
onclick={() => {
|
||||
void router.push({
|
||||
resource: "home",
|
||||
});
|
||||
void router.push({ resource: "home" });
|
||||
}}>
|
||||
<Avatar {publicKey} />
|
||||
</NakedButton>
|
||||
|
||||
@@ -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>
|
||||
@@ -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,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";
|
||||
|
||||
@@ -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>
|
||||
@@ -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}
|
||||
@@ -0,0 +1,188 @@
|
||||
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 { pluralize, formatOid } from "@app/lib/utils";
|
||||
|
||||
export type Action =
|
||||
| ActionWithAuthor<IssueAction>
|
||||
| ActionWithAuthor<PatchAction>;
|
||||
|
||||
// N.b. I have taken the `%` char as indicator for a `global-oid` class
|
||||
export function createSummary(
|
||||
a: Action[],
|
||||
kind: "issue" | "patch",
|
||||
oid: string,
|
||||
count: number,
|
||||
) {
|
||||
const lastAction = a[a.length - 1];
|
||||
let summary = `${lastAction.type} not implemented!`;
|
||||
|
||||
function times(count: number) {
|
||||
return count > 1 ? `${count} times` : "";
|
||||
}
|
||||
|
||||
if (lastAction.oid === oid) {
|
||||
summary = `opened ${kind} %${formatOid(lastAction.oid)}%`;
|
||||
} else if (lastAction.type === "comment") {
|
||||
summary = `left ${count > 1 ? count : "a"} ${pluralize("comment", count)}`;
|
||||
} else if (lastAction.type === "revision") {
|
||||
const revisions = a.map(i => `%${formatOid(i.oid)}%`).slice(0, 10);
|
||||
summary = `created ${pluralize("revision", count)} ${[
|
||||
...revisions,
|
||||
...(a.length >= 11 ? ["%…%"] : []),
|
||||
].join(", ")}`;
|
||||
} else if (lastAction.type === "merge") {
|
||||
summary = `merged ${pluralize("revision", count)} %${formatOid(lastAction.revision)}%`;
|
||||
} else if (lastAction.type === "edit" && kind === "issue") {
|
||||
summary = `edited issue${count ? times(count) : ""}`;
|
||||
} else if (lastAction.type === "edit" && kind === "patch") {
|
||||
summary = `edited ${pluralize("revision", count)} %${formatOid(lastAction.oid)}%`;
|
||||
} else if (lastAction.type === "revision.edit") {
|
||||
summary = `edited ${pluralize("revision", count)} %${formatOid(lastAction.revision)}%`;
|
||||
} else if (lastAction.type === "lifecycle" && count > 1) {
|
||||
summary = `changed to ${lastAction.state.status} and ${count} more changes`;
|
||||
} else if (
|
||||
lastAction.type === "lifecycle" &&
|
||||
lastAction.state.status === "draft"
|
||||
) {
|
||||
summary = `changed to ${lastAction.state.status}`;
|
||||
} else if (
|
||||
lastAction.type === "lifecycle" &&
|
||||
lastAction.state.status === "open"
|
||||
) {
|
||||
summary = `reopened ${kind}`;
|
||||
} else if (
|
||||
lastAction.type === "lifecycle" &&
|
||||
lastAction.state.status === "archived"
|
||||
) {
|
||||
summary = `archived ${kind}`;
|
||||
} else if (
|
||||
lastAction.type === "lifecycle" &&
|
||||
lastAction.state.status === "closed" &&
|
||||
lastAction.state.reason === "solved"
|
||||
) {
|
||||
summary = `closed ${kind} as solved`;
|
||||
} else if (
|
||||
lastAction.type === "lifecycle" &&
|
||||
lastAction.state.status === "closed"
|
||||
) {
|
||||
summary = `closed ${kind}`;
|
||||
} else if (lastAction.type === "revision.comment") {
|
||||
summary = `left ${count > 1 ? count : "a"} review ${pluralize("comment", count)}`;
|
||||
} else if (lastAction.type === "review.comment") {
|
||||
summary = `left ${count > 1 ? count : "a"} review ${pluralize("comment", count)}`;
|
||||
} else if (a.every(e => e.type === "comment.react")) {
|
||||
const reactions = a.map(i => i.reaction).slice(0, 10);
|
||||
summary = `reacted with ${[
|
||||
...reactions,
|
||||
...(a.length >= 11 ? ["%…%"] : []),
|
||||
].join(", ")} to ${count > 1 ? count : "a"} ${pluralize("comment", count)}`;
|
||||
} else if (lastAction.type === "comment.edit") {
|
||||
summary = `edited ${count > 1 ? count : "a"} ${pluralize("comment", count)}`;
|
||||
} else if (lastAction.type === "review" && lastAction.verdict) {
|
||||
summary = `${lastAction.verdict}ed revision %${formatOid(lastAction.revision)}% with a review`;
|
||||
} else if (lastAction.type === "review") {
|
||||
summary = `left a review with a comment on revision %${formatOid(lastAction.revision)}%`;
|
||||
} else if (lastAction.type === "assign") {
|
||||
summary = "changed assignes";
|
||||
} else if (lastAction.type === "revision.comment.edit") {
|
||||
summary = `edited ${count > 1 ? count : "a"} ${pluralize("comment", count)}`;
|
||||
} else if (lastAction.type === "comment.redact") {
|
||||
summary = `redacted ${count > 1 ? count : "a"} ${pluralize("comment", count)}`;
|
||||
} else if (lastAction.type === "label") {
|
||||
summary = `added ${pluralize("label", count)}`;
|
||||
} else if (lastAction.type === "review.comment.edit") {
|
||||
summary = `edited ${count > 1 ? count : "a"} review ${pluralize("comment", count)}`;
|
||||
} else if (lastAction.type === "review.comment.react") {
|
||||
summary = `reacted to ${count > 1 ? count : "a"} review ${pluralize("comment", count)}`;
|
||||
} else if (lastAction.type === "review.comment.redact") {
|
||||
summary = `redacted ${count > 1 ? count : "a"} review ${pluralize("comment", count)}`;
|
||||
} else if (lastAction.type === "review.comment.resolve") {
|
||||
summary = `resolved ${count > 1 ? count : "a"} review ${pluralize("comment", count)}`;
|
||||
} else if (lastAction.type === "review.comment.unresolve") {
|
||||
summary = `unresolved ${count > 1 ? count : "a"} review ${pluralize("comment", count)}`;
|
||||
} else if (lastAction.type === "review.edit") {
|
||||
summary = `edited ${count > 1 ? count : "a"} ${pluralize("review", count)}`;
|
||||
} else if (lastAction.type === "review.redact") {
|
||||
summary = `redacted ${count > 1 ? count : "a"} ${pluralize("review", count)}`;
|
||||
} else if (lastAction.type === "revision.comment.react") {
|
||||
summary = `reacted to ${count > 1 ? count : "a"} revision ${pluralize("comment", count)}`;
|
||||
} else if (lastAction.type === "revision.comment.redact") {
|
||||
summary = `redacted ${count > 1 ? count : "a"} revision ${pluralize("comment", count)}`;
|
||||
} else if (lastAction.type === "revision.react") {
|
||||
summary = `reacted to ${count > 1 ? count : "a"} ${pluralize("revision", count)}`;
|
||||
} else if (lastAction.type === "revision.redact") {
|
||||
summary = `redacted ${count > 1 ? count : "a"} ${pluralize("revision", count)}`;
|
||||
}
|
||||
|
||||
return summary.replaceAll(
|
||||
/[%](\S+)[%]/g,
|
||||
'<span class="global-oid">$1</span>',
|
||||
);
|
||||
}
|
||||
|
||||
export function compressActions(
|
||||
actions: Action[],
|
||||
kind: "issue" | "patch",
|
||||
oid: string,
|
||||
) {
|
||||
const result: {
|
||||
summary: string;
|
||||
oid: string;
|
||||
items: Action[];
|
||||
}[] = [];
|
||||
|
||||
let currentGroup: Action[] = [];
|
||||
|
||||
for (const action of actions) {
|
||||
if (currentGroup.length === 0) {
|
||||
currentGroup.push(action);
|
||||
continue;
|
||||
}
|
||||
|
||||
const last = currentGroup[currentGroup.length - 1];
|
||||
const sameAuthorDid = last.author.did === action.author.did;
|
||||
const sameType =
|
||||
last.type === action.type ||
|
||||
(last.type === "revision.edit" && action.type === "edit") ||
|
||||
(action.type === "revision.edit" && last.type === "edit") ||
|
||||
action.oid === oid;
|
||||
|
||||
if (sameAuthorDid && sameType) {
|
||||
currentGroup.push(action);
|
||||
} else {
|
||||
const summaryStr = createSummary(
|
||||
currentGroup,
|
||||
kind,
|
||||
oid,
|
||||
currentGroup.length,
|
||||
);
|
||||
|
||||
result.push({
|
||||
summary: summaryStr,
|
||||
oid,
|
||||
items: currentGroup,
|
||||
});
|
||||
|
||||
currentGroup = [action];
|
||||
}
|
||||
}
|
||||
|
||||
// Summarize any open actions.
|
||||
if (currentGroup.length > 0) {
|
||||
const summaryStr = createSummary(
|
||||
currentGroup,
|
||||
kind,
|
||||
oid,
|
||||
currentGroup.length,
|
||||
);
|
||||
result.push({
|
||||
summary: summaryStr,
|
||||
oid,
|
||||
items: currentGroup,
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
+8
-1
@@ -103,7 +103,12 @@ function urlToRoute(url: URL): Route | null {
|
||||
|
||||
switch (resource) {
|
||||
case "": {
|
||||
return { resource: "home" };
|
||||
return {
|
||||
resource: "home",
|
||||
};
|
||||
}
|
||||
case "inbox": {
|
||||
return { resource: "inbox" };
|
||||
}
|
||||
case "repos": {
|
||||
return repoUrlToRoute(segments, url.searchParams);
|
||||
@@ -120,6 +125,8 @@ function urlToRoute(url: URL): Route | null {
|
||||
export function routeToPath(route: Route): string {
|
||||
if (route.resource === "home") {
|
||||
return "/";
|
||||
} else if (route.resource === "inbox") {
|
||||
return "/inbox";
|
||||
} else if (route.resource === "authenticationError") {
|
||||
return "/authenticationError";
|
||||
} else if (
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import type { Config } from "@bindings/config/Config";
|
||||
import type { NotificationItem } from "@bindings/cob/inbox/NotificationItem";
|
||||
import type { PaginatedQuery } from "@bindings/cob/PaginatedQuery";
|
||||
import type { NotificationCount } from "@bindings/cob/inbox/NotificationCount";
|
||||
import type { RepoInfo } from "@bindings/repo/RepoInfo";
|
||||
import type { RepoCount } from "@bindings/repo/RepoCount";
|
||||
import type { LoadedRepoRoute, RepoRoute } from "@app/views/repo/router";
|
||||
|
||||
import { invoke } from "@app/lib/invoke";
|
||||
import { SvelteMap } from "svelte/reactivity";
|
||||
|
||||
import {
|
||||
loadCreateIssue,
|
||||
@@ -12,6 +17,14 @@ import {
|
||||
loadPatches,
|
||||
} from "@app/views/repo/router";
|
||||
|
||||
export type HomeReposTab = "delegate" | "private";
|
||||
|
||||
export interface HomeInboxTab {
|
||||
rid: string;
|
||||
name: string;
|
||||
count: number;
|
||||
}
|
||||
|
||||
interface BootingRoute {
|
||||
resource: "booting";
|
||||
}
|
||||
@@ -26,21 +39,53 @@ interface AuthenticationErrorRoute {
|
||||
|
||||
interface HomeRoute {
|
||||
resource: "home";
|
||||
activeTab?: HomeReposTab;
|
||||
}
|
||||
|
||||
interface InboxRoute {
|
||||
resource: "inbox";
|
||||
activeTab?: HomeInboxTab;
|
||||
}
|
||||
|
||||
interface LoadedInboxRoute {
|
||||
resource: "inbox";
|
||||
params: {
|
||||
activeTab?: HomeInboxTab;
|
||||
repoCount: RepoCount;
|
||||
notificationCount: SvelteMap<string, NotificationCount>;
|
||||
notifications: SvelteMap<
|
||||
string,
|
||||
{
|
||||
repo: HomeInboxTab;
|
||||
items: Record<string, NotificationItem[]>;
|
||||
pagination: { cursor: number; more: boolean };
|
||||
}
|
||||
>;
|
||||
config: Config;
|
||||
};
|
||||
}
|
||||
|
||||
interface LoadedHomeRoute {
|
||||
resource: "home";
|
||||
params: { repos: RepoInfo[]; config: Config };
|
||||
params: {
|
||||
activeTab?: HomeReposTab;
|
||||
repoCount: RepoCount;
|
||||
notificationCount: Map<string, NotificationCount>;
|
||||
repos: RepoInfo[];
|
||||
config: Config;
|
||||
};
|
||||
}
|
||||
|
||||
export type Route =
|
||||
| AuthenticationErrorRoute
|
||||
| InboxRoute
|
||||
| BootingRoute
|
||||
| HomeRoute
|
||||
| RepoRoute;
|
||||
|
||||
export type LoadedRoute =
|
||||
| AuthenticationErrorRoute
|
||||
| LoadedInboxRoute
|
||||
| BootingRoute
|
||||
| LoadedHomeRoute
|
||||
| LoadedRepoRoute;
|
||||
@@ -49,12 +94,77 @@ export async function loadRoute(
|
||||
route: Route,
|
||||
_previousLoaded: LoadedRoute,
|
||||
): Promise<LoadedRoute> {
|
||||
const [count, repoCount, config] = await Promise.all([
|
||||
invoke<Record<string, NotificationCount>>("count_notifications_by_repo"),
|
||||
invoke<RepoCount>("repo_count"),
|
||||
invoke<Config>("config"),
|
||||
]);
|
||||
const notificationCount = new SvelteMap(Object.entries(count));
|
||||
if (route.resource === "home") {
|
||||
const [config, repos] = await Promise.all([
|
||||
invoke<Config>("config"),
|
||||
invoke<RepoInfo[]>("list_repos", { show: "all" }),
|
||||
]);
|
||||
return { resource: "home", params: { repos, config } };
|
||||
let show = "all";
|
||||
|
||||
if (route.resource === "home") {
|
||||
if (route.activeTab === "delegate") {
|
||||
show = "delegate";
|
||||
} else if (route.activeTab === "private") {
|
||||
show = "private";
|
||||
}
|
||||
}
|
||||
|
||||
const repos = await invoke<RepoInfo[]>("list_repos", { show });
|
||||
return {
|
||||
resource: "home",
|
||||
params: {
|
||||
activeTab: route.activeTab,
|
||||
repoCount,
|
||||
notificationCount,
|
||||
repos,
|
||||
config,
|
||||
},
|
||||
};
|
||||
} else if (route.resource === "inbox") {
|
||||
const notifications: LoadedInboxRoute["params"]["notifications"] =
|
||||
new SvelteMap();
|
||||
if (route.activeTab) {
|
||||
const items = await invoke<
|
||||
PaginatedQuery<Record<string, NotificationItem[]>>
|
||||
>("list_notifications", {
|
||||
params: {
|
||||
repo: route.activeTab.rid,
|
||||
},
|
||||
});
|
||||
notifications.set(route.activeTab.rid, {
|
||||
repo: route.activeTab,
|
||||
items: items.content,
|
||||
pagination: { cursor: items.cursor, more: items.more },
|
||||
});
|
||||
} else {
|
||||
for (const [rid, item] of notificationCount) {
|
||||
const result = await invoke<
|
||||
PaginatedQuery<Record<string, NotificationItem[]>>
|
||||
>("list_notifications", {
|
||||
params: {
|
||||
repo: rid,
|
||||
},
|
||||
});
|
||||
notifications.set(item.rid, {
|
||||
repo: { name: item.name, rid: item.rid, count: item.count },
|
||||
items: result.content,
|
||||
pagination: { cursor: result.cursor, more: result.more },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
resource: "inbox",
|
||||
params: {
|
||||
activeTab: route.activeTab,
|
||||
repoCount,
|
||||
notifications,
|
||||
notificationCount,
|
||||
config,
|
||||
},
|
||||
};
|
||||
} else if (route.resource === "repo.issue") {
|
||||
return loadIssue(route);
|
||||
} else if (route.resource === "repo.createIssue") {
|
||||
|
||||
@@ -47,6 +47,10 @@ export function truncateDid(did: string): string {
|
||||
return `did:key:${truncateId(publicKeyFromDid(did))}`;
|
||||
}
|
||||
|
||||
export function didFromPublicKey(publicKey: string) {
|
||||
return `did:key:${publicKey}`;
|
||||
}
|
||||
|
||||
export function publicKeyFromDid(did: string) {
|
||||
return did.replace("did:key:", "");
|
||||
}
|
||||
@@ -165,6 +169,10 @@ export function formatEditedCaption(author: Author, timestamp: number) {
|
||||
return `${author.alias ? author.alias : truncateDid(author.did)} edited ${absoluteTimestamp(timestamp)}`;
|
||||
}
|
||||
|
||||
export function pluralize(singular: string, count: number): string {
|
||||
return count === 1 ? singular : `${singular}s`;
|
||||
}
|
||||
|
||||
export function isMac() {
|
||||
if (
|
||||
(navigator.platform && navigator.platform.includes("Mac")) ||
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
<script lang="ts">
|
||||
import type { Config } from "@bindings/config/Config";
|
||||
import type { RepoInfo } from "@bindings/repo/RepoInfo";
|
||||
|
||||
import * as router from "@app/lib/router";
|
||||
|
||||
import CopyableId from "@app/components/CopyableId.svelte";
|
||||
import Header from "@app/components/Header.svelte";
|
||||
import RepoCard from "@app/components/RepoCard.svelte";
|
||||
import Settings from "@app/components/Settings.svelte";
|
||||
|
||||
interface Props {
|
||||
repos: RepoInfo[];
|
||||
config: Config;
|
||||
}
|
||||
|
||||
const { repos, config }: Props = $props();
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.header {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 1;
|
||||
}
|
||||
.repo-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(21rem, 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div style:height="fit-content">
|
||||
<div class="header">
|
||||
<Header publicKey={config.publicKey}>
|
||||
{#snippet center()}
|
||||
<CopyableId id={`did:key:${config.publicKey}`} />
|
||||
{/snippet}
|
||||
{#snippet settingsButton()}
|
||||
<Settings
|
||||
styleHeight="32px"
|
||||
popoverProps={{
|
||||
popoverPositionRight: "0",
|
||||
popoverPositionTop: "2.5rem",
|
||||
}} />
|
||||
{/snippet}
|
||||
</Header>
|
||||
</div>
|
||||
<div style:padding="1rem">
|
||||
<div class="txt-semibold" style:margin="0.5rem 0 1.5rem 1rem">
|
||||
Repositories
|
||||
</div>
|
||||
<div class="repo-grid">
|
||||
{#each repos as repo}
|
||||
{#if repo.payloads["xyz.radicle.project"]}
|
||||
<RepoCard
|
||||
{repo}
|
||||
selfDid={`did:key:${config.publicKey}`}
|
||||
onclick={() => {
|
||||
void router.push({
|
||||
resource: "repo.issues",
|
||||
rid: repo.rid,
|
||||
status: "open",
|
||||
});
|
||||
}} />
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,215 @@
|
||||
<script lang="ts">
|
||||
import type { HomeInboxTab } from "@app/lib/router/definitions";
|
||||
import type { Config } from "@bindings/config/Config";
|
||||
import type { NotificationCount } from "@bindings/cob/inbox/NotificationCount";
|
||||
import type { NotificationItem } from "@bindings/cob/inbox/NotificationItem";
|
||||
import type { PaginatedQuery } from "@bindings/cob/PaginatedQuery";
|
||||
import type { RepoCount } from "@bindings/repo/RepoCount";
|
||||
|
||||
import { SvelteMap } from "svelte/reactivity";
|
||||
import { invoke } from "@app/lib/invoke";
|
||||
import * as router from "@app/lib/router";
|
||||
|
||||
import CopyableId from "@app/components/CopyableId.svelte";
|
||||
import HomeSidebar from "@app/components/HomeSidebar.svelte";
|
||||
import Icon from "@app/components/Icon.svelte";
|
||||
import Layout from "@app/views/repo/Layout.svelte";
|
||||
import RepoNotifications from "@app/components/RepoNotifications.svelte";
|
||||
import Border from "@app/components/Border.svelte";
|
||||
|
||||
interface Props {
|
||||
activeTab?: HomeInboxTab;
|
||||
notificationCount: SvelteMap<string, NotificationCount>;
|
||||
notifications: SvelteMap<
|
||||
string,
|
||||
{
|
||||
repo: HomeInboxTab;
|
||||
items: Record<string, NotificationItem[]>;
|
||||
pagination: { cursor: number; more: boolean };
|
||||
}
|
||||
>;
|
||||
repoCount: RepoCount;
|
||||
config: Config;
|
||||
}
|
||||
|
||||
/* eslint-disable prefer-const */
|
||||
let {
|
||||
notificationCount,
|
||||
repoCount,
|
||||
activeTab,
|
||||
config,
|
||||
notifications,
|
||||
}: Props = $props();
|
||||
/* eslint-enable prefer-const */
|
||||
|
||||
let cursor: number | undefined = undefined;
|
||||
let more: boolean | undefined = undefined;
|
||||
|
||||
// If we are focused on a repo populate the pagination vars.
|
||||
$effect(() => {
|
||||
if (activeTab && notifications.has(activeTab.rid)) {
|
||||
const n = notifications.get(activeTab.rid);
|
||||
cursor = n!.pagination.cursor;
|
||||
more = n!.pagination.more;
|
||||
}
|
||||
});
|
||||
|
||||
async function clearAll() {
|
||||
try {
|
||||
await invoke("clear_notifications", {
|
||||
params: { type: "all" },
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Clearing notifications failed", error);
|
||||
} finally {
|
||||
notificationCount.clear();
|
||||
notifications.clear();
|
||||
}
|
||||
}
|
||||
|
||||
async function clearByRepo(rid: string) {
|
||||
try {
|
||||
await invoke("clear_notifications", {
|
||||
params: { type: "repo", content: rid },
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Clearing notifications failed", error);
|
||||
} finally {
|
||||
await reload([rid]);
|
||||
}
|
||||
}
|
||||
|
||||
async function clearByIds(rid: string, ids: string[]) {
|
||||
try {
|
||||
await invoke("clear_notifications", {
|
||||
params: { type: "ids", content: ids },
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Clearing notifications failed", error);
|
||||
} finally {
|
||||
await reload([rid]);
|
||||
}
|
||||
}
|
||||
|
||||
async function reload(rids: string[]) {
|
||||
for (const rid of rids) {
|
||||
const [n, count] = await Promise.all([
|
||||
invoke<PaginatedQuery<Record<string, NotificationItem[]>>>(
|
||||
"list_notifications",
|
||||
{
|
||||
params: {
|
||||
repo: rid,
|
||||
},
|
||||
},
|
||||
),
|
||||
invoke<Record<string, NotificationCount>>(
|
||||
"count_notifications_by_repo",
|
||||
),
|
||||
]);
|
||||
notificationCount = new SvelteMap(Object.entries(count));
|
||||
|
||||
notifications.set(rid, {
|
||||
repo: notificationCount.get(rid)!,
|
||||
items: n.content,
|
||||
pagination: { cursor: n.cursor, more: n.more },
|
||||
});
|
||||
|
||||
// If we are looking at a single repo and there are no more notifications left after a reload, push the user to the general inbox
|
||||
if (activeTab && Object.values(n.content).length === 0) {
|
||||
void router.push({ resource: "inbox" });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function loadMoreContent() {
|
||||
if (more && activeTab) {
|
||||
const c = cursor ? cursor : 20;
|
||||
const p = await invoke<
|
||||
PaginatedQuery<Record<string, NotificationItem[]>>
|
||||
>("list_notifications", {
|
||||
params: {
|
||||
repo: activeTab.rid,
|
||||
skip: more ? c + 20 : c,
|
||||
take: 20,
|
||||
},
|
||||
});
|
||||
|
||||
cursor = p.cursor;
|
||||
more = p.more;
|
||||
|
||||
const currentNotifications = notifications.get(activeTab.rid);
|
||||
notifications.set(activeTab.rid, {
|
||||
repo: currentNotifications!.repo,
|
||||
items: { ...currentNotifications!.items, ...p.content },
|
||||
pagination: { cursor: p.cursor, more: p.more },
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.container {
|
||||
padding: 1rem 1rem 1rem 0;
|
||||
}
|
||||
.header {
|
||||
font-weight: var(--font-weight-medium);
|
||||
font-size: var(--font-size-medium);
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding-right: 1.5rem;
|
||||
align-items: center;
|
||||
min-height: 40px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<Layout
|
||||
loadMoreContent={async () => {
|
||||
if (activeTab) {
|
||||
await loadMoreContent();
|
||||
}
|
||||
}}
|
||||
hideSidebar
|
||||
styleSecondColumnOverflow="visible"
|
||||
publicKey={config.publicKey}>
|
||||
{#snippet headerCenter()}
|
||||
<CopyableId id={config.publicKey} />
|
||||
{/snippet}
|
||||
{#snippet secondColumn()}
|
||||
<HomeSidebar
|
||||
activeTab={{ type: "inbox", repo: activeTab }}
|
||||
{notificationCount}
|
||||
{repoCount} />
|
||||
{/snippet}
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<div>Inbox</div>
|
||||
{#if notifications.size > 0}
|
||||
<Icon onclick={clearAll} name="broom-double" />
|
||||
{/if}
|
||||
</div>
|
||||
{#each notifications.values() as { repo, pagination, items }}
|
||||
<RepoNotifications
|
||||
all={Boolean(activeTab)}
|
||||
{clearByIds}
|
||||
{clearByRepo}
|
||||
{repo}
|
||||
more={pagination.more}
|
||||
{items} />
|
||||
{:else}
|
||||
<Border
|
||||
variant="ghost"
|
||||
styleAlignItems="center"
|
||||
styleJustifyContent="center">
|
||||
<div
|
||||
class="global-flex"
|
||||
style:height="74px"
|
||||
style:justify-content="center">
|
||||
<div class="txt-missing txt-small global-flex" style:gap="0.25rem">
|
||||
<Icon name="none" />
|
||||
No notifications.
|
||||
</div>
|
||||
</div>
|
||||
</Border>
|
||||
{/each}
|
||||
</div>
|
||||
</Layout>
|
||||
@@ -0,0 +1,99 @@
|
||||
<script lang="ts">
|
||||
import type { HomeReposTab } from "@app/lib/router/definitions";
|
||||
import type { Config } from "@bindings/config/Config";
|
||||
import type { NotificationCount } from "@bindings/cob/inbox/NotificationCount";
|
||||
import type { RepoCount } from "@bindings/repo/RepoCount";
|
||||
import type { RepoInfo } from "@bindings/repo/RepoInfo";
|
||||
|
||||
import * as router from "@app/lib/router";
|
||||
import { didFromPublicKey } from "@app/lib/utils";
|
||||
|
||||
import CopyableId from "@app/components/CopyableId.svelte";
|
||||
import HomeSidebar from "@app/components/HomeSidebar.svelte";
|
||||
import Layout from "@app/views/repo/Layout.svelte";
|
||||
import RepoCard from "@app/components/RepoCard.svelte";
|
||||
import Border from "@app/components/Border.svelte";
|
||||
import Icon from "@app/components/Icon.svelte";
|
||||
|
||||
interface Props {
|
||||
activeTab?: HomeReposTab;
|
||||
config: Config;
|
||||
notificationCount: Map<string, NotificationCount>;
|
||||
repoCount: RepoCount;
|
||||
repos: RepoInfo[];
|
||||
}
|
||||
|
||||
/* eslint-disable prefer-const */
|
||||
let { config, repos, notificationCount, repoCount, activeTab }: Props =
|
||||
/* eslint-enable prefer-const */
|
||||
$props();
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.container {
|
||||
padding: 1rem 1rem 1rem 0;
|
||||
}
|
||||
.repo-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(21rem, 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
.header {
|
||||
font-weight: var(--font-weight-medium);
|
||||
font-size: var(--font-size-medium);
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding-right: 1.5rem;
|
||||
align-items: center;
|
||||
min-height: 40px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<Layout
|
||||
hideSidebar
|
||||
styleSecondColumnOverflow="visible"
|
||||
publicKey={config.publicKey}>
|
||||
{#snippet headerCenter()}
|
||||
<CopyableId id={config.publicKey} />
|
||||
{/snippet}
|
||||
{#snippet secondColumn()}
|
||||
<HomeSidebar
|
||||
activeTab={{ type: "repos", filter: activeTab }}
|
||||
{repoCount}
|
||||
{notificationCount} />
|
||||
{/snippet}
|
||||
<div class="container">
|
||||
<div class="header">Repositories</div>
|
||||
<div class="repo-grid">
|
||||
{#each repos as repo}
|
||||
{#if repo.payloads["xyz.radicle.project"]}
|
||||
<RepoCard
|
||||
{repo}
|
||||
selfDid={didFromPublicKey(config.publicKey)}
|
||||
onclick={() => {
|
||||
void router.push({
|
||||
resource: "repo.issues",
|
||||
rid: repo.rid,
|
||||
status: "open",
|
||||
});
|
||||
}} />
|
||||
{/if}
|
||||
{:else}
|
||||
<Border
|
||||
variant="ghost"
|
||||
styleAlignItems="center"
|
||||
styleJustifyContent="center">
|
||||
<div
|
||||
class="global-flex"
|
||||
style:height="74px"
|
||||
style:justify-content="center">
|
||||
<div class="txt-missing txt-small global-flex" style:gap="0.25rem">
|
||||
<Icon name="none" />
|
||||
No repositories.
|
||||
</div>
|
||||
</div>
|
||||
</Border>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</Layout>
|
||||
@@ -35,7 +35,7 @@
|
||||
publicKey: string;
|
||||
headerCenter?: Snippet;
|
||||
secondColumn: Snippet;
|
||||
sidebar: Snippet;
|
||||
sidebar?: Snippet;
|
||||
loadMoreContent?: () => Promise<void>;
|
||||
loadMoreSecondColumn?: () => Promise<void>;
|
||||
hideSidebar?: boolean;
|
||||
@@ -47,7 +47,7 @@
|
||||
publicKey,
|
||||
headerCenter = undefined,
|
||||
secondColumn,
|
||||
sidebar,
|
||||
sidebar = undefined,
|
||||
loadMoreContent = undefined,
|
||||
loadMoreSecondColumn = undefined,
|
||||
hideSidebar = false,
|
||||
@@ -65,7 +65,7 @@
|
||||
if (
|
||||
contentContainer &&
|
||||
contentContainer.scrollTop + contentContainer.clientHeight >=
|
||||
contentContainer.scrollHeight - 600 &&
|
||||
contentContainer.scrollHeight / 2 &&
|
||||
loadingContent === false
|
||||
) {
|
||||
loadingContent = true;
|
||||
@@ -80,7 +80,7 @@
|
||||
secondColumnContainer &&
|
||||
secondColumnContainer.scrollTop +
|
||||
secondColumnContainer.clientHeight >=
|
||||
secondColumnContainer.scrollHeight - 600 &&
|
||||
secondColumnContainer.scrollHeight / 2 &&
|
||||
loadingSecondColumn === false
|
||||
) {
|
||||
loadingSecondColumn = true;
|
||||
@@ -135,12 +135,14 @@
|
||||
<Header {publicKey} center={headerCenter}></Header>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="sidebar"
|
||||
style:display={hideSidebar ? "none" : "flex"}
|
||||
style:padding-right="1rem">
|
||||
{@render sidebar()}
|
||||
</div>
|
||||
{#if sidebar}
|
||||
<div
|
||||
class="sidebar"
|
||||
style:display={hideSidebar ? "none" : "flex"}
|
||||
style:padding-right="1rem">
|
||||
{@render sidebar()}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div
|
||||
class="secondColumn"
|
||||
|
||||
Reference in New Issue
Block a user