Skip to content

Commit

Permalink
feat(web): convo list
Browse files Browse the repository at this point in the history
  • Loading branch information
McPizza0 committed May 27, 2024
1 parent d036ab9 commit 1fccf93
Show file tree
Hide file tree
Showing 23 changed files with 610 additions and 256 deletions.
4 changes: 3 additions & 1 deletion apps/platform/trpc/routers/convoRouter/convoRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,9 @@ export const convoRouter = router({
},
with: {
author: {
columns: {},
columns: {
publicId: true
},
with: {
orgMember: {
columns: {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "default",
"style": "new-york",
"rsc": false,
"tsx": true,
"tailwind": {
Expand Down
3 changes: 2 additions & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-hover-card": "^1.0.7",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-scroll-area": "^1.0.5",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-separator": "^1.0.3",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-toggle": "^1.0.3",
"@radix-ui/react-toggle-group": "^1.0.4",
"@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-tooltip": "^1.0.7",
"@radix-ui/themes": "^3.0.2",
"@simplewebauthn/browser": "^10.0.0",
Expand Down
18 changes: 3 additions & 15 deletions apps/web/src/app/[orgShortCode]/_components/sidebar-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import useLoading from '@/src/hooks/use-loading';
import { cn, generateAvatarUrl, getInitials } from '@/src/lib/utils';
import { useGlobalStore } from '@/src/providers/global-store-provider';
import { Button } from '@/src/components/shadcn-ui/button';
import {
Avatar,
AvatarFallback,
Expand All @@ -25,31 +24,20 @@ import {

import {
Check,
AddressBook,
SignOut,
ChatCircle,
MoonStars,
Gear,
SpinnerGap,
Sun,
CaretRight,
CaretLeft,
SquaresFour,
Shield,
CaretUp,
Book,
QuestionMark,
MapPin,
Activity,
Megaphone,
PushPin,
CaretDoubleLeft,
CaretUpDown,
Plus,
Palette,
Monitor,
Question,
Paperclip,
User
} from '@phosphor-icons/react';
import { env } from 'next-runtime-env';
Expand All @@ -59,11 +47,11 @@ import { useMemo } from 'react';
import { toast } from 'sonner';
import { useQueryClient } from '@tanstack/react-query';
import React from 'react';
import { SidebarNavButton } from './sidebar-nav-button';

import { useTheme } from 'next-themes';
import { sidebarSubmenuOpenAtom } from './atoms';
import { useAtom } from 'jotai';
import { usePreferencesState } from '@/src/stores/preferences-store';

import {
ToggleGroup,
ToggleGroupItem
Expand Down Expand Up @@ -102,7 +90,7 @@ export default function SidebarContent() {
<span className={cn('font-display text-slate-11 text-sm')}>
UnInbox
</span>
<span className={cn('text-slate-11 text-xs')}>v0.1.23</span>
<span className={cn('text-slate-11 text-xs')}>v0.1.0</span>
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ export function SidebarNavButton({
<div className={'flex w-full max-w-full flex-col gap-0 p-0'}>
<div
className={cn(
'bg-sand-3 text-sand-12 flex w-full max-w-full flex-row items-center justify-start gap-0 overflow-hidden truncate rounded-md pl-1 text-left',
active ? 'bg-sand-5' : '',
disabled ? 'opacity-80' : 'hover:bg-sand-4'
' text-base-12 flex w-full max-w-full flex-row items-center justify-start gap-0 overflow-hidden truncate rounded-md pl-1 text-left',
active ? 'bg-base-5' : '',
disabled ? 'opacity-80' : 'hover:bg-base-4'
)}
{...props}>
{children ? (
<div
className="text-sand-12 h-5 w-5 cursor-pointer rounded-sm p-0.5"
className="text-base-12 h-5 w-5 cursor-pointer rounded-sm p-0.5"
onClick={() => {
setExpanded(!expanded);
}}>
Expand Down Expand Up @@ -89,14 +89,14 @@ export function SidebarNavButton({
asChild>
<div
className={cn(
'text-sand-12 flex h-full w-full flex-row gap-0 overflow-hidden px-2 py-2',
'text-base-12 flex h-full w-full flex-row gap-0 overflow-hidden px-2 py-2',
disabled ? 'cursor-not-allowed' : 'cursor-pointer'
)}>
<div className="mr-2 h-5 w-5 rounded-sm p-0 *:h-5 *:w-5">
{icon}
</div>
<div className="text-sand-12 flex w-full max-w-full flex-row justify-between gap-2 overflow-hidden">
<span className={cn('text-sand-12 truncate text-sm')}>
<div className="text-base-12 flex w-full max-w-full flex-row justify-between gap-2 overflow-hidden">
<span className={cn('text-base-12 truncate text-sm')}>
{label}
</span>
{badge && <Badge variant={'secondary'}>{badge}</Badge>}
Expand Down
8 changes: 1 addition & 7 deletions apps/web/src/app/[orgShortCode]/_components/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@

import { cn } from '@/src/lib/utils';
import { usePreferencesState } from '@/src/stores/preferences-store';
import {
CaretDoubleLeft,
CaretLineRight,
Cross,
PushPin,
X
} from '@phosphor-icons/react';
import { CaretDoubleLeft, PushPin, X } from '@phosphor-icons/react';
import SidebarContent from './sidebar-content';
import { sidebarSubmenuOpenAtom } from './atoms';
import { useAtom } from 'jotai';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function TopBar({
const toggleConvoHiddenState = useToggleConvoHidden$Cache();

return (
<div className=" bg-sand-2 flex h-12 w-full flex-row items-center justify-between p-2">
<div className=" bg-base-2 flex h-12 w-full flex-row items-center justify-between p-2">
<div className="flex flex-row items-center gap-4">
<Link href={`/${orgShortCode}/convo`}>
<IconButton
Expand Down
108 changes: 108 additions & 0 deletions apps/web/src/app/[orgShortCode]/convo/_components/convo-list-item.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
'use client';

import { type RouterOutputs } from '@/src/lib/trpc';
import { useGlobalStore } from '@/src/providers/global-store-provider';
import { useMemo } from 'react';
import useTimeAgo from '@/src/hooks/use-time-ago';
import { formatParticipantData } from '../utils';
import Link from 'next/link';
import AvatarPlus from '@/src/components/avatar-plus';
import { Avatar } from '@/src/components/avatar';
import { cn } from '@/src/lib/utils';
import { usePathname } from 'next/navigation';

export function ConvoItem({
convo
}: {
convo: RouterOutputs['convos']['getOrgMemberConvos']['data'][number];
}) {
const orgShortCode = useGlobalStore((state) => state.currentOrg.shortCode);

const timeAgo = useTimeAgo(convo.lastUpdatedAt);

const authorAsParticipant = useMemo(() => {
return (
convo.participants.find(
(participant) =>
participant.publicId === convo.entries[0]?.author.publicId
) ?? convo.participants[0]
);
}, [convo.participants, convo.entries]);

const authorAvatarData = useMemo(() => {
return formatParticipantData(authorAsParticipant!);
}, [authorAsParticipant]);

const participantData = useMemo(() => {
const allParticipants = convo.participants
.map((participant) => formatParticipantData(participant))
.filter(Boolean) as NonNullable<
ReturnType<typeof formatParticipantData>
>[];
const participantsWithoutAuthor = allParticipants.filter(
(participant) =>
participant.participantPublicId !== authorAsParticipant?.publicId
);
const author = allParticipants.find(
(participant) =>
participant.participantPublicId === authorAsParticipant?.publicId
)!;
return [author].concat(participantsWithoutAuthor);
}, [convo.participants, authorAsParticipant]);

const participantNames = useMemo(() => {
return participantData.map((participant) => participant.name);
}, [participantData]);

const currentPath = usePathname();
const link = `/${orgShortCode}/convo/${convo.publicId}`;

const isActive = currentPath === link;

return (
<Link
href={link}
className={cn(
'flex h-full w-full max-w-full flex-row gap-2 overflow-visible rounded-lg border-2 p-2',
isActive ? 'bg-accent-3 border-accent-8 ' : 'border-transparent'
)}>
<AvatarPlus
size="md"
users={participantData}
/>
<div className="flex w-full flex-1 flex-col">
<div className="flex w-full flex-row items-end justify-between gap-1">
<span className="truncate text-sm font-medium">
{participantNames.join(', ')}
</span>
<span className="text-base-11 min-w-fit text-right text-xs">
{timeAgo}
</span>
</div>

<span className="w-full truncate text-left text-xs font-medium">
{convo.subjects[0]?.subject}
</span>

<div className="flex w-full flex-row items-start justify-start gap-1 text-left text-sm">
<div className="px-0.5">
{authorAvatarData && (
<Avatar
avatarProfilePublicId={authorAvatarData.avatarProfilePublicId}
avatarTimestamp={authorAvatarData.avatarTimestamp}
name={authorAvatarData.name}
size={'sm'}
color={authorAvatarData.color}
key={authorAvatarData.participantPublicId}
/>
)}
</div>

<span className="line-clamp-2 w-full max-w-full overflow-ellipsis break-words">
{convo.entries[0]?.bodyPlainText ?? ''}
</span>
</div>
</div>
</Link>
);
}
Loading

0 comments on commit 1fccf93

Please sign in to comment.