Skip to content

Commit 1decc4e

Browse files
authored
Merge pull request #8 from summerscar/master
✨feat(视频页): 增加tag筛选功能
2 parents 7bf3591 + 01c6601 commit 1decc4e

File tree

3 files changed

+108
-96
lines changed

3 files changed

+108
-96
lines changed

src/pages/projects/index.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export const VideoRow = function ({title, videos, ...props}) {
8383
}
8484
}); // lazy loads elements with default selector as '.lozad'
8585
observer.observe();
86-
})
86+
}, [videos])
8787

8888
return (
8989
<div className="margin-top--log margin-bottom--log">
@@ -94,7 +94,7 @@ export const VideoRow = function ({title, videos, ...props}) {
9494
<div className="row">
9595
{
9696
videos.map((video, index) => (
97-
<div className={clsx('col col--6')} key={index}>
97+
<div className={clsx('col col--6')} key={video.title}>
9898
<div>
9999
<video
100100
type="video/mp4"
@@ -142,12 +142,17 @@ export const VideoRow = function ({title, videos, ...props}) {
142142
)
143143
}
144144

145+
const tags = ['全部', '魔法', 'DynamicTable', '机器人', '物联网', '开源硬件']
146+
145147
function Projects() {
146148
const context = useDocusaurusContext();
149+
const [currentTag, setCurrentTag] = useState('全部')
147150
const {siteConfig = {}} = context;
151+
148152
useLayoutEffect(() => {
149153
window.$(".stack").lettering();
150154
}, [])
155+
151156
return (
152157
<Layout title="Projects">
153158
{/*
@@ -159,17 +164,21 @@ function Projects() {
159164
</div>
160165
<div className={clsx(styles.navContainer)}>
161166
<div className={clsx(styles.filter)}>
162-
<button className={clsx(styles.tag1)}>全部</button>
163-
<button className={clsx(styles.tags)}>魔法</button>
164-
<button className={clsx(styles.tags)}>DynamicTable</button>
165-
<button className={clsx(styles.tags)}>机器人</button>
166-
<button className={clsx(styles.tags)}>物联网</button>
167-
<button className={clsx(styles.tags)}>开源硬件</button>
167+
{
168+
tags.map(tag => (
169+
<button
170+
className={clsx(styles.tag, currentTag === tag && styles.tagActive)}
171+
onClick={() => setCurrentTag(tag)}
172+
>
173+
{ tag }
174+
</button>)
175+
)
176+
}
168177
</div>
169178
</div>
170179
<main className={clsx(styles.newContainer)}>
171-
<VideoRow title="" videos={videos['横版视频']}/>
172-
<VideoRow title="" videos={videos['竖版视频']}/>
180+
<VideoRow title="" videos={videos['横版视频'].filter(video => currentTag === '全部' || video.tags.includes(currentTag))}/>
181+
<VideoRow title="" videos={videos['竖版视频'].filter(video => currentTag === '全部' || video.tags.includes(currentTag))}/>
173182
</main>
174183
</div>
175184
</Layout>

src/pages/projects/styles.module.css

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
padding-top: 1rem;
2525
}
2626
*/
27-
27+
2828
/*
2929
.triangle_top {
30-
30+
3131
border-style: solid;
3232
border-width: 60px 50vw 0;
3333
color: #ffb81e;
@@ -38,7 +38,7 @@
3838

3939

4040
.mainPage {
41-
background-color: black!important;
41+
background-color: black!important;
4242
/*
4343
background-image: radial-gradient(circl,#0a0a0a,black);
4444
*/
@@ -145,17 +145,20 @@
145145
justify-content: center;
146146
}
147147

148-
.tags {
148+
.tag {
149149
color: white;
150150
padding: 0.5rem 1rem;
151151
border: solid white 1.5px;
152152
border-radius: 2.5rem;
153153
margin:0 1rem;
154154
background-color:black;
155155
font-size:1.5rem;
156+
outline: none;
157+
cursor: pointer;
156158
}
157159

158-
.tag1 {
160+
.tagActive {
161+
outline: none;
159162
color: white;
160163
padding: 0.5rem 1rem;
161164
border: solid white 1.5px;

0 commit comments

Comments
 (0)