Skip to content

Commit

Permalink
feat: support new ui
Browse files Browse the repository at this point in the history
  • Loading branch information
JianJroh committed Nov 23, 2023
1 parent 9f98e47 commit c2d724d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
Binary file modified assets/demo.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ function App() {
if (event.target instanceof HTMLLIElement) {
const targetIndex = Number(event.target.dataset.index);
if (!isSharePage) {
const isScrollUp = activeQuestionIndex != null && targetIndex < activeQuestionIndex;
questionEls.forEach((q) => {
q.style.scrollMarginTop = isScrollUp ? '60px' : '0';
q.style.scrollMarginTop = '56px';
});
}
questionEls?.[targetIndex]?.scrollIntoView({ behavior: 'smooth' });
Expand Down
3 changes: 1 addition & 2 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ export function queryChatContainer() {
}

export function queryQuestionEls() {
const CHAT_ITEM_EL_CLASS = 'group';
return Array.from((queryChatContainer()?.children ?? []) as HTMLDivElement[])
.filter((child) => child.classList.contains(CHAT_ITEM_EL_CLASS))
.filter((child) => child.hasAttribute('data-testid'))
.filter((_, index) => index % 2 === 0);
}

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/sharePage.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const isSharePage = location.pathname.startsWith('/share/');

export const scrollMarginTop = 45;
export const scrollMarginTop = 0;
8 changes: 7 additions & 1 deletion src/hooks/useQuestionEls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import { useMountedCallbackValue } from './common/useMountedCallbackValue';
export function useQuestionEls() {
const [questionEls, setQuestionEls] = useState(queryQuestionEls());

const questions = useMemo(() => questionEls.map((q) => q.innerText.trim() ?? ''), [questionEls]);
const questions = useMemo(
() =>
questionEls
.map((q) => q.querySelector<HTMLDivElement>('[data-message-author-role]')?.innerText)
.filter((s): s is string => !!s),
[questionEls]
);

const chatContainer = useMountedCallbackValue(queryChatContainer);

Expand Down

0 comments on commit c2d724d

Please sign in to comment.