Skip to content

Commit adfc845

Browse files
committed
chore: stash progress
1 parent ea41253 commit adfc845

File tree

8 files changed

+126
-104
lines changed

8 files changed

+126
-104
lines changed

platforms/blabsy-w3ds-auth-api/src/controllers/WebhookController.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,13 @@ export class WebhookController {
155155

156156
private mapDataToFirebase(tableName: string, data: any): any {
157157
const now = Timestamp.now();
158+
console.log("MAPPING DATA TO ", tableName);
158159

159160
switch (tableName) {
160161
case "users":
161-
return this.mapUserData(data, now);
162+
const result = this.mapUserData(data, now);
163+
console.log("mappppped", result);
164+
return result;
162165
case "tweets":
163166
return this.mapTweetData(data, now);
164167
case "chats":
@@ -172,13 +175,12 @@ export class WebhookController {
172175

173176
private mapUserData(data: any, now: Timestamp): Partial<User> {
174177
return {
175-
id: data.id,
176178
bio: data.bio || null,
177179
name: data.name,
178180
theme: data.theme || null,
179181
accent: data.accent || null,
180-
website: data.website || null,
181-
location: data.location || null,
182+
website: null,
183+
location: null,
182184
username: data.username,
183185
photoURL: data.photoURL,
184186
verified: data.verified || false,

platforms/blabsy/.env.development

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Dev URL
22
# NEXT_PUBLIC_URL=http://localhost
3-
# NEXT_PUBLIC_BASE_URL=http://192.168.0.226:4444
3+
NEXT_PUBLIC_BASE_URL=http://192.168.0.226:4444
44

55
NEXT_PUBLIC_URL=https://blabsy.w3ds-prototype.merul.org
6-
NEXT_PUBLIC_BASE_URL=https://blabsy.w3ds-prototype.merul.org
6+
# NEXT_PUBLIC_BASE_URL=https://blabsy.w3ds-prototype.merul.org
77

88
# Emulator
99
NEXT_PUBLIC_USE_EMULATOR=false

platforms/blabsy/src/components/user/user-avatar.tsx

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,44 @@ import cn from 'clsx';
33
import { NextImage } from '@components/ui/next-image';
44

55
type UserAvatarProps = {
6-
src: string;
7-
alt: string;
8-
size?: number;
9-
username?: string;
10-
className?: string;
6+
src: string;
7+
alt: string;
8+
size?: number;
9+
username?: string;
10+
className?: string;
1111
};
1212

1313
export function UserAvatar({
14-
src,
15-
alt,
16-
size,
17-
username,
18-
className
14+
src,
15+
alt,
16+
size,
17+
username,
18+
className
1919
}: UserAvatarProps): JSX.Element {
20-
const pictureSize = size ?? 48;
20+
const pictureSize = size ?? 48;
2121

22-
return (
23-
<Link href={username ? `/user/${username}` : '#'}>
24-
<a
25-
className={cn(
26-
'blur-picture flex self-start',
27-
!username && 'pointer-events-none',
28-
className
29-
)}
30-
tabIndex={username ? 0 : -1}
31-
>
32-
<NextImage
33-
useSkeleton
34-
imgClassName='rounded-full'
35-
width={pictureSize}
36-
height={pictureSize}
37-
src={src}
38-
alt={alt}
39-
key={src}
40-
/>
41-
</a>
42-
</Link>
43-
);
22+
console.log(typeof src);
23+
24+
return (
25+
<Link href={username ? `/user/${username}` : '#'}>
26+
<a
27+
className={cn(
28+
'blur-picture flex self-start',
29+
!username && 'pointer-events-none',
30+
className
31+
)}
32+
tabIndex={username ? 0 : -1}
33+
>
34+
<NextImage
35+
useSkeleton
36+
imgClassName='rounded-full'
37+
width={pictureSize}
38+
height={pictureSize}
39+
src={src}
40+
alt={alt}
41+
key={src}
42+
/>
43+
</a>
44+
</Link>
45+
);
4446
}

platforms/pictique-api/src/controllers/UserController.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,12 @@ export class UserController {
8181
return res.status(401).json({ error: "Unauthorized" });
8282
}
8383

84+
const user = await this.userService.findById(userId);
85+
8486
const updatedUser = await this.userService.updateProfile(userId, {
85-
handle,
86-
avatarUrl: avatar,
87-
name
87+
handle: handle ?? user?.handle,
88+
avatarUrl: avatar ?? user?.avatarUrl,
89+
name: name ?? user?.name,
8890
});
8991

9092
res.json(updatedUser);

platforms/pictique/src/lib/stores/posts.ts

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@ import { apiClient } from '$lib/utils/axios';
33
import { goto } from '$app/navigation';
44

55
export interface Post {
6-
id: string;
7-
text: string;
8-
images: string[];
9-
author: {
10-
id: string;
11-
handle: string;
12-
name: string;
13-
avatarUrl: string;
14-
};
15-
createdAt: string;
16-
likedBy: string[];
17-
comments: {
18-
id: string;
19-
text: string;
20-
author: {
21-
id: string;
22-
handle: string;
23-
name: string;
24-
avatarUrl: string;
25-
};
26-
createdAt: string;
27-
}[];
6+
id: string;
7+
text: string;
8+
images: string[];
9+
author: {
10+
id: string;
11+
handle: string;
12+
name: string;
13+
avatarUrl: string;
14+
};
15+
createdAt: string;
16+
likedBy: string[];
17+
comments: {
18+
id: string;
19+
text: string;
20+
author: {
21+
id: string;
22+
handle: string;
23+
name: string;
24+
avatarUrl: string;
25+
};
26+
createdAt: string;
27+
}[];
2828
}
2929

3030
export const posts = writable<Post[]>([]);
@@ -35,42 +35,42 @@ export const isCreatePostModalOpen = writable(false);
3535
export const openCreatePostModal = () => isCreatePostModalOpen.set(true);
3636
export const closeCreatePostModal = () => isCreatePostModalOpen.set(false);
3737

38-
export const fetchFeed = async (page = 1, limit = 10) => {
39-
try {
40-
isLoading.set(true);
41-
error.set(null);
42-
const response = await apiClient.get(`/api/posts/feed?page=${page}&limit=${limit}`);
43-
posts.set(response.data);
44-
} catch (err) {
45-
error.set(err instanceof Error ? err.message : 'Failed to fetch feed');
46-
} finally {
47-
isLoading.set(false);
48-
}
38+
export const fetchFeed = async (page = 1, limit = 10_000) => {
39+
try {
40+
isLoading.set(true);
41+
error.set(null);
42+
const response = await apiClient.get(`/api/posts/feed?page=${page}&limit=${limit}`);
43+
posts.set(response.data);
44+
} catch (err) {
45+
error.set(err instanceof Error ? err.message : 'Failed to fetch feed');
46+
} finally {
47+
isLoading.set(false);
48+
}
4949
};
5050

5151
export const createPost = async (text: string, images: string[]) => {
52-
try {
53-
isLoading.set(true);
54-
error.set(null);
55-
const response = await apiClient.post('/api/posts', {
56-
text,
57-
images: images.map((img) => img)
58-
});
59-
await fetchFeed(1);
60-
return response.data;
61-
} catch (err) {
62-
error.set(err instanceof Error ? err.message : 'Failed to create post');
63-
throw err;
64-
} finally {
65-
isLoading.set(false);
66-
}
52+
try {
53+
isLoading.set(true);
54+
error.set(null);
55+
const response = await apiClient.post('/api/posts', {
56+
text,
57+
images: images.map((img) => img)
58+
});
59+
await fetchFeed(1);
60+
return response.data;
61+
} catch (err) {
62+
error.set(err instanceof Error ? err.message : 'Failed to create post');
63+
throw err;
64+
} finally {
65+
isLoading.set(false);
66+
}
6767
};
6868

6969
export const toggleLike = async (postId: string) => {
70-
try {
71-
const response = await apiClient.post(`/api/posts/${postId}/like`);
72-
return response.data;
73-
} catch (err) {
74-
throw new Error(err instanceof Error ? err.message : 'Failed to toggle like');
75-
}
70+
try {
71+
const response = await apiClient.post(`/api/posts/${postId}/like`);
72+
return response.data;
73+
} catch (err) {
74+
throw new Error(err instanceof Error ? err.message : 'Failed to toggle like');
75+
}
7676
};

platforms/pictique/src/lib/utils/axios.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ export const removeAuthToken = (): void => {
3333

3434
// Utility function to store auth id
3535
export const setAuthId = (id: string): void => {
36-
localStorage.setItem("ownerId", id);
36+
localStorage.setItem('ownerId', id);
3737
};
3838

3939
export const getAuthId = () => {
40-
return localStorage.getItem("ownerId");
40+
return localStorage.getItem('ownerId');
4141
};
4242

4343
// Utility function to remove auth token
4444
export const removeAuthId = (): void => {
45-
localStorage.removeItem("ownerId");
45+
localStorage.removeItem('ownerId');
4646
};

platforms/pictique/src/routes/(protected)/+layout.svelte

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
import { comments, fetchComments, createComment, activePostId } from '$lib/stores/comments';
77
import CreatePostModal from '$lib/fragments/CreatePostModal/CreatePostModal.svelte';
88
import { onMount } from 'svelte';
9-
import { apiClient, getAuthId } from '$lib/utils';
9+
import { apiClient, getAuthId, getAuthToken } from '$lib/utils';
1010
import type { userProfile } from '$lib/types';
1111
import { heading } from '../store';
12+
import { goto } from '$app/navigation';
13+
import type { AxiosError } from 'axios';
1214
1315
let { children } = $props();
1416
let ownerId: string | null = $state(null);
@@ -75,14 +77,22 @@
7577
7678
async function fetchProfile() {
7779
try {
78-
const response = await apiClient.get(`/api/users/${ownerId}`);
80+
if (!getAuthToken()) {
81+
goto('/auth');
82+
}
83+
const response = await apiClient.get(`/api/users/${ownerId}`).catch((e: AxiosError) => {
84+
if (e.response?.status === 401) {
85+
goto('/auth');
86+
}
87+
});
88+
if (!response) return;
7989
profile = response.data;
8090
} catch (err) {
8191
console.log(err instanceof Error ? err.message : 'Failed to load profile');
8292
}
8393
}
8494
85-
onMount(fetchProfile)
95+
onMount(fetchProfile);
8696
</script>
8797

8898
<main
@@ -165,7 +175,7 @@
165175
{/if}
166176

167177
{#if route !== `/messages/${idFromParams}`}
168-
<BottomNav class="btm-nav" profileSrc={profile?.avatarUrl ?? ""} />
178+
<BottomNav class="btm-nav" profileSrc={profile?.avatarUrl ?? ''} />
169179
{/if}
170180
</main>
171181

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
import { goto } from '$app/navigation';
33
import { Button } from '$lib/ui';
44
import { SettingsNavigationButton } from '$lib/fragments';
5+
import { removeAuthToken } from '$lib/utils';
6+
7+
async function handleLogout() {
8+
removeAuthToken();
9+
window.location.href = '/auth';
10+
}
511
</script>
612

713
<div class="flex flex-col gap-3">
@@ -17,5 +23,5 @@
1723
{/snippet}
1824
</SettingsNavigationButton>
1925
<hr class="text-grey" />
20-
<Button size="sm" variant="secondary" callback={() => alert('logout')}>Logout</Button>
26+
<Button size="sm" variant="secondary" callback={handleLogout}>Logout</Button>
2127
</div>

0 commit comments

Comments
 (0)