Skip to content

Commit a58a257

Browse files
committed
fix: pictique types
1 parent cf22525 commit a58a257

File tree

5 files changed

+130
-121
lines changed

5 files changed

+130
-121
lines changed
Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { Post } from '$lib/types';
2-
import { apiClient } from '$lib/utils/axios';
3-
import { writable } from 'svelte/store';
1+
import type { Post } from "$lib/types";
2+
import { apiClient } from "$lib/utils/axios";
3+
import { writable } from "svelte/store";
44

55
export const posts = writable<Post[]>([]);
66
export const isLoading = writable(false);
@@ -11,41 +11,45 @@ export const openCreatePostModal = () => isCreatePostModalOpen.set(true);
1111
export const closeCreatePostModal = () => isCreatePostModalOpen.set(false);
1212

1313
export const fetchFeed = async (page = 1, limit = 10_000) => {
14-
try {
15-
isLoading.set(true);
16-
error.set(null);
17-
const response = await apiClient.get(`/api/posts/feed?page=${page}&limit=${limit}`);
18-
posts.set(response.data);
19-
} catch (err) {
20-
error.set(err instanceof Error ? err.message : 'Failed to fetch feed');
21-
} finally {
22-
isLoading.set(false);
23-
}
14+
try {
15+
isLoading.set(true);
16+
error.set(null);
17+
const response = await apiClient.get(
18+
`/api/posts/feed?page=${page}&limit=${limit}`,
19+
);
20+
posts.set(response.data.posts);
21+
} catch (err) {
22+
error.set(err instanceof Error ? err.message : "Failed to fetch feed");
23+
} finally {
24+
isLoading.set(false);
25+
}
2426
};
2527

2628
export const createPost = async (text: string, images: string[]) => {
27-
try {
28-
isLoading.set(true);
29-
error.set(null);
30-
const response = await apiClient.post('/api/posts', {
31-
text,
32-
images: images.map((img) => img)
33-
});
34-
await fetchFeed(1);
35-
return response.data;
36-
} catch (err) {
37-
error.set(err instanceof Error ? err.message : 'Failed to create post');
38-
throw err;
39-
} finally {
40-
isLoading.set(false);
41-
}
29+
try {
30+
isLoading.set(true);
31+
error.set(null);
32+
const response = await apiClient.post("/api/posts", {
33+
text,
34+
images: images.map((img) => img),
35+
});
36+
await fetchFeed(1);
37+
return response.data;
38+
} catch (err) {
39+
error.set(err instanceof Error ? err.message : "Failed to create post");
40+
throw err;
41+
} finally {
42+
isLoading.set(false);
43+
}
4244
};
4345

4446
export const toggleLike = async (postId: string) => {
45-
try {
46-
const response = await apiClient.post(`/api/posts/${postId}/like`);
47-
return response.data;
48-
} catch (err) {
49-
throw new Error(err instanceof Error ? err.message : 'Failed to toggle like');
50-
}
47+
try {
48+
const response = await apiClient.post(`/api/posts/${postId}/like`);
49+
return response.data;
50+
} catch (err) {
51+
throw new Error(
52+
err instanceof Error ? err.message : "Failed to toggle like",
53+
);
54+
}
5155
};
Lines changed: 84 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,111 @@
1-
import type { SVGAttributes } from 'svelte/elements';
1+
import type { SVGAttributes } from "svelte/elements";
22

33
export interface ISvgProps extends SVGAttributes<SVGElement> {
4-
size?: number | string;
5-
color?: string;
4+
size?: number | string;
5+
color?: string;
66
}
77

88
export type CommentType = {
9-
commentId: string;
10-
name: string;
11-
userImgSrc: string;
12-
comment: string;
13-
isUpVoted: boolean;
14-
isDownVoted: boolean;
15-
upVotes: number;
16-
time: string;
17-
replies: CommentType[];
9+
commentId: string;
10+
name: string;
11+
userImgSrc: string;
12+
comment: string;
13+
isUpVoted: boolean;
14+
isDownVoted: boolean;
15+
upVotes: number;
16+
time: string;
17+
replies: CommentType[];
1818
};
1919

2020
export type PostData = {
21-
createdAt: string | number | Date;
22-
id: string;
23-
avatar: string;
24-
userId: string;
25-
username: string;
26-
imgUris: string[];
27-
caption: string;
28-
time: string;
29-
count: {
30-
likes: number;
31-
comments: number;
32-
};
21+
createdAt: string | number | Date;
22+
id: string;
23+
avatar: string;
24+
userId: string;
25+
username: string;
26+
imgUris: string[];
27+
caption: string;
28+
time: string;
29+
count: {
30+
likes: number;
31+
comments: number;
32+
};
3333
};
3434

