-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add RecommendDaily page ui and logic
- Loading branch information
Showing
10 changed files
with
201 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import React from 'react' | ||
import { Spinner } from '@blueprintjs/core' | ||
|
||
import MusicList from 'components/MusicList' | ||
import songApis from 'apis/song' | ||
import useAsyncFn from 'hooks/useAsyncFn' | ||
import { getDay, getWeekday } from 'helpers/time' | ||
import { createMusic } from 'helpers/business' | ||
import { getSession } from 'helpers/session' | ||
import { PlayMusicDispatchContext, ACTIONS } from 'reducers/playMusic' | ||
import { IMusic } from 'apis/types/business' | ||
import styles from './style.module.css' | ||
|
||
const { useEffect, useContext } = React | ||
|
||
const RecommendDaily = () => { | ||
const dispatch = useContext(PlayMusicDispatchContext) | ||
const [state, getRecommendSongsFn] = useAsyncFn(songApis.getRecommendSongs) | ||
const session = getSession() | ||
const isLogined = !!session.userId | ||
|
||
useEffect(() => { | ||
if (isLogined) { | ||
getRecommendSongsFn() | ||
} | ||
}, [isLogined]) | ||
|
||
const playAll = (autoPlay?: boolean) => { | ||
dispatch({ | ||
type: ACTIONS.SET_PLAY_LIST, | ||
payload: { | ||
playList: state.value | ||
} | ||
}) | ||
|
||
if (autoPlay) { | ||
const item = state.value?.[0] as IMusic | ||
dispatch({ | ||
type: ACTIONS.PLAY, | ||
payload: { | ||
musicId: item.id, | ||
music: createMusic({ | ||
...item, | ||
picUrl: item.album?.blurPicUrl, | ||
duration: item.duration / 1000 | ||
}) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
return ( | ||
<div className={styles.root}> | ||
<div className={styles.header}> | ||
<div className={styles.left}> | ||
<div className={styles.date}> | ||
<div className={styles.weekday}>{getWeekday()}</div> | ||
<div className={styles.day}>{getDay()}</div> | ||
</div> | ||
<div className={styles.title}> | ||
<div className={styles.name}>每日歌曲推荐</div> | ||
<div className={styles.tips}>根据你的音乐口味生成,每天6:00更新</div> | ||
</div> | ||
</div> | ||
|
||
{isLogined && ( | ||
<div | ||
className='playAll' | ||
onClick={() => playAll(true)} | ||
> | ||
播放全部 | ||
</div> | ||
)} | ||
</div> | ||
|
||
{isLogined ? ( | ||
<div className={styles.content}> | ||
{state.loading ? <Spinner className='spinner' /> : ( | ||
<MusicList | ||
data={state.value || []} | ||
onPlayAll={() => playAll()} | ||
/> | ||
)} | ||
</div> | ||
) : ( | ||
<div className={styles.needLogin}>请先登录喔~</div> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export default RecommendDaily |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
@value colors: "~styles/colors.module.css"; | ||
@value red, borderColor, nameColor from colors; | ||
|
||
.root { | ||
padding: 20px 0 50px; | ||
} | ||
|
||
.header { | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
padding-bottom: 20px; | ||
border-bottom: 1px solid borderColor; | ||
} | ||
|
||
.left { | ||
display: flex; | ||
} | ||
|
||
.date { | ||
width: 100px; | ||
height: 100px; | ||
margin-right: 15px; | ||
background-color: rgba(0, 0, 0, 0.5); | ||
border-radius: 5px; | ||
border-top-left-radius: 5px; | ||
border: 1px solid borderColor; | ||
box-shadow: 0 1px 5px 2px borderColor; | ||
|
||
.weekday { | ||
padding: 5px 0; | ||
text-align: center; | ||
background-color: red; | ||
border-top-left-radius: 5px; | ||
border-top-right-radius: 5px; | ||
color: #fff; | ||
} | ||
|
||
.day { | ||
padding: 12px 0; | ||
font-size: 2.5em; | ||
font-weight: bold; | ||
text-align: center; | ||
background-color: #fff; | ||
border-bottom-left-radius: 5px; | ||
border-bottom-right-radius: 5px; | ||
} | ||
} | ||
|
||
.title { | ||
.name { | ||
margin: 10px 0 15px; | ||
font-size: 1.5em; | ||
} | ||
|
||
.tips { | ||
color: nameColor; | ||
} | ||
} | ||
|
||
.needLogin { | ||
margin-top: 100px; | ||
text-align: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters