1
- import React from 'react' ;
1
+ import React , { useEffect } from 'react' ;
2
2
import styled from 'styled-components' ;
3
3
import VelogResponsive from '../../components/velog/VelogResponsive' ;
4
4
import UserProfileContainer from '../../containers/velog/UserProfileContainer' ;
@@ -9,20 +9,34 @@ import SeriesTab from './tabs/SeriesTab';
9
9
import AboutTab from './tabs/AboutTab' ;
10
10
import palette from '../../lib/styles/palette' ;
11
11
import media from '../../lib/styles/media' ;
12
+ import UserTags from '../../components/velog/UserTags' ;
13
+ import qs from 'qs' ;
14
+ import { usePrevious } from 'react-use' ;
12
15
13
16
const UserPageBlock = styled ( VelogResponsive ) `` ;
14
17
15
18
export interface UserPageProps
16
19
extends RouteComponentProps < { username : string ; tab ?: 'series' | 'about' } > { }
17
20
18
- const UserPage : React . FC < UserPageProps > = ( { match } ) => {
21
+ const UserPage : React . FC < UserPageProps > = ( { match, location } ) => {
19
22
const { username, tab } = match . params ;
23
+ const { tag } = qs . parse ( location . search , {
24
+ ignoreQueryPrefix : true ,
25
+ } ) as { tag : string | undefined } ;
26
+
27
+ const prevTag = usePrevious ( tag ) ;
28
+ useEffect ( ( ) => {
29
+ if ( prevTag !== tag ) {
30
+ window . scrollTo ( 0 , 0 ) ;
31
+ }
32
+ } , [ prevTag , tag ] ) ;
20
33
21
34
return (
22
35
< UserPageBlock >
23
36
< UserProfileContainer username = { username } />
24
37
< MobileSeparator />
25
38
< VelogTab username = { username } tab = { tab || 'posts' } />
39
+ < UserTags username = { username } tag = { tag || null } />
26
40
< Route path = "/@:username" exact component = { UserPostsTab } />
27
41
< Route path = "/@:username/series" component = { SeriesTab } />
28
42
< Route path = "/@:username/about" component = { AboutTab } />
0 commit comments