Skip to content

Commit 5202216

Browse files
grv-saini-20sosweetham
authored andcommitted
fix: added a edit modal
1 parent d70a8b4 commit 5202216

File tree

2 files changed

+93
-14
lines changed

2 files changed

+93
-14
lines changed

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

Lines changed: 92 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
<script lang="ts">
22
import { onMount } from 'svelte';
33
import { ChatMessage, MessageInput } from '$lib/fragments';
4-
import { Avatar, Button } from '$lib/ui';
4+
import { Avatar, Button, Input, Label } from '$lib/ui';
5+
import { InputFile } from '$lib/fragments';
6+
import { HugeiconsFreeIcons, Edit01FreeIcons } from '@hugeicons/core-free-icons';
57
import { goto } from '$app/navigation';
68
import { page } from '$app/state';
9+
import Settings from '$lib/icons/Settings.svelte';
10+
import { clickOutside } from '$lib/utils';
711
812
let messagesContainer: HTMLDivElement;
913
let messageValue = $state('');
14+
let openMenuId = $state<string | null>(null);
1015
1116
let userId = 'user-1';
1217
let id = page.params.id;
@@ -40,8 +45,6 @@
4045
}
4146
]);
4247
43-
let openMenuId = $state<string | null>(null);
44-
4548
function scrollToBottom() {
4649
if (messagesContainer) {
4750
messagesContainer.scrollTop = messagesContainer.scrollHeight;
@@ -67,8 +70,39 @@
6770
messageValue = '';
6871
setTimeout(scrollToBottom, 0);
6972
}
73+
74+
// Edit Dialog state and logic
75+
let openEditDialog = $state(false);
76+
let groupName = $state(group.name);
77+
let groupDescription = $state(group.description);
78+
let groupImageDataUrl = $state(group.avatar);
79+
let groupImageFiles = $state<FileList | undefined>();
80+
81+
function handleGroupImageChange() {
82+
if (groupImageFiles && groupImageFiles[0]) {
83+
const reader = new FileReader();
84+
reader.onload = (e) => {
85+
if (e.target?.result) {
86+
groupImageDataUrl = e.target.result as string;
87+
}
88+
};
89+
reader.readAsDataURL(groupImageFiles[0]);
90+
}
91+
}
92+
93+
$effect(() => {
94+
if (groupImageFiles) handleGroupImageChange();
95+
});
96+
97+
function saveGroupInfo() {
98+
group.name = groupName;
99+
group.description = groupDescription;
100+
group.avatar = groupImageDataUrl;
101+
openEditDialog = false;
102+
}
70103
</script>
71104

105+
<!-- Group Header -->
72106
<section class="flex items-center justify-between gap-4 px-4 py-3 border-b border-gray-200">
73107
<div class="flex items-center gap-4">
74108
<Avatar src={group.avatar} />
@@ -77,18 +111,26 @@
77111
<p class="text-sm text-gray-600">{group.description}</p>
78112
</div>
79113
</div>
80-
<Button
81-
variant="secondary"
82-
size="sm"
83-
class="w-[max-content]"
84-
callback={() => {
85-
goto(`/group/${id}/members`)
86-
}}
87-
>
88-
View Members
89-
</Button>
114+
<div class="flex items-center gap-2">
115+
<Button
116+
variant="secondary"
117+
size="sm"
118+
class="w-[max-content]"
119+
callback={() => {
120+
goto(`/group/${id}/members`);
121+
}}
122+
>
123+
View Members
124+
</Button>
125+
<button
126+
onclick={() => (openEditDialog = true)}
127+
>
128+
<Settings size="24px" color="var(--color-brand-burnt-orange)" />
129+
</button>
130+
</div>
90131
</section>
91132

133+
<!-- Chat Area -->
92134
<section class="chat relative px-0">
93135
<div class="h-[calc(100vh-300px)] mt-4 overflow-auto" bind:this={messagesContainer}>
94136
{#each messages as msg (msg.id)}
@@ -109,3 +151,40 @@
109151
{handleSend}
110152
/>
111153
</section>
154+
155+
<dialog open={openEditDialog} use:clickOutside={() => openEditDialog = false} onclose={() => (openEditDialog = false)} class="absolute start-[50%] top-[50%] translate-x-[-50%] translate-y-[-50%] p-4" >
156+
<div class="flex flex-col gap-6">
157+
<div>
158+
<InputFile
159+
bind:files={groupImageFiles}
160+
accept="image/*"
161+
label="Upload Group Avatar"
162+
cancelLabel="Remove"
163+
oncancel={() => {
164+
groupImageDataUrl = '';
165+
groupImageFiles = undefined;
166+
}}
167+
/>
168+
{#if groupImageDataUrl}
169+
<img
170+
src={groupImageDataUrl}
171+
alt="Group preview"
172+
class="mt-2 h-24 w-24 rounded-full object-cover"
173+
/>
174+
{/if}
175+
</div>
176+
177+
<div>
178+
<Label>Group Name</Label>
179+
<Input type="text" placeholder="Edit group name" bind:value={groupName} />
180+
</div>
181+
182+
<div>
183+
<Label>Description</Label>
184+
<Input type="text" placeholder="Edit group description" bind:value={groupDescription} />
185+
</div>
186+
187+
<hr class="text-grey" />
188+
<Button size="sm" variant="secondary" callback={saveGroupInfo}>Save Changes</Button>
189+
</div>
190+
</dialog>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
let groupId = page.params.id;
77
8-
let userId = 'user-1'; // Simulated current user
8+
let userId = 'user-1';
99
1010
let group = $state({
1111
id: groupId,

0 commit comments

Comments
 (0)