3535
export interface Post {
36-
id: string;
37-
text: string;
38-
images: string[];
39-
author: {
40-
id: string;
41-
handle: string;
42-
name: string;
43-
avatarUrl: string;
44-
};
45-
createdAt: string;
46-
likedBy: userProfile[];
47-
comments: {
48-
id: string;
49-
text: string;
50-
author: {
51-
id: string;
52-
handle: string;
53-
name: string;
54-
avatarUrl: string;
55-
};
56-
createdAt: string;
57-
}[];
36+
id: string;
37+
text: string;
38+
images: string[];
39+
author: {
40+
id: string;
41+
handle: string;
42+
name: string;
43+
avatarUrl: string;
44+
};
45+
createdAt: string;
46+
likedBy: userProfile[];
47+
comments: {
48+
id: string;
49+
text: string;
50+
author: {
51+
id: string;
52+
handle: string;
53+
name: string;
54+
avatarUrl: string;
55+
};
56+
createdAt: string;
57+
}[];
5858
}
5959

6060
export type userProfile = {
61-
id: string;
62-
handle: string;
63-
name: string;
64-
description: string;
65-
avatarUrl: string;
66-
totalPosts: number;
67-
followers: number;
68-
following: number;
69-
posts: PostData[];
61+
id: string;
62+
handle: string;
63+
name: string;
64+
description: string;
65+
avatarUrl: string;
66+
totalPosts: number;
67+
followers: number;
68+
following: number;
69+
posts: PostData[];
70+
username: string;
7071
};
7172

7273
export type Image = {
73-
url: string;
74-
alt: string;
74+
url: string;
75+
alt: string;
7576
};
7677

7778
export type GroupInfo = {
78-
id: string;
79-
name: string;
80-
avatar: string;
79+
id: string;
80+
name: string;
81+
avatar: string;
8182
};
8283

8384
export type Chat = {
84-
id: string;
85-
avatar: string;
86-
handle: string;
87-
unread: boolean;
88-
text: string;
89-
participants: {
90-
id: string;
91-
name?: string;
92-
handle?: string;
93-
ename?: string;
94-
avatarUrl: string;
95-
}[];
96-
latestMessage: {
97-
text: string;
98-
isRead: boolean;
99-
};
85+
id: string;
86+
avatar: string;
87+
handle: string;
88+
unread: boolean;
89+
text: string;
90+
participants: {
91+
id: string;
92+
name?: string;
93+
handle?: string;
94+
ename?: string;
95+
avatarUrl: string;
96+
}[];
97+
latestMessage: {
98+
text: string;
99+
isRead: boolean;
100+
};
100101
};
101102

102103
export type MessageType = {
103-
id: string;
104-
avatar: string;
105-
handle: string;
106-
unread: boolean;
107-
text: string;
104+
id: string;
105+
avatar: string;
106+
handle: string;
107+
unread: boolean;
108+
text: string;
109+
name: string;
110+
username: string;
108111
};

platforms/pictique/src/lib/ui/Avatar/Avatar.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
{:else}
5656
<img
5757
{...restProps}
58-
on:error={handleError}
58+
onerror={handleError}
5959
src={img}
6060
{alt}
6161
class={cn([classes.common, classes.size, restProps.class].join(' '))}

platforms/pictique/src/routes/(protected)/home/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
{:else if $error}
9696
<li class="my-4 text-center text-red-500">{$error}</li>
9797
{:else}
98-
{#each $posts.posts as post (post.id)}
98+
{#each $posts as post (post.id)}
9999
<li class="mb-6">
100100
<Post
101101
avatar={post.author.avatarUrl}

platforms/pictique/src/routes/(protected)/messages/+page.svelte

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@
3434
return {
3535
id: c.id,
3636
avatar,
37-
username: c.name ?? memberNames.join(', '),
37+
username: c.handle ?? memberNames.join(', '),
3838
unread: c.latestMessage ? c.latestMessage.isRead : false,
39-
text: c.latestMessage?.text ?? 'No message yet'
39+
text: c.latestMessage?.text ?? 'No message yet',
40+
handle: c.handle ?? memberNames.join(', '),
41+
name: c.handle ?? memberNames.join(', ')
4042
};
4143
});
4244
}
@@ -126,7 +128,7 @@
126128
{/if}
127129

128130
{#if groups.length > 0}
129-
<h3 class="text-md mt-6 mb-2 font-semibold text-gray-700">Groups</h3>
131+
<h3 class="text-md mb-2 mt-6 font-semibold text-gray-700">Groups</h3>
130132
{#each groups as group}
131133
<Group
132134
name={group.name || 'New Group'}
@@ -173,7 +175,7 @@
173175
class="accent-brand focus:ring"
174176
/>
175177
<Avatar src={member.avatarUrl} size="sm" />
176-
<span class="text-sm">{member.name ?? member.handle ?? member.ename}</span>
178+
<span class="text-sm">{member.name ?? member.handle}</span>
177179
</label>
178180
{/each}
179181
</div>

0 commit comments

Comments
 (0)