1
- import React from 'react' ;
1
+ import React , { useEffect } from 'react' ;
2
2
import UserPosts from '../../../containers/velog/UserPosts' ;
3
3
import { RouteComponentProps } from 'react-router' ;
4
4
import qs from 'qs' ;
@@ -8,6 +8,8 @@ import styled from 'styled-components';
8
8
import media from '../../../lib/styles/media' ;
9
9
import usePreserveScroll from '../../../lib/hooks/usePreserveScroll' ;
10
10
import { Helmet } from 'react-helmet-async' ;
11
+ import { usePrevious } from 'react-use' ;
12
+ import UserTags from '../../../components/velog/UserTags' ;
11
13
12
14
export interface UserPostsTabProps
13
15
extends RouteComponentProps < { username : string } > {
@@ -32,8 +34,15 @@ const UserPostsTab: React.FC<UserPostsTabProps> = ({
32
34
const { username } = match . params ;
33
35
usePreserveScroll ( 'user/posts' ) ;
34
36
37
+ const prevTag = usePrevious ( tag ) ;
38
+ useEffect ( ( ) => {
39
+ if ( prevTag !== tag ) {
40
+ window . scrollTo ( 0 , 0 ) ;
41
+ }
42
+ } , [ prevTag , tag ] ) ;
43
+
35
44
return (
36
- < >
45
+ < div >
37
46
< HideOnMobile >
38
47
< Helmet >
39
48
< link
@@ -49,14 +58,17 @@ const UserPostsTab: React.FC<UserPostsTabProps> = ({
49
58
username = { match . params . username }
50
59
/>
51
60
</ HideOnMobile >
61
+ < TagWrapper >
62
+ < UserTags username = { username } tag = { tag || null } />
63
+ </ TagWrapper >
52
64
< Block >
53
65
{ q ? (
54
66
< SearchResult username = { username } keyword = { q } />
55
67
) : (
56
68
< UserPosts username = { match . params . username } tag = { tag || null } />
57
69
) }
58
70
</ Block >
59
- </ >
71
+ </ div >
60
72
) ;
61
73
} ;
62
74
@@ -73,4 +85,7 @@ const Block = styled.div`
73
85
}
74
86
` ;
75
87
88
+ const TagWrapper = styled . div `
89
+ position: relative;
90
+ ` ;
76
91
export default UserPostsTab ;
0 commit comments