-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from reaviz/easy-mode
#18 Simplify SessionGroups and SessionMessages for basic implementation
- Loading branch information
Showing
8 changed files
with
111 additions
and
469 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,17 +1,31 @@ | ||
import { FC, ReactNode, useContext, useMemo } from 'react'; | ||
import { GroupedSessions, groupSessionsByDate } from '@/utils/grouping'; | ||
import { ChatContext } from '@/ChatContext'; | ||
import { SessionsGroup } from './SessionsGroup'; | ||
import { SessionListItem } from './SessionListItem'; | ||
|
||
export interface SessionGroupsProps { | ||
/** | ||
* Render function for the session groups. | ||
*/ | ||
children: (groups: GroupedSessions[]) => ReactNode; | ||
children?: (groups: GroupedSessions[]) => ReactNode; | ||
} | ||
|
||
export const SessionGroups: FC<SessionGroupsProps> = ({ children }) => { | ||
const { sessions } = useContext(ChatContext); | ||
const groups = useMemo(() => groupSessionsByDate(sessions), [sessions]); | ||
|
||
return <>{children(groups)}</>; | ||
return ( | ||
<> | ||
{children | ||
? children(groups) | ||
: groups.map(({ heading, sessions }) => ( | ||
<SessionsGroup heading={heading}> | ||
{sessions.map(session => ( | ||
<SessionListItem key={session.id} session={session} /> | ||
))} | ||
</SessionsGroup> | ||
))} | ||
</> | ||
); | ||
}; |
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
Oops, something went wrong.