-
Notifications
You must be signed in to change notification settings - Fork 4
feat: group #258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
feat: group #258
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2611f00
feat: group
grv-saini-20 d70a8b4
fix: separate page added for members
grv-saini-20 5202216
fix: added a edit modal
grv-saini-20 0c50d7e
fix: responsiveness
grv-saini-20 d3d2485
fix: responsiveness
grv-saini-20 be3ec6f
fix: role based editing
grv-saini-20 cf4617d
fix: user role based edit in group info
grv-saini-20 25613d5
fix: edit image with pencil icon
grv-saini-20 a0ff772
fix: added a text area
grv-saini-20 a419df9
feat: new group functionality and textarea fixed
grv-saini-20 de6a1b4
feat: new group functionality and textarea fixed
grv-saini-20 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<script lang="ts"> | ||
import type { HTMLAttributes } from 'svelte/elements'; | ||
import Avatar from '../../ui/Avatar/Avatar.svelte'; | ||
import { cn } from '../../utils'; | ||
|
||
interface IGroupProps extends HTMLAttributes<HTMLButtonElement> { | ||
avatar: string; | ||
name: string; | ||
unread?: boolean; | ||
callback: () => void; | ||
} | ||
|
||
const { | ||
avatar, | ||
name, | ||
unread = false, | ||
callback, | ||
...restProps | ||
}: IGroupProps = $props(); | ||
</script> | ||
|
||
<button | ||
{...restProps} | ||
class={cn([ | ||
'relative flex w-full cursor-pointer items-center gap-3 rounded-lg py-4 px-2', | ||
restProps.class | ||
])} | ||
onclick={callback} | ||
> | ||
<Avatar src={avatar} alt="Group Avatar" size="md" /> | ||
<span class="flex w-full items-center justify-between"> | ||
<h2 class="text-left font-medium">{name}</h2> | ||
{#if unread} | ||
<span class="h-2 w-2 rounded-full bg-blue-500"></span> | ||
{/if} | ||
</span> | ||
</button> | ||
|
||
<!-- | ||
@component | ||
@name GroupItem | ||
@description A group item component that displays a group avatar and name, with an optional unread indicator. | ||
@props | ||
- avatar: string - The URL of the group avatar image. | ||
- name: string - The group name. | ||
- unread: boolean - Optional. Indicates if there are unread messages. Defaults to false. | ||
- callback: () => void - Function to call when the group is clicked. | ||
@usage | ||
<script> | ||
import GroupItem from '$lib/ui/GroupItem.svelte'; | ||
</script> | ||
|
||
<GroupItem | ||
avatar="https://example.com/group-avatar.jpg" | ||
name="Study Buddies" | ||
unread={true} | ||
callback={() => console.log('Group clicked')} | ||
/> | ||
--> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
platforms/pictique/src/routes/(protected)/group/[id]/+page.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<script lang="ts"> | ||
import { onMount } from 'svelte'; | ||
import { ChatMessage, MessageInput } from '$lib/fragments'; | ||
import { Avatar, Button } from '$lib/ui'; | ||
import { goto } from '$app/navigation'; | ||
import { page } from '$app/state'; | ||
|
||
let messagesContainer: HTMLDivElement; | ||
let messageValue = $state(''); | ||
|
||
let userId = 'user-1'; | ||
let id = page.params.id; | ||
|
||
let group = { | ||
id: 'group-123', | ||
name: 'Design Team', | ||
avatar: 'https://i.pravatar.cc/150?img=15', | ||
description: 'Discuss all design-related tasks and updates here.', | ||
members: [ | ||
{ id: 'user-1', name: 'Alice', avatar: 'https://i.pravatar.cc/150?img=1', role: 'owner' }, | ||
{ id: 'user-2', name: 'Bob', avatar: 'https://i.pravatar.cc/150?img=2', role: 'admin' }, | ||
{ id: 'user-3', name: 'Charlie', avatar: 'https://i.pravatar.cc/150?img=3', role: 'member' } | ||
] | ||
}; | ||
|
||
let messages = $state([ | ||
{ | ||
id: 'msg-1', | ||
isOwn: false, | ||
userImgSrc: 'https://i.pravatar.cc/150?img=2', | ||
time: '2 minutes ago', | ||
message: 'Hey everyone, can we finalize the color palette today?' | ||
}, | ||
{ | ||
id: 'msg-2', | ||
isOwn: true, | ||
userImgSrc: 'https://i.pravatar.cc/150?img=1', | ||
time: '1 minute ago', | ||
message: 'Yes, I just pushed a new draft to Figma.' | ||
} | ||
]); | ||
|
||
let openMenuId = $state<string | null>(null); | ||
|
||
function scrollToBottom() { | ||
if (messagesContainer) { | ||
messagesContainer.scrollTop = messagesContainer.scrollHeight; | ||
} | ||
} | ||
|
||
onMount(() => { | ||
setTimeout(scrollToBottom, 0); | ||
}); | ||
|
||
function handleSend() { | ||
if (!messageValue.trim()) return; | ||
messages = [ | ||
...messages, | ||
{ | ||
id: `msg-${Date.now()}`, | ||
isOwn: true, | ||
userImgSrc: group.members.find((m) => m.id === userId)?.avatar || '', | ||
time: 'just now', | ||
message: messageValue | ||
} | ||
]; | ||
messageValue = ''; | ||
setTimeout(scrollToBottom, 0); | ||
} | ||
</script> | ||
|
||
<section class="flex items-center justify-between gap-4 px-4 py-3 border-b border-gray-200"> | ||
<div class="flex items-center gap-4"> | ||
<Avatar src={group.avatar} /> | ||
<div> | ||
<h1 class="text-lg font-semibold">{group.name}</h1> | ||
<p class="text-sm text-gray-600">{group.description}</p> | ||
</div> | ||
</div> | ||
<Button | ||
variant="secondary" | ||
size="sm" | ||
class="w-[max-content]" | ||
callback={() => { | ||
goto(`/group/${id}/members`) | ||
}} | ||
> | ||
View Members | ||
</Button> | ||
</section> | ||
|
||
<section class="chat relative px-0"> | ||
<div class="h-[calc(100vh-300px)] mt-4 overflow-auto" bind:this={messagesContainer}> | ||
{#each messages as msg (msg.id)} | ||
<ChatMessage | ||
isOwn={msg.isOwn} | ||
userImgSrc={msg.userImgSrc} | ||
time={msg.time} | ||
message={msg.message} | ||
/> | ||
{/each} | ||
</div> | ||
|
||
<MessageInput | ||
class="sticky start-0 bottom-[-15px] w-full" | ||
variant="dm" | ||
src={group.avatar} | ||
bind:value={messageValue} | ||
{handleSend} | ||
/> | ||
</section> |
129 changes: 129 additions & 0 deletions
129
platforms/pictique/src/routes/(protected)/group/[id]/members/+page.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<script lang="ts"> | ||
import { page } from '$app/state'; | ||
import { Avatar, Button } from '$lib/ui'; | ||
import { clickOutside } from '$lib/utils'; | ||
let groupId = page.params.id; | ||
let userId = 'user-1'; // Simulated current user | ||
let group = $state({ | ||
id: groupId, | ||
name: 'Design Team', | ||
avatar: 'https://i.pravatar.cc/150?img=15', | ||
description: 'Discuss all design-related tasks and updates here.', | ||
members: [ | ||
{ id: 'user-1', name: 'Alice', avatar: 'https://i.pravatar.cc/150?img=1', role: 'owner' }, | ||
{ id: 'user-2', name: 'Bob', avatar: 'https://i.pravatar.cc/150?img=2', role: 'admin' }, | ||
{ id: 'user-3', name: 'Charlie', avatar: 'https://i.pravatar.cc/150?img=3', role: 'member' } | ||
] | ||
}); | ||
let openMenuId = $state<string | null>(null); | ||
function currentUserRole() { | ||
return group.members.find((m) => m.id === userId)?.role; | ||
} | ||
function canManage(member: { id?: string; name?: string; avatar?: string; role: any; }) { | ||
const current = currentUserRole(); | ||
if (member.role === 'owner') return false; | ||
if (current === 'owner') return true; | ||
if (current === 'admin' && member.role === 'member') return true; | ||
return false; | ||
} | ||
function promoteToAdmin(memberId: string) { | ||
const m = group.members.find((m) => m.id === memberId); | ||
if (m && m.role === 'member') m.role = 'admin'; | ||
openMenuId = null; | ||
} | ||
function removeMember(memberId: string) { | ||
group.members = group.members.filter((m) => m.id !== memberId || m.role === 'owner'); | ||
openMenuId = null; | ||
} | ||
function addMember() { | ||
const newId = `user-${Date.now()}`; | ||
group.members = [ | ||
...group.members, | ||
{ | ||
id: newId, | ||
name: `New Member ${group.members.length + 1}`, | ||
avatar: `https://i.pravatar.cc/150?u=${newId}`, | ||
role: 'member' | ||
} | ||
]; | ||
} | ||
</script> | ||
|
||
<section class="mx-auto w-full h-[80vh] flex flex-col justify-between"> | ||
<div> | ||
<div class="flex items-center gap-4 mb-6"> | ||
<Avatar src={group.avatar} /> | ||
<div> | ||
<h1 class="text-xl font-semibold">{group.name}</h1> | ||
<p class="text-sm text-gray-600">{group.description}</p> | ||
</div> | ||
</div> | ||
|
||
<div class="space-y-6"> | ||
{#each group.members as member (member.id)} | ||
<div class="flex items-center justify-between"> | ||
<div class="flex items-center gap-3"> | ||
<Avatar src={member.avatar} size="sm" /> | ||
<div> | ||
<p class="text-sm font-medium">{member.name}</p> | ||
{#if member.role !== 'member'} | ||
<p class="text-xs text-gray-500">{member.role}</p> | ||
{/if} | ||
</div> | ||
</div> | ||
|
||
{#if canManage(member)} | ||
<div class="relative" use:clickOutside={() => (openMenuId = null)}> | ||
<button | ||
onclick={() => (openMenuId = openMenuId === member.id ? null : member.id)} | ||
> | ||
⋮ | ||
</button> | ||
This conversation was marked as resolved.
Show resolved
Hide resolved
|
||
|
||
{#if openMenuId === member.id} | ||
<div class="absolute right-0 mt-2 w-40 rounded-md bg-white shadow-lg border z-10"> | ||
<!-- svelte-ignore a11y_click_events_have_key_events --> | ||
<ul class="text-sm"> | ||
{#if currentUserRole() === 'owner' && member.role === 'member'} | ||
<!-- svelte-ignore a11y_click_events_have_key_events --> | ||
<!-- svelte-ignore a11y_no_noninteractive_element_interactions --> | ||
<li | ||
class="px-4 py-2 hover:bg-gray-100 cursor-pointer" | ||
onclick={() => promoteToAdmin(member.id)} | ||
> | ||
Make admin | ||
</li> | ||
This conversation was marked as resolved.
Show resolved
Hide resolved
|
||
{/if} | ||
<!-- svelte-ignore a11y_click_events_have_key_events --> | ||
<!-- svelte-ignore a11y_no_noninteractive_element_interactions --> | ||
<li | ||
class="px-4 py-2 hover:bg-red-50 text-red-600 cursor-pointer" | ||
onclick={() => removeMember(member.id)} | ||
> | ||
Remove member | ||
</li> | ||
This conversation was marked as resolved.
Show resolved
Hide resolved
This conversation was marked as resolved.
Show resolved
Hide resolved
|
||
</ul> | ||
</div> | ||
{/if} | ||
</div> | ||
{/if} | ||
</div> | ||
{/each} | ||
</div> | ||
</div> | ||
|
||
<div class="flex justify-center"> | ||
<Button size="sm" variant="secondary" class="mt-6" callback={addMember}> | ||
Add Member | ||
</Button> | ||
</div> | ||
</section> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.