mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 10:10:30 +08:00
Adding embed editing in issues and patches
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script lang="ts" strictEvents>
|
||||
import type { Embed } from "@app/lib/file";
|
||||
import type { Embed } from "@httpd-client";
|
||||
import type { GroupedReactions } from "@app/lib/reactions";
|
||||
|
||||
import { tick } from "svelte";
|
||||
@@ -21,6 +21,7 @@
|
||||
export let body: string;
|
||||
export let enableAttachments: boolean = false;
|
||||
export let reactions: GroupedReactions | undefined = undefined;
|
||||
export let embeds: Map<string, Embed> | undefined = undefined;
|
||||
export let caption = "commented";
|
||||
export let rawPath: string;
|
||||
export let timestamp: number;
|
||||
@@ -145,6 +146,7 @@
|
||||
<ExtendedTextarea
|
||||
{rawPath}
|
||||
{body}
|
||||
{embeds}
|
||||
{enableAttachments}
|
||||
submitInProgress={state === "submit"}
|
||||
submitCaption="Save"
|
||||
@@ -152,7 +154,7 @@
|
||||
on:submit={async ({ detail: { comment, embeds } }) => {
|
||||
state = "submit";
|
||||
try {
|
||||
await editComment_(comment, embeds);
|
||||
await editComment_(comment, Array.from(embeds.values()));
|
||||
} finally {
|
||||
state = "read";
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import type { Embed } from "@app/lib/file";
|
||||
import type { Embed } from "@httpd-client";
|
||||
|
||||
import ExtendedTextarea from "@app/components/ExtendedTextarea.svelte";
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
on:submit={async ({ detail: { comment, embeds } }) => {
|
||||
try {
|
||||
state = "submit";
|
||||
await submit(comment, embeds);
|
||||
await submit(comment, Array.from(embeds.values()));
|
||||
} finally {
|
||||
state = "collapsed";
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts" strictEvents>
|
||||
import type { Embed, EmbedWithOid } from "@app/lib/file";
|
||||
import type { Embed } from "@httpd-client";
|
||||
|
||||
import { createEventDispatcher } from "svelte";
|
||||
|
||||
@@ -23,10 +23,10 @@
|
||||
export let inline: boolean = false;
|
||||
export let rawPath: string;
|
||||
export let body: string = "";
|
||||
export let embeds: Map<string, Embed> = new Map();
|
||||
export let submitInProgress: boolean = false;
|
||||
|
||||
let preview: boolean = false;
|
||||
let newEmbeds: EmbedWithOid[] = [];
|
||||
let selectionStart = 0;
|
||||
let selectionEnd = 0;
|
||||
let inputFiles: FileList | undefined = undefined;
|
||||
@@ -34,15 +34,14 @@
|
||||
const inputId = `input-label-${crypto.randomUUID()}`;
|
||||
|
||||
const dispatch = createEventDispatcher<{
|
||||
submit: { comment: string; embeds: Embed[] };
|
||||
submit: { comment: string; embeds: Map<string, Embed> };
|
||||
close: null;
|
||||
click: null;
|
||||
}>();
|
||||
|
||||
function submit() {
|
||||
dispatch("submit", { comment: body, embeds: newEmbeds });
|
||||
dispatch("submit", { comment: body, embeds });
|
||||
preview = false;
|
||||
newEmbeds = [];
|
||||
}
|
||||
|
||||
const MAX_BLOB_SIZE = 4_194_304;
|
||||
@@ -86,10 +85,10 @@
|
||||
}
|
||||
|
||||
function attachEmbeds(files: FileList) {
|
||||
const embeds = Array.from(files).map(embed);
|
||||
void Promise.all(embeds).then(embeds =>
|
||||
embeds.forEach(embed => {
|
||||
if (embed.content.length > MAX_BLOB_SIZE) {
|
||||
const embedPromise = Array.from(files).map(embed);
|
||||
void Promise.all(embedPromise).then(newEmbeds =>
|
||||
newEmbeds.forEach(({ oid, name, content }) => {
|
||||
if (content.length > MAX_BLOB_SIZE) {
|
||||
modal.show({
|
||||
component: ErrorModal,
|
||||
props: {
|
||||
@@ -103,15 +102,8 @@
|
||||
});
|
||||
return;
|
||||
}
|
||||
newEmbeds = [
|
||||
...newEmbeds,
|
||||
{
|
||||
oid: embed.oid,
|
||||
name: embed.name,
|
||||
content: embed.content,
|
||||
},
|
||||
];
|
||||
const embedText = `\n`;
|
||||
embeds.set(oid, { name, content });
|
||||
const embedText = `\n`;
|
||||
body = body
|
||||
.slice(0, selectionStart)
|
||||
.concat(embedText, body.slice(selectionEnd));
|
||||
@@ -196,7 +188,7 @@
|
||||
</Radio>
|
||||
{#if preview}
|
||||
<div class="preview">
|
||||
<Markdown {rawPath} content={body} embeds={newEmbeds} />
|
||||
<Markdown {rawPath} content={body} {embeds} />
|
||||
</div>
|
||||
{:else}
|
||||
<input
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import type { EmbedWithOid } from "@app/lib/file";
|
||||
import type { Embed } from "@httpd-client";
|
||||
|
||||
import dompurify from "dompurify";
|
||||
import matter from "@radicle/gray-matter";
|
||||
@@ -28,7 +28,7 @@
|
||||
export let rawPath: string;
|
||||
// If present, means we are in a preview context,
|
||||
// use this for image previews instead of /raw URLs.
|
||||
export let embeds: EmbedWithOid[] | undefined = undefined;
|
||||
export let embeds: Map<string, Embed> | undefined = undefined;
|
||||
|
||||
let container: HTMLElement;
|
||||
let frontMatter: [string, any][] | undefined = undefined;
|
||||
@@ -112,10 +112,9 @@
|
||||
|
||||
// If the image is an oid embed
|
||||
if (imagePath && isCommit(imagePath)) {
|
||||
const embed = embeds?.find(e => {
|
||||
return e.oid === imagePath;
|
||||
});
|
||||
if (embed) {
|
||||
const embed = embeds?.get(imagePath);
|
||||
// If the embed content is the base64 encoded image, use it directly.
|
||||
if (embed && embed.content.startsWith("data:")) {
|
||||
i.setAttribute("src", embed.content);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -20,10 +20,11 @@
|
||||
</script>
|
||||
|
||||
<script lang="ts" strictEvents>
|
||||
import type { Embed } from "@app/lib/file";
|
||||
import type { Embed } from "@httpd-client";
|
||||
|
||||
import * as utils from "@app/lib/utils";
|
||||
import partial from "lodash/partial";
|
||||
import { parseEmbedIntoMap } from "@app/lib/file";
|
||||
import { tick } from "svelte";
|
||||
|
||||
import CommentComponent from "@app/components/Comment.svelte";
|
||||
@@ -88,13 +89,14 @@
|
||||
<div class="comments">
|
||||
<div class="top-level-comment" class:has-replies={replies.length > 0}>
|
||||
<CommentComponent
|
||||
{enableAttachments}
|
||||
{rawPath}
|
||||
id={root.id}
|
||||
authorId={root.author.id}
|
||||
authorAlias={root.author.alias}
|
||||
reactions={root.reactions}
|
||||
embeds={parseEmbedIntoMap(root.embeds)}
|
||||
timestamp={root.timestamp}
|
||||
disableEdit={root.embeds.length > 0}
|
||||
body={root.body}
|
||||
editComment={editComment &&
|
||||
canEditComment(root.author.id) &&
|
||||
@@ -107,6 +109,7 @@
|
||||
<div class="replies">
|
||||
{#each replies as reply}
|
||||
<CommentComponent
|
||||
{enableAttachments}
|
||||
{rawPath}
|
||||
id={reply.id}
|
||||
authorId={reply.author.id}
|
||||
@@ -115,8 +118,8 @@
|
||||
isReply
|
||||
isLastReply={replies[replies.length - 1] === reply}
|
||||
reactions={reply.reactions}
|
||||
embeds={parseEmbedIntoMap(reply.embeds)}
|
||||
timestamp={reply.timestamp}
|
||||
disableEdit={reply.embeds.length > 0}
|
||||
body={reply.body}
|
||||
editComment={editComment &&
|
||||
canEditComment(reply.author.id) &&
|
||||
|
||||
+9
-8
@@ -1,10 +1,4 @@
|
||||
export interface Embed {
|
||||
name: string;
|
||||
content: string;
|
||||
}
|
||||
export interface EmbedWithOid extends Embed {
|
||||
oid: string;
|
||||
}
|
||||
import type { Embed } from "@httpd-client";
|
||||
|
||||
async function parseGitOid(bytes: Uint8Array): Promise<string> {
|
||||
// Create the header
|
||||
@@ -38,6 +32,13 @@ function base64String(file: File): Promise<string> {
|
||||
});
|
||||
}
|
||||
|
||||
export function parseEmbedIntoMap(embeds: Embed[]) {
|
||||
return embeds.reduce((acc, embed) => {
|
||||
acc.set(embed.content.substring(4), embed);
|
||||
return acc;
|
||||
}, new Map());
|
||||
}
|
||||
|
||||
const mimes: Record<string, string> = {
|
||||
"3gp": "video/3gpp",
|
||||
"7z": "application/x-7z-compressed",
|
||||
@@ -101,7 +102,7 @@ const mimes: Record<string, string> = {
|
||||
zip: "application/zip",
|
||||
};
|
||||
|
||||
async function embed(file: File): Promise<EmbedWithOid> {
|
||||
async function embed(file: File) {
|
||||
const bytes = new Uint8Array(await file.arrayBuffer());
|
||||
const oid = await parseGitOid(bytes);
|
||||
const content = await base64String(file);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts" strictEvents>
|
||||
import type { Embed } from "@app/lib/file";
|
||||
import type { Embed } from "@httpd-client";
|
||||
|
||||
import Badge from "@app/components/Badge.svelte";
|
||||
import Clipboard from "@app/components/Clipboard.svelte";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<script lang="ts">
|
||||
import type { Embed } from "@httpd-client/lib/project/comment";
|
||||
import type {
|
||||
BaseUrl,
|
||||
DiffResponse,
|
||||
Embed,
|
||||
PatchState,
|
||||
Verdict,
|
||||
} from "@httpd-client";
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
<script lang="ts">
|
||||
import type { BaseUrl, Issue, IssueState, Project } from "@httpd-client";
|
||||
import type { Embed } from "@app/lib/file";
|
||||
import type {
|
||||
BaseUrl,
|
||||
Issue,
|
||||
IssueState,
|
||||
Embed,
|
||||
Project,
|
||||
} from "@httpd-client";
|
||||
import type { Session } from "@app/lib/httpd";
|
||||
|
||||
import isEqual from "lodash/isEqual";
|
||||
@@ -15,6 +20,7 @@
|
||||
import { closeFocused } from "@app/components/Popover.svelte";
|
||||
import { groupReactions } from "@app/lib/reactions";
|
||||
import { httpdStore } from "@app/lib/httpd";
|
||||
import { parseEmbedIntoMap } from "@app/lib/file";
|
||||
|
||||
import AssigneeInput from "@app/views/projects/Cob/AssigneeInput.svelte";
|
||||
import Badge from "@app/components/Badge.svelte";
|
||||
@@ -358,14 +364,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: embeds = issue.discussion.reduce(
|
||||
(acc, comment) => {
|
||||
acc[comment.id] = comment.embeds;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, Embed[]>,
|
||||
$: uniqueEmbeds = uniqBy(
|
||||
issue.discussion.flatMap(comment => comment.embeds),
|
||||
"content",
|
||||
);
|
||||
$: uniqueEmbeds = uniqBy(Object.values(embeds).flat(), "content");
|
||||
$: selectedItem = issue.state.status === "closed" ? items[0] : items[1];
|
||||
$: threads = issue.discussion
|
||||
.filter(
|
||||
@@ -518,6 +520,7 @@
|
||||
<ExtendedTextarea
|
||||
rawPath={rawPath(project.head)}
|
||||
enableAttachments
|
||||
embeds={parseEmbedIntoMap(issue.discussion[0].embeds)}
|
||||
body={issue.discussion[0].body}
|
||||
submitCaption="Save"
|
||||
submitInProgress={issueState === "submit"}
|
||||
@@ -535,7 +538,7 @@
|
||||
issue.title,
|
||||
issue.id,
|
||||
comment,
|
||||
embeds,
|
||||
Array.from(embeds.values()),
|
||||
);
|
||||
} finally {
|
||||
issueState = "read";
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<script lang="ts">
|
||||
import type { BaseUrl, Project } from "@httpd-client";
|
||||
import type { EmbedWithOid } from "@app/lib/file";
|
||||
import type { BaseUrl, Embed, Project } from "@httpd-client";
|
||||
|
||||
import * as modal from "@app/lib/modal";
|
||||
import * as router from "@app/lib/router";
|
||||
@@ -28,7 +27,6 @@
|
||||
export let rawPath: (commit?: string) => string;
|
||||
export let tracking: boolean;
|
||||
|
||||
let newEmbeds: EmbedWithOid[] = [];
|
||||
let preview: boolean = false;
|
||||
let selectionStart = 0;
|
||||
let selectionEnd = 0;
|
||||
@@ -41,6 +39,7 @@
|
||||
let creatingIssue: boolean = false;
|
||||
|
||||
const api = new HttpdClient(baseUrl);
|
||||
const newEmbeds = new Map<string, Embed>();
|
||||
|
||||
function handleFileDrop(event: { detail: DragEvent }) {
|
||||
event.detail.preventDefault();
|
||||
@@ -48,10 +47,7 @@
|
||||
const embeds = Array.from(event.detail.dataTransfer.files).map(embed);
|
||||
void Promise.all(embeds).then(embeds =>
|
||||
embeds.forEach(({ oid, name, content }) => {
|
||||
newEmbeds = [
|
||||
...newEmbeds,
|
||||
{ oid: oid, name: name, content: content },
|
||||
];
|
||||
newEmbeds.set(oid, { name, content });
|
||||
const embedText = `\n`;
|
||||
issueText = issueText
|
||||
.slice(0, selectionStart)
|
||||
|
||||
@@ -35,8 +35,7 @@
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import type { BaseUrl, Patch } from "@httpd-client";
|
||||
import type { Embed } from "@app/lib/file";
|
||||
import type { BaseUrl, Embed, Patch } from "@httpd-client";
|
||||
import type { PatchView } from "./router";
|
||||
import type { Route } from "@app/lib/router";
|
||||
import type { ComponentProps } from "svelte";
|
||||
@@ -45,10 +44,11 @@
|
||||
import * as role from "@app/lib/roles";
|
||||
import * as router from "@app/lib/router";
|
||||
import * as utils from "@app/lib/utils";
|
||||
import { HttpdClient } from "@httpd-client";
|
||||
import capitalize from "lodash/capitalize";
|
||||
import isEqual from "lodash/isEqual";
|
||||
import partial from "lodash/partial";
|
||||
import uniqBy from "lodash/uniqBy";
|
||||
import { HttpdClient } from "@httpd-client";
|
||||
import { httpdStore, type Session } from "@app/lib/httpd";
|
||||
|
||||
import Badge from "@app/components/Badge.svelte";
|
||||
@@ -60,6 +60,7 @@
|
||||
import CommitTeaser from "@app/views/projects/Commit/CommitTeaser.svelte";
|
||||
import DropdownList from "@app/components/DropdownList.svelte";
|
||||
import DropdownListItem from "@app/components/DropdownList/DropdownListItem.svelte";
|
||||
import Embeds from "@app/views/projects/Cob/Embeds.svelte";
|
||||
import ErrorModal from "@app/modals/ErrorModal.svelte";
|
||||
import ExtendedTextarea from "@app/components/ExtendedTextarea.svelte";
|
||||
import Icon from "@app/components/Icon.svelte";
|
||||
@@ -468,6 +469,12 @@
|
||||
revisionId = view.revision;
|
||||
}
|
||||
|
||||
$: uniqueEmbeds = uniqBy(
|
||||
patch.revisions.flatMap(({ discussions }) =>
|
||||
discussions.flatMap(comment => comment.embeds),
|
||||
),
|
||||
"content",
|
||||
);
|
||||
$: description = patch.revisions[0].description;
|
||||
$: newDescription = description;
|
||||
$: patchReviews = computeReviews(patch);
|
||||
@@ -961,6 +968,7 @@
|
||||
}
|
||||
}
|
||||
}} />
|
||||
<Embeds embeds={uniqueEmbeds} />
|
||||
</div>
|
||||
</div>
|
||||
</Layout>
|
||||
|
||||
Reference in New Issue
Block a user