mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-20 22:00:43 +08:00
@@ -37,9 +37,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
function removeAssignee({ detail: key }: { detail: number }) {
|
||||
updatedAssignees = updatedAssignees.filter((_, i) => i !== key);
|
||||
if (action === "create") {
|
||||
function removeAssignee(remove: string) {
|
||||
updatedAssignees = updatedAssignees.filter(assignee => assignee !== remove);
|
||||
if (action === "create" || action === "edit") {
|
||||
dispatch("save", updatedAssignees);
|
||||
}
|
||||
}
|
||||
@@ -62,11 +62,25 @@
|
||||
margin-bottom: 1.25rem;
|
||||
}
|
||||
|
||||
.close {
|
||||
color: inherit;
|
||||
border: none;
|
||||
border-bottom-right-radius: var(--border-radius);
|
||||
border-top-right-radius: var(--border-radius);
|
||||
background-color: transparent;
|
||||
line-height: 1.5;
|
||||
padding: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
.close:hover {
|
||||
color: var(--color-foreground);
|
||||
}
|
||||
|
||||
.chip-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
gap: 0.5rem;
|
||||
white-space: nowrap;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -97,15 +111,18 @@
|
||||
{/if}
|
||||
</div>
|
||||
<div class="body">
|
||||
{#each updatedAssignees as assignee, key (assignee)}
|
||||
<Chip
|
||||
on:remove={removeAssignee}
|
||||
removeable={editInProgress || action === "create"}
|
||||
{key}>
|
||||
<div aria-label="chip" class="chip-content">
|
||||
{#each updatedAssignees as assignee (assignee)}
|
||||
<Chip actionable={editInProgress || action === "create"}>
|
||||
<div slot="content" aria-label="chip" class="txt-overflow chip-content">
|
||||
<Avatar inline nodeId={assignee} />
|
||||
<span>{formatNodeId(assignee)}</span>
|
||||
</div>
|
||||
<button
|
||||
slot="icon"
|
||||
class="section close"
|
||||
on:click={() => removeAssignee(assignee)}>
|
||||
✕
|
||||
</button>
|
||||
</Chip>
|
||||
{:else}
|
||||
<div class="txt-missing">No assignees</div>
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<script lang="ts" strictEvents>
|
||||
import Chip from "@app/components/Chip.svelte";
|
||||
import Clipboard from "@app/components/Clipboard.svelte";
|
||||
|
||||
export let embeds: { name: string; content: string }[] = [];
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.header {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
align-items: center;
|
||||
font-size: var(--font-size-small);
|
||||
margin-bottom: 0.75rem;
|
||||
color: var(--color-foreground-6);
|
||||
}
|
||||
.body {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
flex-direction: row;
|
||||
gap: 0.5rem;
|
||||
margin-bottom: 1.25rem;
|
||||
}
|
||||
|
||||
.chip-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div>
|
||||
<div class="header">
|
||||
<span>Attachments</span>
|
||||
</div>
|
||||
<div class="body">
|
||||
{#each embeds as embed}
|
||||
<Chip actionable>
|
||||
<div slot="content" aria-label="chip" class="chip-content">
|
||||
<span class="txt-overflow">{embed.name}</span>
|
||||
</div>
|
||||
<Clipboard
|
||||
slot="icon"
|
||||
text={`})`}
|
||||
tiny />
|
||||
</Chip>
|
||||
{:else}
|
||||
<div class="txt-missing">No attachments</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
@@ -4,7 +4,8 @@
|
||||
|
||||
export let title: string;
|
||||
export let subtitle: string[];
|
||||
export let error: Error;
|
||||
// This is more explicit than the standard error type.
|
||||
export let error: { message: string; stack?: string };
|
||||
</script>
|
||||
|
||||
<Modal {title} emoji="🚨">
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
} else {
|
||||
updatedLabels = [...updatedLabels, sanitizedValue];
|
||||
inputValue = "";
|
||||
if (action === "create") {
|
||||
if (action === "create" || action === "edit") {
|
||||
dispatch("save", updatedLabels);
|
||||
}
|
||||
}
|
||||
@@ -33,9 +33,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
function removeLabel({ detail: key }: { detail: number }) {
|
||||
updatedLabels = updatedLabels.filter((_, i) => i !== key);
|
||||
if (action === "create") {
|
||||
function removeLabel(remove: string) {
|
||||
updatedLabels = updatedLabels.filter(label => label !== remove);
|
||||
if (action === "create" || action === "edit") {
|
||||
dispatch("save", updatedLabels);
|
||||
}
|
||||
}
|
||||
@@ -57,10 +57,18 @@
|
||||
gap: 0.5rem;
|
||||
margin-bottom: 1.25rem;
|
||||
}
|
||||
.label {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
.close {
|
||||
color: inherit;
|
||||
border: none;
|
||||
border-bottom-right-radius: var(--border-radius);
|
||||
border-top-right-radius: var(--border-radius);
|
||||
background-color: transparent;
|
||||
line-height: 1.5;
|
||||
padding: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
.close:hover {
|
||||
color: var(--color-foreground);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -91,12 +99,14 @@
|
||||
{/if}
|
||||
</div>
|
||||
<div class="metadata-section-body">
|
||||
{#each updatedLabels as label, key (label)}
|
||||
<Chip
|
||||
on:remove={removeLabel}
|
||||
removeable={editInProgress || action === "create"}
|
||||
{key}>
|
||||
<div aria-label="chip" class="label">{label}</div>
|
||||
{#each updatedLabels as label}
|
||||
<Chip actionable={editInProgress || action === "create"}>
|
||||
<div slot="content" aria-label="chip" class="txt-overflow">{label}</div>
|
||||
<div slot="icon">
|
||||
<button class="section close" on:click={() => removeLabel(label)}>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
</Chip>
|
||||
{:else}
|
||||
<div class="txt-missing">No labels</div>
|
||||
|
||||
@@ -5,10 +5,12 @@
|
||||
|
||||
import { isEqual } from "lodash";
|
||||
|
||||
import * as router from "@app/lib/router";
|
||||
import * as modal from "@app/lib/modal";
|
||||
import * as router from "@app/lib/router";
|
||||
import * as utils from "@app/lib/utils";
|
||||
import { HttpdClient } from "@httpd-client";
|
||||
import { ResponseError } from "@httpd-client/lib/fetcher";
|
||||
import { embed } from "@app/lib/file";
|
||||
import { httpdStore } from "@app/lib/httpd";
|
||||
|
||||
import AssigneeInput from "@app/views/projects/Cob/AssigneeInput.svelte";
|
||||
@@ -17,11 +19,12 @@
|
||||
import Button from "@app/components/Button.svelte";
|
||||
import CobHeader from "@app/views/projects/Cob/CobHeader.svelte";
|
||||
import CobStateButton from "@app/views/projects/Cob/CobStateButton.svelte";
|
||||
import Embeds from "@app/views/projects/Cob/Embeds.svelte";
|
||||
import ErrorModal from "@app/views/projects/Cob/ErrorModal.svelte";
|
||||
import Floating, { closeFocused } from "@app/components/Floating.svelte";
|
||||
import Icon from "@app/components/Icon.svelte";
|
||||
import LabelInput from "./Cob/LabelInput.svelte";
|
||||
import Layout from "./Layout.svelte";
|
||||
import LabelInput from "@app/views/projects/Cob/LabelInput.svelte";
|
||||
import Layout from "@app/views/projects/Layout.svelte";
|
||||
import Markdown from "@app/components/Markdown.svelte";
|
||||
import ReactionSelector from "@app/components/ReactionSelector.svelte";
|
||||
import Reactions from "@app/components/Reactions.svelte";
|
||||
@@ -35,6 +38,9 @@
|
||||
const rawPath = utils.getRawBasePath(project.id, baseUrl, project.head);
|
||||
const api = new HttpdClient(baseUrl);
|
||||
|
||||
let newEmbeds: { name: string; content: string }[] = [];
|
||||
let selectionStart = 0;
|
||||
let selectionEnd = 0;
|
||||
let action: "edit" | "view";
|
||||
$: action =
|
||||
$httpdStore.state === "authenticated" && utils.isLocal(baseUrl.hostname)
|
||||
@@ -46,9 +52,47 @@
|
||||
["Close issue as other", { status: "closed", reason: "other" }],
|
||||
];
|
||||
|
||||
const MAX_BLOB_SIZE = 4_194_304;
|
||||
|
||||
function handleFileDrop(event: DragEvent) {
|
||||
event.preventDefault();
|
||||
if (event.dataTransfer) {
|
||||
const embeds = Array.from(event.dataTransfer.files).map(embed);
|
||||
void Promise.all(embeds).then(embeds =>
|
||||
embeds.forEach(embed => {
|
||||
if (embed.content.length > MAX_BLOB_SIZE) {
|
||||
modal.show({
|
||||
component: ErrorModal,
|
||||
props: {
|
||||
title: "File too large",
|
||||
subtitle: [
|
||||
"The file you tried to upload is too large.",
|
||||
"The maximum file size is 4MB.",
|
||||
],
|
||||
error: { message: `File ${embed.name} is too large` },
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
newEmbeds.push({ name: embed.name, content: embed.content });
|
||||
const embedText = `\n`;
|
||||
commentBody = commentBody
|
||||
.slice(0, selectionStart)
|
||||
.concat(embedText, commentBody.slice(selectionEnd));
|
||||
selectionStart += embedText.length;
|
||||
selectionEnd = selectionStart;
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function createReply({
|
||||
detail: reply,
|
||||
}: CustomEvent<{ id: string; body: string }>) {
|
||||
}: CustomEvent<{
|
||||
id: string;
|
||||
embeds: { name: string; content: string }[];
|
||||
body: string;
|
||||
}>) {
|
||||
if ($httpdStore.state === "authenticated" && reply.body.trim().length > 0) {
|
||||
const status = await updateIssue(
|
||||
project.id,
|
||||
@@ -56,6 +100,7 @@
|
||||
{
|
||||
type: "comment",
|
||||
body: reply.body,
|
||||
embeds: reply.embeds,
|
||||
replyTo: reply.id,
|
||||
},
|
||||
$httpdStore.session,
|
||||
@@ -72,7 +117,12 @@
|
||||
const status = await updateIssue(
|
||||
project.id,
|
||||
issue.id,
|
||||
{ type: "comment", body, replyTo: issue.id },
|
||||
{
|
||||
type: "comment",
|
||||
body,
|
||||
embeds: newEmbeds,
|
||||
replyTo: issue.id,
|
||||
},
|
||||
$httpdStore.session,
|
||||
api,
|
||||
);
|
||||
@@ -218,7 +268,10 @@
|
||||
"There was an error while refreshing this issue.",
|
||||
"Check your radicle-httpd logs for details.",
|
||||
],
|
||||
error,
|
||||
error: {
|
||||
message: error.message,
|
||||
stack: error.stack,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -237,7 +290,23 @@
|
||||
await api.project.updateIssue(projectId, issueId, action, session.id);
|
||||
return "success";
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
if (error instanceof ResponseError && error.status === 413) {
|
||||
modal.show({
|
||||
component: ErrorModal,
|
||||
props: {
|
||||
title: "Issue editing failed",
|
||||
subtitle: [
|
||||
"Not able to upload the attached file.",
|
||||
"Try to reduce the size of your attachment.",
|
||||
"Check your radicle-httpd logs for details.",
|
||||
],
|
||||
error: {
|
||||
message: error.body as string,
|
||||
stack: error.stack,
|
||||
},
|
||||
},
|
||||
});
|
||||
} else if (error instanceof Error) {
|
||||
modal.show({
|
||||
component: ErrorModal,
|
||||
props: {
|
||||
@@ -246,7 +315,10 @@
|
||||
"There was an error while updating the issue.",
|
||||
"Check your radicle-httpd logs for details.",
|
||||
],
|
||||
error,
|
||||
error: {
|
||||
message: error.message,
|
||||
stack: error.stack,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -256,6 +328,13 @@
|
||||
|
||||
const issueDescription = issue.discussion[0];
|
||||
|
||||
$: embeds = issue.discussion.reduce(
|
||||
(acc, comment) => {
|
||||
acc.push(...comment.embeds);
|
||||
return acc;
|
||||
},
|
||||
[] as { name: string; content: string }[],
|
||||
);
|
||||
$: selectedItem = issue.state.status === "closed" ? items[0] : items[1];
|
||||
$: threads = issue.discussion
|
||||
.filter(
|
||||
@@ -402,7 +481,6 @@
|
||||
{#if issueReactions.size > 0}
|
||||
<div style:margin-top="1rem">
|
||||
<Reactions
|
||||
clickable={$httpdStore.state === "authenticated"}
|
||||
reactions={issueReactions}
|
||||
on:remove={event =>
|
||||
handleReaction({ ...event.detail, id: issue.id })} />
|
||||
@@ -430,8 +508,12 @@
|
||||
<div style:margin-top="1rem">
|
||||
<Textarea
|
||||
resizable
|
||||
bind:selectionStart
|
||||
bind:selectionEnd
|
||||
on:drop={handleFileDrop}
|
||||
on:submit={async () => {
|
||||
await createComment(commentBody);
|
||||
newEmbeds = [];
|
||||
commentBody = "";
|
||||
}}
|
||||
bind:value={commentBody}
|
||||
@@ -448,6 +530,7 @@
|
||||
disabled={!commentBody}
|
||||
on:click={async () => {
|
||||
await createComment(commentBody);
|
||||
newEmbeds = [];
|
||||
commentBody = "";
|
||||
}}>
|
||||
Comment
|
||||
@@ -462,6 +545,7 @@
|
||||
assignees={issue.assignees}
|
||||
on:save={saveAssignees} />
|
||||
<LabelInput {action} labels={issue.labels} on:save={saveLabels} />
|
||||
<Embeds {embeds} />
|
||||
</div>
|
||||
</div>
|
||||
</Layout>
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import * as router from "@app/lib/router";
|
||||
import * as utils from "@app/lib/utils";
|
||||
import { HttpdClient } from "@httpd-client";
|
||||
import { embed } from "@app/lib/file";
|
||||
import { httpdStore } from "@app/lib/httpd";
|
||||
|
||||
import AssigneeInput from "@app/views/projects/Cob/AssigneeInput.svelte";
|
||||
@@ -22,6 +23,9 @@
|
||||
export let baseUrl: BaseUrl;
|
||||
export let project: Project;
|
||||
|
||||
const newEmbeds: Map<string, { name: string; content: string }> = new Map();
|
||||
let selectionStart = 0;
|
||||
let selectionEnd = 0;
|
||||
let preview: boolean = false;
|
||||
let action: "create" | "view";
|
||||
$: action =
|
||||
@@ -32,20 +36,39 @@
|
||||
: "view";
|
||||
|
||||
let issueTitle = "";
|
||||
let issueText: string | undefined = undefined;
|
||||
let issueText = "";
|
||||
let assignees: string[] = [];
|
||||
let labels: string[] = [];
|
||||
|
||||
const api = new HttpdClient(baseUrl);
|
||||
|
||||
function handleFileDrop(event: DragEvent) {
|
||||
event.preventDefault();
|
||||
if (event.dataTransfer) {
|
||||
const embeds = Array.from(event.dataTransfer.files).map(embed);
|
||||
void Promise.all(embeds).then(embeds =>
|
||||
embeds.forEach(({ oid, name, content }) => {
|
||||
newEmbeds.set(oid, { name, content });
|
||||
const embedText = `\n`;
|
||||
issueText = issueText
|
||||
.slice(0, selectionStart)
|
||||
.concat(embedText, issueText.slice(selectionEnd));
|
||||
selectionStart += embedText.length;
|
||||
selectionEnd = selectionStart;
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function createIssue(sessionId: string) {
|
||||
try {
|
||||
const result = await api.project.createIssue(
|
||||
project.id,
|
||||
{
|
||||
title: issueTitle,
|
||||
description: issueText ?? "",
|
||||
description: issueText,
|
||||
assignees: assignees,
|
||||
embeds: [...newEmbeds.values()],
|
||||
labels: labels,
|
||||
},
|
||||
sessionId,
|
||||
@@ -141,6 +164,9 @@
|
||||
{#if action === "create"}
|
||||
<Textarea
|
||||
resizable
|
||||
bind:selectionStart
|
||||
bind:selectionEnd
|
||||
on:drop={handleFileDrop}
|
||||
bind:value={issueText}
|
||||
on:submit={() => {
|
||||
void createIssue(session.id);
|
||||
@@ -150,6 +176,7 @@
|
||||
<p class="txt-missing">No description</p>
|
||||
{:else}
|
||||
<Markdown
|
||||
embeds={newEmbeds}
|
||||
content={issueText}
|
||||
rawPath={utils.getRawBasePath(
|
||||
project.id,
|
||||
|
||||
Reference in New Issue
Block a user