diff --git a/platforms/metagram/src/lib/dummyData.ts b/platforms/metagram/src/lib/dummyData.ts index d27ff35a..653f42ea 100644 --- a/platforms/metagram/src/lib/dummyData.ts +++ b/platforms/metagram/src/lib/dummyData.ts @@ -1,3 +1,5 @@ +import type { CommentType } from './types'; + export const dummyPosts = Array.from({ length: 100 }, (_, i) => ({ id: i + 1, avatar: 'https://www.gravatar.com/avatar/2c7d99fe281ecd3bcd65ab915bac6dd5?s=250', @@ -9,10 +11,74 @@ export const dummyPosts = Array.from({ length: 100 }, (_, i) => ({ count: { likes: Math.floor(Math.random() * 500), comments: Math.floor(Math.random() * 200) - }, - callback: { - like: () => alert(`Like clicked on post ${i + 1}`), - comment: () => alert(`Comment clicked on post ${i + 1}`), - menu: () => alert(`Menu clicked on post ${i + 1}`) } })); + +export const comments: CommentType[] = Array.from({ length: 50 }, (_, i) => ({ + userImgSrc: 'https://picsum.photos/800', + name: `user${i + 1}`, + commentId: `${i + 1}p`, + comment: `this is the dummy comment which is commented by user${i + 1}`, + isUpVoted: false, + isDownVoted: false, + upVotes: 0, + time: '2 minutes ago', + replies: [ + { + userImgSrc: 'https://picsum.photos/800', + name: `user${i + 1}x`, + commentId: `${i + 1}x`, + comment: `this is the dummy reply which is replied by another${i}x`, + isUpVoted: false, + isDownVoted: false, + upVotes: 0, + time: '1 minute ago', + replies: [ + { + userImgSrc: 'https://picsum.photos/800', + name: `user${i + 1}a`, + commentId: `${i + 1}a`, + comment: `this is the dummy reply which is replied by another${i}a`, + isUpVoted: false, + isDownVoted: false, + upVotes: 0, + time: '1 minute ago', + replies: [] + } + ] + }, + { + userImgSrc: 'https://picsum.photos/800', + name: `user${i + 1}y`, + commentId: `${i + 1}y`, + comment: `this is the dummy reply which is replied by another${i}y`, + isUpVoted: false, + isDownVoted: false, + upVotes: 0, + time: '1 minute ago', + replies: [] + }, + { + userImgSrc: 'https://picsum.photos/800', + name: `user${i + 1}y`, + commentId: `${i + 1}y`, + comment: `this is the dummy reply which is replied by another${i}y`, + isUpVoted: false, + isDownVoted: false, + upVotes: 0, + time: '1 minute ago', + replies: [] + }, + { + userImgSrc: 'https://picsum.photos/800', + name: `user${i + 1}y`, + commentId: `${i + 1}y`, + comment: `this is the dummy reply which is replied by another${i}y`, + isUpVoted: false, + isDownVoted: false, + upVotes: 0, + time: '1 minute ago', + replies: [] + } + ] +})); diff --git a/platforms/metagram/src/lib/fragments/Comment/Comment.stories.ts b/platforms/metagram/src/lib/fragments/Comment/Comment.stories.ts new file mode 100644 index 00000000..cca0ea3d --- /dev/null +++ b/platforms/metagram/src/lib/fragments/Comment/Comment.stories.ts @@ -0,0 +1,19 @@ +import type { ComponentProps } from 'svelte'; +import { Comment } from '..'; +import { comments } from '$lib/dummyData'; + +export default { + title: 'UI/Comment', + component: Comment, + tags: ['autodocs'], + render: (args: { Component: Comment; props: ComponentProps }) => ({ + Component: Comment, + props: args + }) +}; + +export const Main = { + args: { + comment: comments[0] + } +}; diff --git a/platforms/metagram/src/lib/fragments/Comment/Comment.svelte b/platforms/metagram/src/lib/fragments/Comment/Comment.svelte new file mode 100644 index 00000000..86a5a068 --- /dev/null +++ b/platforms/metagram/src/lib/fragments/Comment/Comment.svelte @@ -0,0 +1,147 @@ + + +
+
+ +
+

{comment.name}

+

{comment.comment}

+
+
+
+ +

{comment.upVotes}

+ + + + +

{comment.time}

+
+ {#if comment?.replies?.length} + + {/if} +
diff --git a/platforms/metagram/src/lib/fragments/Drawer/Drawer.svelte b/platforms/metagram/src/lib/fragments/Drawer/Drawer.svelte index e58cce3f..e01b1ad4 100644 --- a/platforms/metagram/src/lib/fragments/Drawer/Drawer.svelte +++ b/platforms/metagram/src/lib/fragments/Drawer/Drawer.svelte @@ -7,20 +7,13 @@ import type { SwipeCustomEvent } from 'svelte-gestures'; interface IDrawerProps extends HTMLAttributes { - isPaneOpen?: boolean; + drawer?: CupertinoPane; children?: Snippet; - handleSwipe?: (isOpen: boolean | undefined) => void; } - let { - isPaneOpen = $bindable(), - children = undefined, - handleSwipe, - ...restProps - }: IDrawerProps = $props(); + let { drawer = $bindable(), children = undefined, ...restProps }: IDrawerProps = $props(); let drawerElement: HTMLElement; - let drawer: CupertinoPane; function dismiss() { if (drawer) drawer.destroy({ animate: true }); @@ -28,9 +21,7 @@ const handleDrawerSwipe = (event: SwipeCustomEvent) => { if (event.detail.direction === ('down' as string)) { - handleSwipe?.(false); drawer?.destroy({ animate: true }); - isPaneOpen = false; } }; @@ -51,13 +42,6 @@ onBackdropTap: () => dismiss() } }); - if (isPaneOpen) { - drawer.present({ animate: true }); - } else { - drawer.destroy({ animate: true }); - } - - drawer.present(); }); @@ -71,7 +55,9 @@ onswipe={handleDrawerSwipe} class={cn(restProps.class)} > - {@render children?.()} +
+ {@render children?.()} +