Skip to content

Commit 6f5f9cb

Browse files
grv-saini-20coodos
andauthored
fix: avatars (#226)
* fix: avatars * fix: avatar in follow request page * fix: images uploaded shown in user profile * fix: button size * fix: avatar --------- Co-authored-by: Merul Dhiman <[email protected]>
1 parent 236af86 commit 6f5f9cb

File tree

14 files changed

+217
-179
lines changed

14 files changed

+217
-179
lines changed

platforms/pictique/src/lib/fragments/BottomNav/BottomNav.svelte

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import { goto } from '$app/navigation';
33
import { page } from '$app/state';
44
import { Camera, CommentsTwo, Home, Search } from '$lib/icons';
5-
import { isNavigatingThroughNav } from '$lib/store/store.svelte';
6-
import { uploadedImages } from '$lib/store/store.svelte';
5+
import { isNavigatingThroughNav, ownerId } from '$lib/store/store.svelte';
6+
import { uploadedImages } from '$lib/store/store.svelte';
77
import { getAuthId, revokeImageUrls } from '$lib/utils';
88
import type { HTMLAttributes } from 'svelte/elements';
99
@@ -25,7 +25,7 @@
2525
let fullPath = $derived(page.url.pathname);
2626
2727
let imageInput: HTMLInputElement;
28-
let images: FileList | null = $state(null);
28+
let images: FileList | null = $state(null);
2929
3030
const handleNavClick = (newTab: string) => {
3131
// activeTab = newTab;
@@ -37,9 +37,9 @@
3737
previousTab = newTab;
3838
if (newTab === 'profile') {
3939
goto(`/profile/${ownerId}`);
40-
} else if (newTab === "post") {
41-
uploadedImages.value = null;
42-
imageInput.value = "";
40+
} else if (newTab === 'post') {
41+
uploadedImages.value = null;
42+
imageInput.value = '';
4343
imageInput.click();
4444
} else {
4545
goto(`/${newTab}`);
@@ -49,22 +49,34 @@
4949
$effect(() => {
5050
ownerId = getAuthId()
5151
activeTab = _activeTab.split('/').pop() ?? '';
52-
if (images && images.length > 0 && activeTab !== 'post' && previousTab === 'post' && !_activeTab.includes('post/audience')) {
53-
if (uploadedImages.value)
54-
revokeImageUrls(uploadedImages.value);
55-
uploadedImages.value = Array.from(images).map(file => ({
56-
url: URL.createObjectURL(file),
57-
alt: file.name
58-
}));
52+
if (
53+
images &&
54+
images.length > 0 &&
55+
activeTab !== 'post' &&
56+
previousTab === 'post' &&
57+
!_activeTab.includes('post/audience')
58+
) {
59+
if (uploadedImages.value) revokeImageUrls(uploadedImages.value);
60+
uploadedImages.value = Array.from(images).map((file) => ({
61+
url: URL.createObjectURL(file),
62+
alt: file.name
63+
}));
5964
images = null; // To prevent re-triggering the effect and thus making an infinite loop with /post route's effect when the length of uploadedImages goes to 0
60-
if (uploadedImages.value.length > 0) {
61-
goto("/post");
62-
}
65+
if (uploadedImages.value.length > 0) {
66+
goto('/post');
67+
}
6368
}
6469
});
6570
</script>
6671

67-
<input type="file" accept="image/*" multiple bind:files={images} bind:this={imageInput} class="hidden" />
72+
<input
73+
type="file"
74+
accept="image/*"
75+
multiple
76+
bind:files={images}
77+
bind:this={imageInput}
78+
class="hidden"
79+
/>
6880
<!-- svelte-ignore a11y_no_noninteractive_element_to_interactive_role -->
6981
<nav
7082
aria-label="Main navigation"

platforms/pictique/src/lib/fragments/CreatePostModal/CreatePostModal.svelte

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@
5151
<button
5252
type="button"
5353
class="rounded-full p-2 hover:bg-gray-100"
54-
on:click={closeCreatePostModal}
54+
onclick={closeCreatePostModal}
5555
>
5656
5757
</button>
5858
</div>
5959

6060
<div class="mb-4">
61+
<!-- svelte-ignore element_invalid_self_closing_tag -->
6162
<textarea
6263
bind:value={text}
6364
placeholder="What's on your mind?"
@@ -70,6 +71,7 @@
7071
<div class="mb-4 grid grid-cols-2 gap-4">
7172
{#each images as image, index}
7273
<div class="relative">
74+
<!-- svelte-ignore a11y_img_redundant_alt -->
7375
<img
7476
src={image}
7577
alt="Post image"
@@ -78,7 +80,7 @@
7880
<button
7981
type="button"
8082
class="absolute top-2 right-2 rounded-full bg-black/50 p-1 text-white hover:bg-black/70"
81-
on:click={() => removeImage(index)}
83+
onclick={() => removeImage(index)}
8284
>
8385
8486
</button>
@@ -87,14 +89,17 @@
8789
</div>
8890
{/if}
8991

90-
<div class="flex items-center justify-between">
91-
<label class="cursor-pointer rounded-lg bg-gray-100 px-4 py-2 hover:bg-gray-200">
92-
<input type="file" accept="image/*" class="hidden" on:change={handleImageUpload} />
92+
<div class="flex items-center justify-between gap-2">
93+
<label
94+
class="w-full cursor-pointer rounded-full bg-gray-100 px-4 py-3 text-center hover:bg-gray-200"
95+
>
96+
<input type="file" accept="image/*" class="hidden" onchange={handleImageUpload} />
9397
Add Photo
9498
</label>
9599

96100
<Button
97101
variant="secondary"
102+
size="sm"
98103
callback={handleSubmit}
99104
isLoading={isSubmitting}
100105
disabled={!text.trim() && images.length === 0}

platforms/pictique/src/lib/fragments/InputFile/InputFile.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
<label
2828
for={uniqueId}
29-
class="bg-grey text-black-400 font-geist rounded-4xl flex h-[158px] w-full items-center justify-center text-base font-normal"
29+
class="bg-grey text-black-400 font-geist flex h-[158px] w-full items-center justify-center rounded-4xl text-base font-normal"
3030
>
3131
{#if files}
3232
<div class="flex flex-col items-center gap-2">

platforms/pictique/src/lib/fragments/MessageInput/MessageInput.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<!-- svelte-ignore a11y_click_events_have_key_events -->
5353
<!-- svelte-ignore a11y_no_static_element_interactions -->
5454
<div
55-
class="bg-grey h-13 w-13 flex aspect-square items-center justify-center rounded-full"
55+
class="bg-grey flex aspect-square h-13 w-13 items-center justify-center rounded-full"
5656
onclick={handleSend}
5757
>
5858
<HugeiconsIcon size="24px" icon={SentIcon} color="var(--color-black-400)" />

platforms/pictique/src/lib/fragments/Post/Post.svelte

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
interface IPostProps extends HTMLAttributes<HTMLElement> {
1717
avatar: string;
1818
username: string;
19-
userId: string;
19+
userId?: string;
2020
imgUris: string[];
21-
caption: string;
22-
count: {
21+
text: string;
22+
count?: {
2323
likes: number;
2424
comments: number;
2525
};
@@ -58,6 +58,7 @@
5858
5959
const {
6060
avatar,
61+
userId,
6162
username,
6263
imgUris: uris,
6364
text,
@@ -67,9 +68,8 @@
6768
...restProps
6869
}: IPostProps = $props();
6970
70-
let imgUris = $derived.by(() => pairAndJoinChunks(uris));
71-
72-
let galleryRef: HTMLDivElement;
71+
let imgUris = $derived(uris);
72+
let galleryRef: HTMLDivElement | undefined = $state();
7373
let currentIndex = $state(0);
7474
7575
function scrollLeft() {

platforms/pictique/src/lib/fragments/Profile/Profile.svelte

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@
33
import type { userProfile, PostData } from '$lib/types';
44
import Post from '../Post/Post.svelte';
55
6-
export let variant: 'user' | 'other' = 'user';
7-
export let profileData: userProfile;
8-
export let handleSinglePost: (post: PostData) => void;
9-
export let handleFollow: () => Promise<void>;
10-
export let handleMessage: () => Promise<void>;
6+
let {
7+
variant = 'user',
8+
profileData,
9+
handleSinglePost,
10+
handleFollow,
11+
handleMessage
12+
}: {
13+
variant: 'user' | 'other';
14+
profileData: userProfile;
15+
handleSinglePost: (post: PostData) => void;
16+
handleFollow: () => Promise<void>;
17+
handleMessage: () => Promise<void>;
18+
} = $props();
1119
</script>
1220

1321
<div class="flex flex-col gap-4 p-4">
@@ -23,8 +31,8 @@
2331
</div>
2432
{#if variant === 'other'}
2533
<div class="flex gap-2">
26-
<Button variant="primary" callback={handleFollow}>Follow</Button>
27-
<Button variant="primary" callback={handleMessage}>Message</Button>
34+
<Button variant="primary" size="sm" callback={handleFollow}>Follow</Button>
35+
<Button variant="primary" size="sm" callback={handleMessage}>Message</Button>
2836
</div>
2937
{/if}
3038
</div>
@@ -46,13 +54,13 @@
4654

4755
<div class="grid grid-cols-3 gap-1">
4856
{#each profileData.posts.filter((e) => e.imgUris && e.imgUris.length > 0) as post}
49-
<li class="mb-6">
57+
<li class="mb-6 list-none">
5058
<Post
51-
avatar={'https://picsum.photos/200/200'}
59+
avatar={profileData.avatarUrl || 'https://picsum.photos/200/200'}
5260
username={profileData?.username}
5361
imgUris={post.imgUris ?? []}
54-
text={post.text}
55-
time={new Date(post.createdAt).toLocaleDateString()}
62+
text={post.caption}
63+
time={post.time ? new Date(post.time).toLocaleDateString() : ''}
5664
callback={{
5765
like: async () => {
5866
try {

platforms/pictique/src/lib/fragments/UploadedPostView/UploadedPostView.svelte

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<script lang="ts">
22
import { Cross } from '$lib/icons';
3-
import type { Image } from '$lib/types';
3+
import type { Image } from '$lib/types';
44
import { cn } from '$lib/utils';
55
import type { HTMLAttributes } from 'svelte/elements';
66
7-
87
interface IUploadedPostViewProps extends HTMLAttributes<HTMLElement> {
98
images: Image[];
109
width?: string;
@@ -23,12 +22,17 @@
2322

2423
<article
2524
{...restProps}
26-
class={cn(['pl-0.5 pr-4 max-w-screen flex flex-row items-center gap-4 overflow-x-auto min-h-max', restProps.class].join(' '))}
25+
class={cn(
26+
[
27+
'flex min-h-max max-w-screen flex-row items-center gap-4 overflow-x-auto pr-4 pl-0.5',
28+
restProps.class
29+
].join(' ')
30+
)}
2731
>
2832
{#each images as image, i}
29-
<div class={cn(['group relative shrink-0 mt-3 mb-2'])}>
33+
<div class={cn(['group relative mt-3 mb-2 shrink-0'])}>
3034
<Cross
31-
class="absolute right-0 top-0 hidden -translate-y-1/2 translate-x-1/2 cursor-pointer group-hover:block"
35+
class="absolute top-0 right-0 hidden translate-x-1/2 -translate-y-1/2 cursor-pointer group-hover:block"
3236
onclick={() => callback(i)}
3337
/>
3438
<img
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1-
import type { Image, PostData } from "$lib/types";
1+
import type { Image, PostData } from '$lib/types';
22

33
export const isNavigatingThroughNav = $state({
4-
value: false,
4+
value: false
55
});
66

77
export const showComments = $state({
8-
value: false,
8+
value: false
9+
});
10+
11+
export const ownerId = $state({
12+
value: '1'
913
});
1014

1115
export const selectedPost: { value: PostData | null } = $state({
12-
value: null,
16+
value: null
1317
});
1418

1519
export const uploadedImages: { value: Image[] | null } = $state({
16-
value: null,
20+
value: null
1721
});
1822

1923
export const audience: { value: string } = $state({
20-
value: "Everyone",
21-
});
24+
value: 'Everyone'
25+
});
26+

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ import { apiClient, setAuthToken, removeAuthToken } from '$lib/utils/axios';
44
export const isAuthenticated = writable(false);
55

66
export const initializeAuth = () => {
7-
const token = localStorage.getItem('pictique_auth_token');
8-
if (token) {
9-
apiClient.defaults.headers.common['Authorization'] = `Bearer ${token}`;
10-
isAuthenticated.set(true);
11-
}
7+
const token = localStorage.getItem('pictique_auth_token');
8+
if (token) {
9+
apiClient.defaults.headers.common['Authorization'] = `Bearer ${token}`;
10+
isAuthenticated.set(true);
11+
}
1212
};
1313

1414
export const login = (token: string) => {
15-
setAuthToken(token);
16-
apiClient.defaults.headers.common['Authorization'] = `Bearer ${token}`;
17-
isAuthenticated.set(true);
15+
setAuthToken(token);
16+
apiClient.defaults.headers.common['Authorization'] = `Bearer ${token}`;
17+
isAuthenticated.set(true);
1818
};
1919

2020
export const logout = () => {
21-
removeAuthToken();
22-
delete apiClient.defaults.headers.common['Authorization'];
23-
isAuthenticated.set(false);
24-
};
21+
removeAuthToken();
22+
delete apiClient.defaults.headers.common['Authorization'];
23+
isAuthenticated.set(false);
24+
};

0 commit comments

Comments
 (0)