@@ -18,6 +18,10 @@ import { MarkdownPreviewer } from "@osn/previewer";
1818import PostBanner from "@/components/postDetail/postBanner" ;
1919import { isSameAddress } from "frontedUtils/address" ;
2020import { isCollectiveSpace } from "frontedUtils/space" ;
21+ import { ArrowCaretLeft } from "@osn/icons/opensquare" ;
22+ import { useCallback , useEffect , useRef , useState } from "react" ;
23+ import debounce from "lodash.debounce" ;
24+ import { cn } from "@osn/common-ui" ;
2125
2226const Title = styled . div `
2327 ${ p_semibold } ;
@@ -79,7 +83,7 @@ export default function PostContent({ data, space }) {
7983
8084 return (
8185 < Panel >
82- < Title > { data ?. title } </ Title >
86+ < TitleContent title = { data ?. title } / >
8387 < InfoWrapper >
8488 < LeftWrapper >
8589 < Author
@@ -122,3 +126,43 @@ export default function PostContent({ data, space }) {
122126 </ Panel >
123127 ) ;
124128}
129+
130+ const TitleContent = ( { title } ) => {
131+ const [ scrollY , setScrollY ] = useState ( 0 ) ;
132+ const debouncedScrollHandler = useRef ( null ) ;
133+ const handleScroll = useCallback ( ( ) => {
134+ setScrollY ( window . scrollY ) ;
135+ } , [ ] ) ;
136+
137+ useEffect ( ( ) => { } , [ handleScroll ] ) ;
138+
139+ useEffect ( ( ) => {
140+ debouncedScrollHandler . current = debounce ( handleScroll , 10 ) ;
141+ window . addEventListener ( "scroll" , debouncedScrollHandler . current ) ;
142+ return ( ) => {
143+ if ( debouncedScrollHandler . current ) {
144+ debouncedScrollHandler . current . cancel ( ) ;
145+ window . removeEventListener ( "scroll" , debouncedScrollHandler . current ) ;
146+ }
147+ } ;
148+ } , [ handleScroll ] ) ;
149+
150+ return (
151+ < >
152+ < Title > { title } </ Title >
153+ < div
154+ className = { cn (
155+ "fixed py-5 z-10 top-0 transform -translate-y-full left-0 w-full bg-fillBgPrimary border border-strokeBorderDefault shadow-shadowCardDefault" ,
156+ scrollY > 180 && "translate-y-0" ,
157+ ) }
158+ >
159+ < div className = "max-w-[1144px] mx-auto md:px-8 px-5 flex relative" >
160+ < ArrowCaretLeft className = "w-8 h-8 p-1 md:ml-8 ml-5 rounded-full border shadow absolute left-0 -translate-x-1/2 " />
161+ < div className = "px-8 font-[700] text-base md:font-[600] md:text-[20px]" >
162+ { title }
163+ </ div >
164+ </ div >
165+ </ div >
166+ </ >
167+ ) ;
168+ } ;
0 commit comments