Skip to content

Commit

Permalink
Show edited label on edited issue descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastinez committed Dec 14, 2023
1 parent fb29f14 commit e41ef2d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
10 changes: 1 addition & 9 deletions src/components/Comment.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@
let state: "read" | "edit" | "submit" = "read";
function editedCaption(lastEdit: Comment["edits"][0]) {
return ` ${
lastEdit.author.alias
? lastEdit.author.alias
: utils.formatNodeId(lastEdit.author.id)
} edited ${utils.formatTimestamp(lastEdit.timestamp / 1000)}`;
}
export let editComment:
| ((body: string, embeds: Embed[]) => Promise<void>)
| undefined = undefined;
Expand Down Expand Up @@ -137,7 +129,7 @@
<div
class="txt-small"
style:color="var(--color-foreground-dim)"
title={editedCaption(lastEdit)}>
title={utils.formatEditedCaption(lastEdit)}>
edited
</div>
{/if}
Expand Down
10 changes: 10 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Comment } from "@httpd-client";

import md5 from "md5";
import bs58 from "bs58";
import twemojiModule from "twemoji";
Expand Down Expand Up @@ -83,6 +85,14 @@ export function formatCommit(oid: string): string {
return oid.substring(0, 7);
}

export function formatEditedCaption(lastEdit: Comment["edits"][0]) {
return ` ${
lastEdit.author.alias
? lastEdit.author.alias
: formatNodeId(lastEdit.author.id)
} edited ${formatTimestamp(lastEdit.timestamp / 1000)}`;
}

// Takes a path, eg. "../images/image.png", and a base from where to start resolving, e.g. "static/images/index.html".
// Returns the resolved path.
export function canonicalize(
Expand Down
15 changes: 15 additions & 0 deletions src/views/projects/Issue.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,10 @@
$httpdStore.state === "authenticated" && utils.isLocal(baseUrl.hostname)
? $httpdStore.session
: undefined;
$: lastDescriptionEdit =
issue.discussion[0].edits.length > 1
? issue.discussion[0].edits.pop()
: undefined;
type State = "read" | "edit" | "submit";
Expand Down Expand Up @@ -571,6 +575,17 @@
nodeId={issue.author.id}
alias={issue.author.alias} />
{utils.formatTimestamp(issue.discussion[0].timestamp)}
{#if lastDescriptionEdit}
<div class="txt-small" style:color="var(--color-foreground-dim)">
</div>
<div
class="txt-small"
style:color="var(--color-foreground-dim)"
title={utils.formatEditedCaption(lastDescriptionEdit)}>
edited
</div>
{/if}
</div>
</CobHeader>
{#if threads.length > 0}
Expand Down

0 comments on commit e41ef2d

Please sign in to comment.