add:enhance comments list with scroll, limit, and styling
- Add maxComments, showCommentForm and isScrollable props to CommentsList to limit displayed comments, toggle the form, and enable a scrollable comments container. Show a "+N more comments" indicator when limited. - Adjust CommentForm and list styles (padding, background, flex behavior, responsive heights). Pass currentUserId and new props from FindPreview and FindCard where applicable.
This commit is contained in:
@@ -74,8 +74,10 @@
|
|||||||
|
|
||||||
<style>
|
<style>
|
||||||
.comment-form {
|
.comment-form {
|
||||||
padding: 0.75rem 0;
|
padding: 0.75rem 1rem;
|
||||||
border-top: 1px solid hsl(var(--border));
|
border-top: 1px solid hsl(var(--border));
|
||||||
|
background: hsl(var(--background));
|
||||||
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.input-container {
|
.input-container {
|
||||||
|
|||||||
@@ -9,9 +9,19 @@
|
|||||||
findId: string;
|
findId: string;
|
||||||
currentUserId?: string;
|
currentUserId?: string;
|
||||||
collapsed?: boolean;
|
collapsed?: boolean;
|
||||||
|
maxComments?: number;
|
||||||
|
showCommentForm?: boolean;
|
||||||
|
isScrollable?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
let { findId, currentUserId, collapsed = true }: CommentsListProps = $props();
|
let {
|
||||||
|
findId,
|
||||||
|
currentUserId,
|
||||||
|
collapsed = true,
|
||||||
|
maxComments,
|
||||||
|
showCommentForm = true,
|
||||||
|
isScrollable = false
|
||||||
|
}: CommentsListProps = $props();
|
||||||
|
|
||||||
let isExpanded = $state(!collapsed);
|
let isExpanded = $state(!collapsed);
|
||||||
let hasLoadedComments = $state(false);
|
let hasLoadedComments = $state(false);
|
||||||
@@ -90,8 +100,8 @@
|
|||||||
<button class="retry-button" onclick={loadComments}> Try again </button>
|
<button class="retry-button" onclick={loadComments}> Try again </button>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<div class="comments">
|
<div class="comments" class:scrollable={isScrollable}>
|
||||||
{#each $commentsState.comments as comment (comment.id)}
|
{#each maxComments ? $commentsState.comments.slice(0, maxComments) : $commentsState.comments as comment (comment.id)}
|
||||||
<Comment
|
<Comment
|
||||||
{comment}
|
{comment}
|
||||||
showDeleteButton={canDeleteComment(comment)}
|
showDeleteButton={canDeleteComment(comment)}
|
||||||
@@ -100,10 +110,19 @@
|
|||||||
{:else}
|
{:else}
|
||||||
<div class="no-comments">No comments yet. Be the first to comment!</div>
|
<div class="no-comments">No comments yet. Be the first to comment!</div>
|
||||||
{/each}
|
{/each}
|
||||||
|
{#if maxComments && $commentsState.comments.length > maxComments}
|
||||||
|
<div class="see-more">
|
||||||
|
<div class="see-more-text">
|
||||||
|
+{$commentsState.comments.length - maxComments} more comments
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<CommentForm onSubmit={handleAddComment} />
|
{#if showCommentForm}
|
||||||
|
<CommentForm onSubmit={handleAddComment} />
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
@@ -131,12 +150,36 @@
|
|||||||
.comments-container {
|
.comments-container {
|
||||||
border-top: 1px solid hsl(var(--border));
|
border-top: 1px solid hsl(var(--border));
|
||||||
margin-top: 0.5rem;
|
margin-top: 0.5rem;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 100%;
|
||||||
|
min-height: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.comments {
|
.comments {
|
||||||
padding: 0.75rem 0;
|
padding: 0.75rem 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.comments.scrollable {
|
||||||
|
flex: 1;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 0.75rem 1rem;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.see-more {
|
||||||
|
padding: 0.5rem 0;
|
||||||
|
border-top: 1px solid hsl(var(--border));
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.see-more-text {
|
||||||
|
text-align: center;
|
||||||
|
color: hsl(var(--muted-foreground));
|
||||||
|
font-size: 0.75rem;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
.no-comments {
|
.no-comments {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: hsl(var(--muted-foreground));
|
color: hsl(var(--muted-foreground));
|
||||||
|
|||||||
@@ -148,7 +148,13 @@
|
|||||||
<!-- Comments Section -->
|
<!-- Comments Section -->
|
||||||
{#if showComments}
|
{#if showComments}
|
||||||
<div class="comments-section">
|
<div class="comments-section">
|
||||||
<CommentsList findId={id} {currentUserId} collapsed={false} />
|
<CommentsList
|
||||||
|
findId={id}
|
||||||
|
{currentUserId}
|
||||||
|
collapsed={false}
|
||||||
|
maxComments={5}
|
||||||
|
showCommentForm={true}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import LikeButton from '$lib/components/LikeButton.svelte';
|
import LikeButton from '$lib/components/LikeButton.svelte';
|
||||||
import VideoPlayer from '$lib/components/VideoPlayer.svelte';
|
import VideoPlayer from '$lib/components/VideoPlayer.svelte';
|
||||||
import ProfilePicture from '$lib/components/ProfilePicture.svelte';
|
import ProfilePicture from '$lib/components/ProfilePicture.svelte';
|
||||||
|
import CommentsList from '$lib/components/CommentsList.svelte';
|
||||||
|
|
||||||
interface Find {
|
interface Find {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -30,9 +31,10 @@
|
|||||||
interface Props {
|
interface Props {
|
||||||
find: Find | null;
|
find: Find | null;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
|
currentUserId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
let { find, onClose }: Props = $props();
|
let { find, onClose, currentUserId }: Props = $props();
|
||||||
|
|
||||||
let showModal = $state(true);
|
let showModal = $state(true);
|
||||||
let currentMediaIndex = $state(0);
|
let currentMediaIndex = $state(0);
|
||||||
@@ -251,6 +253,15 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="comments-section">
|
||||||
|
<CommentsList
|
||||||
|
findId={find.id}
|
||||||
|
{currentUserId}
|
||||||
|
isScrollable={true}
|
||||||
|
showCommentForm={true}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</SheetContent>
|
</SheetContent>
|
||||||
</Sheet>
|
</Sheet>
|
||||||
@@ -542,6 +553,30 @@
|
|||||||
background: hsl(var(--secondary) / 0.8);
|
background: hsl(var(--secondary) / 0.8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.comments-section {
|
||||||
|
flex: 1;
|
||||||
|
min-height: 0;
|
||||||
|
border-top: 1px solid hsl(var(--border));
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Desktop comments section */
|
||||||
|
@media (min-width: 768px) {
|
||||||
|
.comments-section {
|
||||||
|
height: calc(100vh - 400px);
|
||||||
|
min-height: 200px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Mobile comments section */
|
||||||
|
@media (max-width: 767px) {
|
||||||
|
.comments-section {
|
||||||
|
height: calc(80vh - 350px);
|
||||||
|
min-height: 150px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Mobile specific adjustments */
|
/* Mobile specific adjustments */
|
||||||
@media (max-width: 640px) {
|
@media (max-width: 640px) {
|
||||||
:global(.sheet-header) {
|
:global(.sheet-header) {
|
||||||
@@ -573,5 +608,9 @@
|
|||||||
.action-button {
|
.action-button {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.comments-section {
|
||||||
|
height: calc(80vh - 380px);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -288,7 +288,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if selectedFind}
|
{#if selectedFind}
|
||||||
<FindPreview find={selectedFind} onClose={closeFindPreview} />
|
<FindPreview find={selectedFind} onClose={closeFindPreview} currentUserId={data.user?.id} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
Reference in New Issue
Block a user