Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
47 changes: 45 additions & 2 deletions platforms/pictique/src/lib/fragments/Profile/Profile.svelte
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
<script lang="ts">
import type { PostData, userProfile } from '$lib/types';
import { Button } from '$lib/ui';
import { HugeiconsIcon } from '@hugeicons/svelte';
import Post from '../Post/Post.svelte';
import { Spring } from 'svelte/motion';
import { Tick01Icon } from '@hugeicons/core-free-icons';

let {
variant = 'user',
profileData,
handleFollow,
handleSinglePost,
handleMessage
handleMessage,
isFollowing = $bindable(false)
}: {
variant: 'user' | 'other';
profileData: userProfile;
handleSinglePost: (post: PostData) => void;
handleFollow: () => Promise<void>;
handleMessage: () => Promise<void>;
isFollowing: boolean;
} = $props();

let imgPosts = $derived(profileData.posts.filter((e) => e.imgUris && e.imgUris.length > 0));
let requestSent = $state(false);

const btnScale = new Spring(1, { stiffness: 0.2, damping: 0.4 });

async function wrappedFollow() {
btnScale.target = 0.95;

await handleFollow();
requestSent = true;

btnScale.target = 1;
}
</script>

<div class="flex flex-col gap-4 p-4">
Expand All @@ -36,7 +53,33 @@
</div>
{#if variant === 'other'}
<div class="flex gap-2">
<Button variant="primary" size="sm" callback={handleFollow}>Follow</Button>
<div style="transform: scale({btnScale.current}); transition: transform 0.2s ease;">
<Button
variant={'primary'}
size="sm"
callback={wrappedFollow}
disabled={isFollowing || requestSent}
class="min-w-[110px] transition-all duration-500 {requestSent
? 'opacity-80'
: ''}"
>
<div class="flex items-center justify-center gap-2">
{#if requestSent}
<HugeiconsIcon icon={Tick01Icon} size={16} />
<span>Followed</span>
{:else if isFollowing}
<span class="flex gap-0.5">
<span class="animate-bounce">.</span>
<span class="animate-bounce [animation-delay:0.2s]">.</span>
<span class="animate-bounce [animation-delay:0.4s]">.</span>
</span>
<span>Following</span>
{:else}
Follow
{/if}
</div>
</Button>
</div>
<Button variant="primary" size="sm" callback={handleMessage}>Message</Button>
</div>
{/if}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
let error = $state<string | null>(null);
let loading = $state(true);
let ownerId: string | null = $derived(getAuthId());
let isFollowing = $state(false);
let ownerProfile = $derived.by(async () => {
if (ownerId) {
const response = await apiClient.get<userProfile>(`/api/users/${ownerId}`);
Expand All @@ -50,10 +51,13 @@

async function handleFollow() {
try {
isFollowing = true;
await apiClient.post(`/api/users/${profileId}/follow`);
await fetchProfile(); // Refresh profile to update follower count
// await fetchProfile(); // Refresh profile to update follower count
} catch (err) {
error = err instanceof Error ? err.message : 'Failed to follow user';
} finally {
isFollowing = false;
}
}

Expand Down Expand Up @@ -94,6 +98,7 @@
</div>
{:else if profile}
<Profile
bind:isFollowing
variant={ownerId === profileId ? 'user' : 'other'}
profileData={profile}
handleSinglePost={(post) => handlePostClick(post)}
Expand Down