|
5 | 5 | import { openCreatePostModal, isCreatePostModalOpen } from '$lib/stores/posts';
|
6 | 6 | import { comments, fetchComments, createComment, activePostId } from '$lib/stores/comments';
|
7 | 7 | import CreatePostModal from '$lib/fragments/CreatePostModal/CreatePostModal.svelte';
|
| 8 | + import { onMount } from 'svelte'; |
| 9 | + import { apiClient, getAuthId } from '$lib/utils'; |
| 10 | + import type { userProfile } from '$lib/types'; |
8 | 11 | import { heading } from '../store';
|
9 | 12 |
|
10 | 13 | let { children } = $props();
|
11 |
| -
|
| 14 | + let ownerId: string | null = $state(null); |
12 | 15 | let route = $derived(page.url.pathname);
|
13 | 16 |
|
14 | 17 | let commentValue: string = $state('');
|
|
17 | 20 | let idFromParams = $state();
|
18 | 21 | let isCommentsLoading = $state(false);
|
19 | 22 | let commentsError = $state<string | null>(null);
|
| 23 | + let profile = $state<userProfile | null>(null); |
20 | 24 |
|
21 | 25 | const handleSend = async () => {
|
22 | 26 | console.log($activePostId, commentValue);
|
|
55 | 59 |
|
56 | 60 | // Watch for changes in showComments to fetch comments when opened
|
57 | 61 | $effect(() => {
|
| 62 | + ownerId = getAuthId(); |
58 | 63 | if (showComments.value && activePostId) {
|
59 | 64 | isCommentsLoading = true;
|
60 | 65 | commentsError = null;
|
|
67 | 72 | });
|
68 | 73 | }
|
69 | 74 | });
|
| 75 | +
|
| 76 | + async function fetchProfile() { |
| 77 | + try { |
| 78 | + const response = await apiClient.get(`/api/users/${ownerId}`); |
| 79 | + profile = response.data; |
| 80 | + } catch (err) { |
| 81 | + console.log(err instanceof Error ? err.message : 'Failed to load profile'); |
| 82 | + } |
| 83 | + } |
| 84 | +
|
| 85 | + onMount(fetchProfile) |
70 | 86 | </script>
|
71 | 87 |
|
72 | 88 | <main
|
73 |
| - class={`block h-[100dvh] ${route !== '/home' && route !== '/messages' && route !== '/profile' && route !== '/settings' && !route.includes('/profile') ? 'grid-cols-[20vw_auto]' : 'grid-cols-[20vw_auto_30vw]'} md:grid`} |
| 89 | + class={`block h-[100dvh] ${route !== '/home' && route !== '/messages' && route !== '/profile' && !route.includes('settings') && !route.includes('/profile') ? 'grid-cols-[20vw_auto]' : 'grid-cols-[20vw_auto_30vw]'} md:grid`} |
74 | 90 | >
|
75 | 91 | <SideBar
|
76 |
| - profileSrc="https://picsum.photos/200" |
| 92 | + profileSrc={profile?.avatarUrl} |
77 | 93 | handlePost={async () => {
|
78 | 94 | openCreatePostModal();
|
79 | 95 | }}
|
|
149 | 165 | {/if}
|
150 | 166 |
|
151 | 167 | {#if route !== `/messages/${idFromParams}`}
|
152 |
| - <BottomNav class="btm-nav" profileSrc="https://picsum.photos/200" /> |
| 168 | + <BottomNav class="btm-nav" profileSrc={profile?.avatarUrl ?? ""} /> |
153 | 169 | {/if}
|
154 | 170 | </main>
|
155 | 171 |
|
|
0 commit comments