@@ -21,7 +21,7 @@ interface PageContentProps {
2121}
2222export function PageContent ( props : PageContentProps ) {
2323 const { setSidebarMdContent } = useSidebarMdContext ( ) ;
24-
24+
2525 // SSR用のローカルstate
2626 const [ dynamicMdContent , setDynamicMdContent ] = useState <
2727 DynamicMarkdownSection [ ]
@@ -52,18 +52,22 @@ export function PageContent(props: PageContentProps) {
5252
5353 useEffect ( ( ) => {
5454 const handleScroll = ( ) => {
55- const updateContent = ( prevDynamicMdContent : DynamicMarkdownSection [ ] ) => {
55+ const updateContent = (
56+ prevDynamicMdContent : DynamicMarkdownSection [ ]
57+ ) => {
5658 const dynMdContent = prevDynamicMdContent . slice ( ) ; // Reactの変更検知のために新しい配列を作成
5759 for ( let i = 0 ; i < sectionRefs . current . length ; i ++ ) {
5860 if ( sectionRefs . current . at ( i ) && dynMdContent . at ( i ) ) {
5961 const rect = sectionRefs . current . at ( i ) ! . getBoundingClientRect ( ) ;
62+ console . log ( i , rect ) ;
6063 dynMdContent . at ( i ) ! . inView =
61- rect . top < window . innerHeight && rect . bottom >= 0 ;
64+ rect . top < window . innerHeight * 0.9 &&
65+ rect . bottom >= window . innerHeight * 0.1 ;
6266 }
6367 }
6468 return dynMdContent ;
6569 } ;
66-
70+
6771 // ローカルstateとcontextの両方を更新
6872 setDynamicMdContent ( updateContent ) ;
6973 setSidebarMdContent ( props . docs_id , updateContent ) ;
@@ -102,8 +106,9 @@ export function PageContent(props: PageContentProps) {
102106 </ div >
103107 < div key = { `${ index } -chat` } >
104108 { /* 右側に表示するチャット履歴欄 */ }
105- { chatHistories . filter ( ( c ) => c . sectionId === section . sectionId ) . map (
106- ( { chatId, messages} ) => (
109+ { chatHistories
110+ . filter ( ( c ) => c . sectionId === section . sectionId )
111+ . map ( ( { chatId, messages } ) => (
107112 < div
108113 key = { chatId }
109114 className = "max-w-xs mb-2 p-2 text-sm border border-base-content/10 rounded-sm shadow-sm bg-base-100"
@@ -131,8 +136,7 @@ export function PageContent(props: PageContentProps) {
131136 ) ) }
132137 </ div >
133138 </ div >
134- )
135- ) }
139+ ) ) }
136140 </ div >
137141 </ >
138142 ) ) }
0 commit comments