Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion platforms/metagram/src/lib/dummyData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ export const dummyPosts = Array.from({ length: 100 }, (_, i) => ({
id: i + 1,
avatar: 'https://www.gravatar.com/avatar/2c7d99fe281ecd3bcd65ab915bac6dd5?s=250',
username: `user${i + 1}`,
imgUri: 'https://picsum.photos/800',
imgUri: [
'https://picsum.photos/800',
'https://picsum.photos/200',
'https://picsum.photos/800',
'https://picsum.photos/200'
],
postAlt: 'Sample',
text: `This is post number ${i + 1}. Loving how these shots came out! 📸`,
time: `${i + 1} hours ago`,
Expand Down
5 changes: 4 additions & 1 deletion platforms/metagram/src/lib/fragments/Post/Post.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export const Primary = {
args: {
avatar: 'https://www.gravatar.com/avatar/2c7d99fe281ecd3bcd65ab915bac6dd5?s=250',
username: 'blurryface',
imgUri: 'https://graphicsfamily.com/wp-content/uploads/edd/2023/01/Free-Photographer-Social-Media-Post-Design-Template-870x870.jpg',
imgUri: [
'https://graphicsfamily.com/wp-content/uploads/edd/2023/01/Free-Photographer-Social-Media-Post-Design-Template-870x870.jpg',
'https://picsum.photos/200'
],
postAlt: 'Sample',
text: 'Took some pictures today! Really love how this one in particular turned out! ',
time: '2 hours ago',
Expand Down
51 changes: 44 additions & 7 deletions platforms/metagram/src/lib/fragments/Post/Post.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import { Avatar } from '$lib/ui';
import { cn } from '$lib/utils';
import {
ArrowLeftIcon,
ArrowRightIcon,
Message02Icon,
MoreVerticalIcon,
RecordIcon,
Expand All @@ -13,7 +15,7 @@
interface IPostProps extends HTMLAttributes<HTMLElement> {
avatar: string;
username: string;
imgUri: string;
imgUri: string[];
postAlt?: string;
text: string;
count: {
Expand All @@ -39,6 +41,16 @@
time,
...restProps
}: IPostProps = $props();

let galleryRef: HTMLDivElement;

function scrollLeft() {
galleryRef.scrollBy({ left: -galleryRef.clientWidth, behavior: 'smooth' });
}

function scrollRight() {
galleryRef.scrollBy({ left: galleryRef.clientWidth, behavior: 'smooth' });
}
</script>

<article {...restProps} class={cn(['flex w-full flex-col gap-4', restProps.class])}>
Expand All @@ -52,12 +64,37 @@
<HugeiconsIcon icon={MoreVerticalIcon} size={24} color="var(--color-black-500)" />
</button>
</div>
<div class="overflow-hidden rounded-4xl">
<img
src={imgUri}
alt={postAlt ?? text}
class="aspect-[4/5] h-full w-full object-cover md:aspect-[16/9]"
/>
<div class="relative">
{#if imgUri.length !== 1}
<button
onclick={scrollLeft}
class="absolute hidden md:inline-block start-2 top-1/2 z-10 -translate-y-1/2 rounded-full bg-white p-2 shadow hover:bg-gray-200"
>
<HugeiconsIcon icon={ArrowLeftIcon} size={20} color="black" />
</button>
{/if}
<div
bind:this={galleryRef}
class="hide-scrollbar flex aspect-[4/5] snap-x snap-mandatory flex-nowrap gap-2 overflow-hidden overflow-x-scroll rounded-4xl md:aspect-[16/9]"
>
{#each imgUri as img}
<div class="aspect-[4/5] h-full w-full snap-center md:aspect-[16/9]">
<img
src={img}
alt={postAlt ?? text}
class=" h-full w-full rounded-4xl object-cover"
/>
</div>
{/each}
</div>
{#if imgUri.length !== 1}
<button
onclick={scrollRight}
class="absolute hidden md:inline-block end-2 top-1/2 z-10 -translate-y-1/2 rounded-full bg-white p-2 shadow hover:bg-gray-200"
>
<HugeiconsIcon icon={ArrowRightIcon} size={20} color="black" />
</button>
{/if}
</div>
<p class="text-black/80">{text}</p>
<p class="text-black/60">{time}</p>
Expand Down
2 changes: 1 addition & 1 deletion platforms/metagram/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type PostData = {
id: number;
avatar: string;
username: string;
imgUri: string;
imgUri: string[];
postAlt: string;
text: string;
time: string;
Expand Down
Loading