Skip to content

Commit

Permalink
Merge branch 'master' into update-style
Browse files Browse the repository at this point in the history
  • Loading branch information
amcdnl committed Aug 1, 2024
2 parents 62fab89 + 5a75c2c commit 203f2f7
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 16 deletions.
9 changes: 0 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reachat",
"version": "1.0.1",
"version": "1.0.3",
"description": "Chat UI for Building LLMs",
"scripts": {
"build-storybook": "storybook build",
Expand Down Expand Up @@ -42,7 +42,6 @@
"framer-motion": "^10.16.16",
"mdast-util-find-and-replace": "^3.0.1",
"reablocks": "^8.4.0",
"react-cool-dimensions": "^3.0.1",
"react-markdown": "^9.0.1",
"react-syntax-highlighter": "^15.5.0",
"reakeys": "^2.0.3",
Expand Down
2 changes: 1 addition & 1 deletion src/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { Session } from './types';
import { ChatTheme, chatTheme } from './theme';
import { ChatContext } from './ChatContext';
import { PluggableList } from 'react-markdown/lib';
import useDimensions from 'react-cool-dimensions';
import { AnimatePresence } from 'framer-motion';
import { useDimensions } from './utils/useDimensions';

export interface ChatProps extends PropsWithChildren {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/SessionsList/SessionGroups.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FC, ReactNode, useContext, useMemo } from 'react';
import { GroupedSessions, groupSessionsByDate } from '@/utils';
import { GroupedSessions, groupSessionsByDate } from '@/utils/grouping';
import { ChatContext } from '@/ChatContext';

export interface SessionGroupsProps {
Expand Down
4 changes: 2 additions & 2 deletions src/utils.spec.ts → src/utils/grouping.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect } from 'vitest';
import { groupSessionsByDate } from './utils';
import { Session } from './types';
import { groupSessionsByDate } from './grouping';
import { Session } from '@/types';
import { subDays } from 'date-fns';

describe('groupSessionsByDate', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts → src/utils/grouping.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { format, isToday, isYesterday, isThisWeek, isThisMonth, isThisYear, parseISO } from 'date-fns';
import { Session } from './types';
import { Session } from '@/types';

export interface GroupedSessions {
heading: string;
Expand Down
28 changes: 28 additions & 0 deletions src/utils/useDimensions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { useCallback, useEffect, useState } from 'react';

export const useDimensions = () => {
const [ref, setRef] = useState<HTMLElement | null>(null);
const [width, setWidth] = useState<number | undefined>(undefined);

const observe = useCallback((element: HTMLElement | null) => {
if (element) setRef(element);
}, []);

useEffect(() => {
if (!ref) return;

const resizeObserver = new ResizeObserver(entries => {
for (let entry of entries) {
setWidth(entry.contentRect.width);
}
});

resizeObserver.observe(ref);

return () => {
resizeObserver.disconnect();
};
}, [ref]);

return { width, observe };
};

0 comments on commit 203f2f7

Please sign in to comment.