Skip to content

Commit 318ae1f

Browse files
committed
chore: checks fixed in pictique.
1 parent 0041c95 commit 318ae1f

File tree

4 files changed

+91
-51
lines changed

4 files changed

+91
-51
lines changed
Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,49 @@
1-
import { writable } from 'svelte/store';
2-
import { apiClient } from '$lib/utils/axios';
1+
import { apiClient } from "$lib/utils/axios";
2+
import { writable } from "svelte/store";
33

44
export interface User {
5-
id: string;
6-
handle: string;
7-
name: string;
8-
description: string;
9-
avatarUrl: string;
10-
isVerified: boolean;
5+
id: string;
6+
ename: string;
7+
handle: string;
8+
name: string;
9+
description: string;
10+
avatarUrl: string;
11+
isVerified: boolean;
1112
}
1213

1314
export const searchResults = writable<User[]>([]);
1415
export const isSearching = writable(false);
1516
export const searchError = writable<string | null>(null);
1617

1718
export const searchUsers = async (query: string) => {
18-
if (!query.trim()) {
19-
searchResults.set([]);
20-
return;
21-
}
19+
if (!query.trim()) {
20+
searchResults.set([]);
21+
return;
22+
}
2223

23-
try {
24-
isSearching.set(true);
25-
searchError.set(null);
26-
const response = await apiClient.get(`/api/users/search?q=${encodeURIComponent(query)}`);
27-
searchResults.set(response.data);
28-
} catch (err) {
29-
searchError.set(err instanceof Error ? err.message : 'Failed to search users');
30-
searchResults.set([]);
31-
} finally {
32-
isSearching.set(false);
33-
}
24+
try {
25+
isSearching.set(true);
26+
searchError.set(null);
27+
const response = await apiClient.get(
28+
`/api/users/search?q=${encodeURIComponent(query)}`,
29+
);
30+
searchResults.set(response.data);
31+
} catch (err) {
32+
searchError.set(
33+
err instanceof Error ? err.message : "Failed to search users",
34+
);
35+
searchResults.set([]);
36+
} finally {
37+
isSearching.set(false);
38+
}
3439
};
3540

3641
export const followUser = async (followingId: string) => {
37-
try {
38-
await apiClient.post('/api/users/follow', { followingId });
39-
return true;
40-
} catch (err) {
41-
console.error('Failed to follow user:', err);
42-
return false;
43-
}
42+
try {
43+
await apiClient.post("/api/users/follow", { followingId });
44+
return true;
45+
} catch (err) {
46+
console.error("Failed to follow user:", err);
47+
return false;
48+
}
4449
};

platforms/pictique/src/lib/types.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,38 @@ export type GroupInfo = {
7979
name: string;
8080
avatar: string;
8181
};
82+
83+
export type MessageInfo = {
84+
avatar: string;
85+
id: string;
86+
text: string;
87+
unread: boolean;
88+
username: string;
89+
};
90+
91+
export type Participant = {
92+
avatarUrl: string;
93+
handle: string;
94+
id: string;
95+
name: string;
96+
ename: string;
97+
};
98+
99+
export type ChatInfo = {
100+
id: string;
101+
name: string;
102+
updatedAt: string;
103+
participants: Participant[];
104+
latestMessage?: {
105+
isRead: boolean;
106+
text: string;
107+
};
108+
};
109+
110+
export type Member = {
111+
id: string;
112+
name?: string;
113+
handle?: string;
114+
ename?: string;
115+
avatarUrl?: string;
116+
};

