-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(chat): add prorotype pinning section
- Loading branch information
Showing
12 changed files
with
267 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,3 @@ | ||
export * from './pinned-message-card'; | ||
export * from './pinned-messages-container'; | ||
export * from './pinned-messages-placeholder'; |
43 changes: 43 additions & 0 deletions
43
apps/chat/src/modules/pinned-messages/grid/pinned-message-card.tsx
This file contains 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,43 @@ | ||
import { LinkIcon } from 'lucide-react'; | ||
import { useLocation } from 'wouter'; | ||
|
||
import type { SdkSearchPinnedMessageItemT } from '@llm/sdk'; | ||
|
||
import { useI18n } from '~/i18n'; | ||
import { ChatMessage } from '~/modules/chats'; | ||
import { ToolbarSmallActionButton } from '~/modules/chats/conversation/messages/buttons'; | ||
import { useSitemap } from '~/routes/use-sitemap'; | ||
|
||
type Props = { | ||
pinnedMessage: SdkSearchPinnedMessageItemT; | ||
}; | ||
|
||
export function PinnedMessageCard({ pinnedMessage }: Props) { | ||
const { message } = pinnedMessage; | ||
|
||
const sitemap = useSitemap(); | ||
const t = useI18n().pack.pinnedMessages.buttons; | ||
const [, navigate] = useLocation(); | ||
|
||
const onNavigate = () => { | ||
const link = sitemap.chat.generate({ pathParams: { id: message.chat.id } }); | ||
|
||
navigate(link); | ||
}; | ||
|
||
return ( | ||
<ChatMessage | ||
className="mx-auto mb-0 max-w-[750px]" | ||
message={{ ...message, repeats: [] }} | ||
showToolbars={false} | ||
showAnim={false} | ||
actionsToolbar={( | ||
<ToolbarSmallActionButton | ||
title={t.goToChat} | ||
icon={<LinkIcon size={14} className="text-gray-500" />} | ||
onClick={onNavigate} | ||
/> | ||
)} | ||
/> | ||
); | ||
} |
86 changes: 86 additions & 0 deletions
86
apps/chat/src/modules/pinned-messages/grid/pinned-messages-container.tsx
This file contains 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,86 @@ | ||
import { flow } from 'fp-ts/lib/function'; | ||
import { useMemo } from 'react'; | ||
|
||
import { | ||
SdkSearchProjectsInputV, | ||
useSdkForLoggedIn, | ||
useSdkSubscribePinnedMessagesOrThrow, | ||
} from '@llm/sdk'; | ||
import { useWorkspaceOrganizationOrThrow } from '~/modules/workspace'; | ||
import { | ||
PaginatedList, | ||
PaginationSearchToolbarItem, | ||
PaginationToolbar, | ||
ResetFiltersButton, | ||
useDebouncedPaginatedSearch, | ||
} from '~/ui'; | ||
|
||
import { PinnedMessagesPlaceholder } from './pinned-messages-placeholder'; | ||
import { PinnedMessagesTimeline } from './pinned-messages-timeline'; | ||
|
||
type Props = { | ||
storeDataInUrl?: boolean; | ||
}; | ||
|
||
export function PinnedMessagesContainer({ storeDataInUrl = false }: Props) { | ||
const { assignWorkspaceToFilters } = useWorkspaceOrganizationOrThrow(); | ||
|
||
const { sdks } = useSdkForLoggedIn(); | ||
const { loading, pagination, result, reset } = useDebouncedPaginatedSearch({ | ||
storeDataInUrl, | ||
schema: SdkSearchProjectsInputV, | ||
fallbackSearchParams: { | ||
limit: 100, | ||
}, | ||
fetchResultsTask: flow(assignWorkspaceToFilters, sdks.dashboard.pinnedMessages.search), | ||
}); | ||
|
||
const allPinnedItems = useSdkSubscribePinnedMessagesOrThrow(); | ||
const mappedResult = useMemo(() => { | ||
if (!result || allPinnedItems.loading) { | ||
return null; | ||
} | ||
|
||
const mappedItems = result.items.filter(item => allPinnedItems.items.some(pinnedItem => pinnedItem.id === item.id)); | ||
|
||
return { | ||
...result, | ||
items: mappedItems, | ||
...!mappedItems.length && { | ||
total: 0, | ||
}, | ||
}; | ||
}, [result, allPinnedItems]); | ||
|
||
return ( | ||
<section> | ||
<PaginationToolbar className="mb-6"> | ||
<PaginationSearchToolbarItem | ||
{...pagination.bind.path('phrase', { | ||
relatedInputs: ({ newGlobalValue, newControlValue }) => ({ | ||
...newGlobalValue, | ||
sort: newControlValue ? 'score:desc' : 'createdAt:asc', | ||
}), | ||
})} | ||
/> | ||
|
||
<ResetFiltersButton onClick={reset} /> | ||
</PaginationToolbar> | ||
|
||
<PaginatedList | ||
result={mappedResult} | ||
loading={loading || allPinnedItems.loading} | ||
pagination={pagination.bind.entire()} | ||
withEmptyPlaceholder={false} | ||
> | ||
{({ items, total }) => { | ||
if (!total || allPinnedItems.loading) { | ||
return <PinnedMessagesPlaceholder />; | ||
} | ||
|
||
return <PinnedMessagesTimeline items={items} />; | ||
}} | ||
</PaginatedList> | ||
</section> | ||
); | ||
} |
10 changes: 10 additions & 0 deletions
10
apps/chat/src/modules/pinned-messages/grid/pinned-messages-placeholder.tsx
This file contains 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,10 @@ | ||
import { useI18n } from '~/i18n'; | ||
import { GhostPlaceholder } from '~/modules/shared'; | ||
|
||
export function PinnedMessagesPlaceholder() { | ||
const t = useI18n().pack.pinnedMessages.grid; | ||
|
||
return ( | ||
<GhostPlaceholder>{t.placeholder}</GhostPlaceholder> | ||
); | ||
} |
55 changes: 55 additions & 0 deletions
55
apps/chat/src/modules/pinned-messages/grid/pinned-messages-timeline.tsx
This file contains 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,55 @@ | ||
import { clsx } from 'clsx'; | ||
|
||
import type { SdkSearchPinnedMessageItemT } from '@llm/sdk'; | ||
|
||
import { formatDate } from '@llm/commons'; | ||
|
||
import { PinnedMessageCard } from './pinned-message-card'; | ||
|
||
type TimelineProps = { | ||
items: SdkSearchPinnedMessageItemT[]; | ||
}; | ||
|
||
export function PinnedMessagesTimeline({ items }: TimelineProps) { | ||
return ( | ||
<div className="relative"> | ||
<div className="top-0 bottom-0 left-1/2 absolute bg-gray-200 w-0.5 -translate-x-1/2" /> | ||
|
||
<div className="relative space-y-12"> | ||
{items.map((item, index) => { | ||
const isEven = index % 2 === 0; | ||
|
||
return ( | ||
<div key={item.id} className="relative"> | ||
<div className="top-7 left-1/2 absolute bg-white border-2 border-gray-300 rounded-full w-3 h-3 -translate-x-1/2" /> | ||
|
||
<div className={clsx('flex items-start', isEven ? 'justify-end pr-[52%]' : 'justify-start pl-[52%]')}> | ||
<div | ||
className="top-1/2 left-1/2 absolute bg-gray-200 w-4 h-0.5" | ||
style={{ | ||
transform: `translateX(${isEven ? '-100%' : '0'})`, | ||
}} | ||
/> | ||
|
||
<div className="w-full max-w-xl"> | ||
<div className="clear-both"> | ||
<PinnedMessageCard pinnedMessage={item} /> | ||
</div> | ||
|
||
<div | ||
className={clsx( | ||
'inline-block bg-gray-50 px-3 pt-4 rounded-full text-gray-600 text-sm', | ||
isEven ? 'float-right' : 'float-left', | ||
)} | ||
> | ||
{formatDate(item.createdAt)} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains 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 @@ | ||
export * from './grid'; |
This file contains 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