mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 22:30:41 +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) &&
|
||||
|
||||
Reference in New Issue
Block a user