platforms/pictique/src/routes/(protected)/group/[id]/+page.svelte

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<script lang="ts">
2-
import { onMount } from 'svelte';
3-
import { ChatMessage, MessageInput } from '$lib/fragments';
4-
import { Avatar, Button, Input, Label } from '$lib/ui';
52
import { goto } from '$app/navigation';
63
import { page } from '$app/state';
4+
import { ChatMessage, MessageInput } from '$lib/fragments';
75
import Settings from '$lib/icons/Settings.svelte';
6+
import { Avatar, Button, Input, Label } from '$lib/ui';
87
import { clickOutside } from '$lib/utils';
98
import { Pen01FreeIcons } from '@hugeicons/core-free-icons';
109
import { HugeiconsIcon } from '@hugeicons/svelte';
10+
import { onMount } from 'svelte';
1111
1212
let messagesContainer: HTMLDivElement;
1313
let messageValue = $state('');
@@ -63,8 +63,8 @@
6363
setTimeout(scrollToBottom, 0);
6464
});
6565
66-
function handleSend() {
67-
if (!messageValue.trim()) return;
66+
function handleSend(): Promise<void> {
67+
if (!messageValue.trim()) return Promise.resolve();
6868
messages = [
6969
...messages,
7070
{
@@ -77,6 +77,7 @@
7777
];
7878
messageValue = '';
7979
setTimeout(scrollToBottom, 0);
80+
return Promise.resolve();
8081
}
8182
8283
let openEditDialog = $state(false);
@@ -152,7 +153,7 @@
152153
</div>
153154

154155
<MessageInput
155-
class="sticky start-0 bottom-[-15px] w-full"
156+
class="sticky bottom-[-15px] start-0 w-full"
156157
variant="dm"
157158
src={group.avatar}
158159
bind:value={messageValue}
@@ -188,7 +189,7 @@
188189
/>
189190
<label
190191
for="group-avatar-input"
191-
class="bg-brand-burnt-orange border-brand-burnt-orange absolute right-0 bottom-0 cursor-pointer rounded-full border p-1 shadow"
192+
class="bg-brand-burnt-orange border-brand-burnt-orange absolute bottom-0 right-0 cursor-pointer rounded-full border p-1 shadow"
192193
>
193194
<HugeiconsIcon icon={Pen01FreeIcons} color="white" />
194195
</label>
@@ -212,7 +213,7 @@
212213
rows="2"
213214
maxlength="260"
214215
placeholder="Edit group description"
215-
class="bg-grey text-black-800 font-geist placeholder:text-black-600 invalid:border-red invalid:text-red focus:invalid:text-black-800 w-full rounded-4xl border border-transparent px-6 py-3.5 text-[15px] font-normal outline-0 focus:invalid:border-transparent"
216+
class="bg-grey text-black-800 font-geist placeholder:text-black-600 invalid:border-red invalid:text-red focus:invalid:text-black-800 rounded-4xl w-full border border-transparent px-6 py-3.5 text-[15px] font-normal outline-0 focus:invalid:border-transparent"
216217
bind:value={groupDescription}
217218
/>
218219
{:else}

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
<script lang="ts">
22
import { goto } from '$app/navigation';
3-
import { onMount } from 'svelte';
43
import { Message } from '$lib/fragments';
54
import Group from '$lib/fragments/Group/Group.svelte';
6-
import { Button, Avatar, Input } from '$lib/ui';
5+
import { isSearching, searchError, searchResults, searchUsers } from '$lib/stores/users';
6+
import type { ChatInfo, GroupInfo, Member, MessageInfo, userProfile } from '$lib/types';
7+
import { Avatar, Button, Input } from '$lib/ui';
78
import { clickOutside } from '$lib/utils';
8-
import { heading } from '../../store';
99
import { apiClient } from '$lib/utils/axios';
10+
import { onMount } from 'svelte';
11+
import { heading } from '../../store';
1012
11-
import { searchUsers, searchResults, isSearching, searchError } from '$lib/stores/users';
12-
import type { GroupInfo } from '$lib/types';
13-
14-
let messages = $state([]);
15-
let groups: GroupInfo[] = $state([]);
16-
let allMembers = $state([]);
13+
let messages = $state<MessageInfo[]>([]);
14+
let groups = $state<GroupInfo[]>([]);
15+
let allMembers = $state<Member[]>([]);
1716
let selectedMembers = $state<string[]>([]);
1817
let currentUserId = '';
1918
let openNewChatModal = $state(false);
2019
let searchValue = $state('');
2120
let debounceTimer: NodeJS.Timeout;
2221
2322
async function loadMessages() {
24-
const { data } = await apiClient.get('/api/chats');
25-
const { data: userData } = await apiClient.get('/api/users');
23+
const { data } = await apiClient.get<{ chats: ChatInfo[] }>('/api/chats');
24+
const { data: userData } = await apiClient.get<userProfile>('/api/users');
2625
currentUserId = userData.id;
2726
2827
messages = data.chats.map((c) => {
@@ -67,7 +66,7 @@
6766
6867
try {
6968
if (selectedMembers.length === 1) {
70-
await apiClient.post(`/api/chats/`, {
69+
await apiClient.post('/api/chats/', {
7170
name: allMembers.find((m) => m.id === selectedMembers[0])?.name ?? 'New Chat',
7271
participantIds: [selectedMembers[0]]
7372
});
@@ -125,7 +124,7 @@
125124
{/if}
126125

127126
{#if groups.length > 0}
128-
<h3 class="text-md mt-6 mb-2 font-semibold text-gray-700">Groups</h3>
127+
<h3 class="text-md mb-2 mt-6 font-semibold text-gray-700">Groups</h3>
129128
{#each groups as group}
130129
<Group
131130
name={group.name || 'New Group'}

0 commit comments

Comments
 (0)