-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mebtte
committed
Jul 3, 2023
1 parent
460a351
commit 3ff6a67
Showing
14 changed files
with
285 additions
and
28 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 was deleted.
Oops, something went wrong.
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
4 changes: 4 additions & 0 deletions
4
apps/pwa/src/pages/player/singer_modify_record_drawer/constants.ts
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 |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import getSingerModifyRecordList from '@/server/api/get_singer_modify_record_list'; | ||
|
||
export interface Singer { | ||
id: string; | ||
avatar: string; | ||
name: string; | ||
} | ||
|
||
export type ModifyRecord = AsyncReturnType<typeof getSingerModifyRecordList>[0]; |
46 changes: 46 additions & 0 deletions
46
apps/pwa/src/pages/player/singer_modify_record_drawer/content.tsx
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,46 @@ | ||
import styled from 'styled-components'; | ||
import Cover from '@/components/cover'; | ||
import getResizedImage from '@/server/asset/get_resized_image'; | ||
import useTitlebarArea from '@/utils/use_titlebar_area_rect'; | ||
import { Singer } from './constants'; | ||
import RecordList from './record_list'; | ||
|
||
const COVER_SIZE = 24; | ||
const Style = styled.div` | ||
min-height: 100vh; | ||
display: flex; | ||
flex-direction: column; | ||
> .singer { | ||
display: flex; | ||
align-items: center; | ||
padding: 5px 10px; | ||
} | ||
`; | ||
|
||
function Content({ singer }: { singer: Singer }) { | ||
const { height } = useTitlebarArea(); | ||
return ( | ||
<Style style={{ paddingTop: height }}> | ||
<div className="singer"> | ||
<Cover | ||
src={ | ||
singer.avatar | ||
? getResizedImage({ | ||
url: singer.avatar, | ||
size: COVER_SIZE * 2, | ||
}) | ||
: '' | ||
} | ||
size={COVER_SIZE} | ||
/> | ||
<div className="name">{singer.name}</div> | ||
</div> | ||
<RecordList singerId={singer.id} /> | ||
</Style> | ||
); | ||
} | ||
|
||
export default Content; |
23 changes: 23 additions & 0 deletions
23
apps/pwa/src/pages/player/singer_modify_record_drawer/hint.tsx
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,23 @@ | ||
import styled from 'styled-components'; | ||
import { SINGER_MODIFY_RECORD_TTL } from '#/constants'; | ||
import { CSSVariable } from '@/global_style'; | ||
|
||
const Style = styled.div` | ||
padding: 10px; | ||
font-size: 12px; | ||
color: ${CSSVariable.TEXT_COLOR_SECONDARY}; | ||
text-align: center; | ||
`; | ||
|
||
function Hint() { | ||
return ( | ||
<Style> | ||
歌手修改记录保留时间为 | ||
{SINGER_MODIFY_RECORD_TTL / (1000 * 60 * 60 * 24)} | ||
天 | ||
</Style> | ||
); | ||
} | ||
|
||
export default Hint; |
122 changes: 122 additions & 0 deletions
122
apps/pwa/src/pages/player/singer_modify_record_drawer/record_list.tsx
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,122 @@ | ||
import styled from 'styled-components'; | ||
import { flexCenter } from '@/style/flexbox'; | ||
import ErrorCard from '@/components/error_card'; | ||
import Spinner from '@/components/spinner'; | ||
import day from '#/utils/day'; | ||
import { AllowUpdateKey } from '#/constants/singer'; | ||
import { CSSVariable } from '@/global_style'; | ||
import Empty from '@/components/empty'; | ||
import useModifyRecordList from './use_modify_record_list'; | ||
import playerEventemitter, { | ||
EventType as PlayerEventType, | ||
} from '../eventemitter'; | ||
|
||
const KEY_MAP_LABEL: Record<AllowUpdateKey, string> = { | ||
[AllowUpdateKey.AVATAR]: '头像', | ||
[AllowUpdateKey.NAME]: '名字', | ||
[AllowUpdateKey.ALIASES]: '别名', | ||
}; | ||
const Root = styled.div` | ||
flex: 1; | ||
min-height: 0; | ||
`; | ||
const CardContainer = styled(Root)` | ||
${flexCenter} | ||
`; | ||
const Style = styled(Root)` | ||
> .record { | ||
margin: 0 20px; | ||
padding: 5px 10px; | ||
position: relative; | ||
border-left: 1px solid ${CSSVariable.BACKGROUND_COLOR_LEVEL_THREE}; | ||
> .time { | ||
font-size: 12px; | ||
color: ${CSSVariable.TEXT_COLOR_SECONDARY}; | ||
} | ||
> .description { | ||
font-size: 14px; | ||
color: ${CSSVariable.TEXT_COLOR_PRIMARY}; | ||
> .user { | ||
color: ${CSSVariable.COLOR_PRIMARY}; | ||
cursor: pointer; | ||
} | ||
> .key { | ||
text-decoration: underline; | ||
} | ||
} | ||
&::after { | ||
content: ''; | ||
--size: 8px; | ||
position: absolute; | ||
top: calc(50% - var(--size) / 2); | ||
left: calc(var(--size) / 2 * -1); | ||
width: var(--size); | ||
height: var(--size); | ||
border-radius: 50%; | ||
border: 1px solid ${CSSVariable.COLOR_PRIMARY}; | ||
} | ||
} | ||
`; | ||
|
||
function RecordList({ singerId }: { singerId: string }) { | ||
const { data, reload } = useModifyRecordList({ singerId }); | ||
|
||
if (data.error) { | ||
return ( | ||
<CardContainer> | ||
<ErrorCard errorMessage={data.error.message} retry={reload} /> | ||
</CardContainer> | ||
); | ||
} | ||
if (data.loading) { | ||
return ( | ||
<CardContainer> | ||
<Spinner /> | ||
</CardContainer> | ||
); | ||
} | ||
if (!data.value.length) { | ||
return ( | ||
<CardContainer> | ||
<Empty description="暂无修改记录" /> | ||
</CardContainer> | ||
); | ||
} | ||
return ( | ||
<Style> | ||
{data.value.map((record) => ( | ||
<div key={record.id} className="record"> | ||
<div className="time"> | ||
{day(record.modifyTimestamp).format('YYYY-MM-DD HH:mm')} | ||
</div> | ||
<div className="description"> | ||
<span | ||
className="user" | ||
onClick={() => | ||
playerEventemitter.emit(PlayerEventType.OPEN_USER_DRAWER, { | ||
id: record.modifyUserId, | ||
}) | ||
} | ||
> | ||
{record.modifyUserNickname} | ||
</span> | ||
修改了 | ||
<span className="key"> | ||
{KEY_MAP_LABEL[record.key] || record.key} | ||
</span> | ||
</div> | ||
</div> | ||
))} | ||
</Style> | ||
); | ||
} | ||
|
||
export default RecordList; |
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,42 @@ | ||
import { useCallback, useEffect, useState } from 'react'; | ||
import getSingerModifyRecordList from '@/server/api/get_singer_modify_record_list'; | ||
import { ModifyRecord } from './constants'; | ||
|
||
type Data = | ||
| { error: null; loading: true; value: null } | ||
| { | ||
error: Error; | ||
loading: false; | ||
value: null; | ||
} | ||
| { | ||
error: null; | ||
loading: false; | ||
value: ModifyRecord[]; | ||
}; | ||
const dataLoading: Data = { | ||
error: null, | ||
loading: true, | ||
value: null, | ||
}; | ||
|
||
export default ({ singerId }: { singerId: string }) => { | ||
const [data, setData] = useState<Data>(dataLoading); | ||
const getModifyRecordList = useCallback(async () => { | ||
setData(dataLoading); | ||
try { | ||
const modifyRecordList = await getSingerModifyRecordList({ | ||
id: singerId, | ||
}); | ||
setData({ error: null, loading: false, value: modifyRecordList }); | ||
} catch (error) { | ||
setData({ error, loading: false, value: null }); | ||
} | ||
}, [singerId]); | ||
|
||
useEffect(() => { | ||
getModifyRecordList(); | ||
}, [getModifyRecordList]); | ||
|
||
return { data, reload: getModifyRecordList }; | ||
}; |
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
Oops, something went wrong.