Implement new design

Co-authored-by: dnlklmn <pelicansinberlin@gmail.com>
Signed-off-by: Rūdolfs Ošiņš <rudolfs@osins.org>
This commit is contained in:
Rūdolfs Ošiņš
2023-10-13 18:05:19 +02:00
co-authored by dnlklmn
parent c5c609167e
commit d914710396
147 changed files with 5374 additions and 4191 deletions
+59 -100
View File
@@ -1,69 +1,27 @@
<script lang="ts" strictEvents>
import type { Comment } from "@httpd-client";
import Button from "@app/components/Button.svelte";
import CommentComponent from "@app/components/Comment.svelte";
import Textarea from "@app/components/Textarea.svelte";
import { createEventDispatcher, tick } from "svelte";
import { scrollIntoView } from "@app/lib/utils";
import { httpdStore } from "@app/lib/httpd";
import { embed } from "@app/lib/file";
import * as utils from "@app/lib/utils";
import CommentComponent from "@app/components/Comment.svelte";
import CommentTextarea from "./CommentTextarea.svelte";
import IconSmall from "./IconSmall.svelte";
export let newEmbeds: { name: string; content: string }[] = [];
export let selectionStart = 0;
export let selectionEnd = 0;
export let thread: { root: Comment; replies: Comment[] };
export let rawPath: string;
export let showReplyTextarea = false;
export let enableAttachments: boolean;
let replyText = "";
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 => {
newEmbeds.push({ name: embed.name, content: embed.content });
const embedText = `![${embed.name}](${embed.oid})\n`;
replyText = replyText
.slice(0, selectionStart)
.concat(embedText, replyText.slice(selectionEnd));
selectionStart += embedText.length;
selectionEnd = selectionStart;
}),
);
}
}
function cancel() {
showReplyTextarea = false;
scrollIntoView(root.id, {
async function toggleReply() {
// This tick allows the DOM to update before scrolling.
await tick();
utils.scrollIntoView(`reply-${root.id}`, {
behavior: "smooth",
block: "center",
});
}
async function toggleReply() {
replyText = "";
showReplyTextarea = !showReplyTextarea;
// This tick allows the DOM to update before scrolling.
await tick();
if (showReplyTextarea) {
scrollIntoView(`reply-${root.id}`, {
behavior: "smooth",
block: "center",
});
}
}
function reply() {
dispatch("reply", { id: root.id, embeds: newEmbeds, body: replyText });
replyText = "";
newEmbeds = [];
showReplyTextarea = false;
}
const dispatch = createEventDispatcher<{
reply: {
id: string;
@@ -82,25 +40,29 @@
.comments {
display: flex;
flex-direction: column;
gap: 1rem;
}
.comment {
background-color: var(--color-foreground-1);
box-shadow: 0 0 0 1px var(--color-border-hint);
border-radius: var(--border-radius-small);
}
.reply {
margin-left: 1.5rem;
.top-level-comment {
background-color: var(--color-background-float);
border-bottom: 1px solid var(--color-fill-separator);
border-top-left-radius: var(--border-radius-small);
border-top-right-radius: var(--border-radius-small);
}
.actions {
display: flex;
justify-content: flex-end;
gap: 1rem;
margin-bottom: 1rem;
.replies {
margin-left: 1rem;
}
.reply {
padding: 1rem;
}
</style>
<div class="comments">
<div class="comment">
<div
class="top-level-comment"
style:border-bottom={replies.length > 0
? "1px solid var(--color-fill-separator)"
: undefined}>
<CommentComponent
{rawPath}
id={root.id}
@@ -109,45 +71,42 @@
reactions={root.reactions}
timestamp={root.timestamp}
body={root.body}
showReplyIcon={Boolean($httpdStore.state === "authenticated")}
on:toggleReply={toggleReply}
on:react />
on:react>
<IconSmall name="chat" slot="icon" />
</CommentComponent>
</div>
{#each replies as reply}
<div class="comment reply">
<CommentComponent
{rawPath}
id={reply.id}
authorId={reply.author.id}
authorAlias={reply.author.alias}
caption="replied"
reactions={reply.reactions}
timestamp={reply.timestamp}
body={reply.body}
on:react />
{#if replies.length > 0}
<div class="replies">
{#each replies as reply}
<CommentComponent
{rawPath}
id={reply.id}
authorId={reply.author.id}
authorAlias={reply.author.alias}
caption="replied"
isReply
isLastReply={replies[replies.length - 1] === reply}
reactions={reply.reactions}
timestamp={reply.timestamp}
body={reply.body}
on:react />
{/each}
</div>
{/each}
{#if showReplyTextarea}
{/if}
{#if $httpdStore.state === "authenticated"}
<div id={`reply-${root.id}`} class="reply">
<Textarea
resizable
focus={showReplyTextarea}
bind:value={replyText}
on:submit={reply}
on:drop={handleFileDrop}
bind:selectionStart
bind:selectionEnd
placeholder="Leave your reply" />
<div class="actions">
<Button variant="text" size="small" on:click={cancel}>Dismiss</Button>
<Button
variant="secondary"
size="small"
disabled={!replyText}
on:click={reply}>
Reply
</Button>
</div>
<CommentTextarea
inline
placeholder="Reply to comment"
on:click={toggleReply}
{enableAttachments}
on:submit={async event => {
dispatch("reply", {
id: root.id,
embeds: event.detail.embeds,
body: event.detail.comment,
});
}} />
</div>
{/if}
</div>