Commit 1167b821 authored by raca's avatar raca

feat: 调接口

parent 3dea30a8
import { requestAfterSilentLogin } from '@/utils/request'
export type PkParams = {
stageId?: number,
userId?: number,
}
export type PkDetails = {
allPkNum: number,
errNum: number,
nickName: string,
resultTime: number,
stageId: number,
stageName: string,
userId: number,
userRanks: {
level: string,
star: number
},
winPkNum: number
}
export function fetchUserDetails (data: PkParams) {
return requestAfterSilentLogin<PkDetails, PkParams>((userInfo) => ({
method: 'GET',
url: '/service-idea/pk/personal/stage/detail',
data: {
stageId: data.stageId,
userId: data.userId || userInfo?.userId,
}
}))
}
export type PkRecord = {
createTime: string;
id: number,
initiator: number,
initiatorAvatar: string,
initiatorErrNum: number,
initiatorName: string,
initiatorResultTime: number,
prizeReceive: string,
recipient: number,
recipientAvatar: string,
recipientErrNum: number,
recipientName: string,
recipientResultTime: number,
result: string,
stageName: string
}
export type PkRecords = {
records: PkRecord[]
} & Pick<PkDetails, 'allPkNum' | 'userRanks' | 'winPkNum'>
export function fetchUserRecords (data: PkParams) {
return requestAfterSilentLogin<PkRecords, PkParams>((userInfo) => ({
method: 'GET',
url: '/service-idea/pk/personal/stage/records',
data: {
stageId: data.stageId,
userId: data.userId || userInfo?.userId,
}
}))
}
...@@ -71,7 +71,7 @@ const ModalName = ({ ...@@ -71,7 +71,7 @@ const ModalName = ({
/> />
<View className={styles.title}>请问大侠,尊姓大名</View> <View className={styles.title}>请问大侠,尊姓大名</View>
<View className={styles.tips}> <View className={styles.tips}>
请输入您的角色名(7字以内)或随机生成 请输入您的角色名(7字以内)
</View> </View>
<View className={styles.input}> <View className={styles.input}>
<View className={styles.inputName}>{name}</View> <View className={styles.inputName}>{name}</View>
......
import { useDidShow, useRouter } from '@tarojs/taro'
import { View, Image, Text } from '@tarojs/components' import { View, Image, Text } from '@tarojs/components'
import { useBoolean } from '@/hooks' import { useBoolean } from '@/hooks'
import { useStoreState, useStoreActions } from '@/store/hooks'
import assetsPk from '@/assets/oss/assets-pk' import assetsPk from '@/assets/oss/assets-pk'
import assetsMainNext from '@/assets/oss/assets-main-next' import assetsMainNext from '@/assets/oss/assets-main-next'
import { badgeImages } from '../battles/const' import { badgeImages } from '../battles/const'
...@@ -9,6 +11,21 @@ import ModalName from './components/modal-name' ...@@ -9,6 +11,21 @@ import ModalName from './components/modal-name'
const AcceptPk = () => { const AcceptPk = () => {
const [isVisible, { setTrue, setFalse }] = useBoolean(false) const [isVisible, { setTrue, setFalse }] = useBoolean(false)
const router = useRouter<{ initiator?: string; stageId?: string }>()
const details = useStoreState((state) => state.battlesModel.details)
const fetchUserDetails = useStoreActions(
(actions) => actions.battlesModel.fetchUserDetails
)
useDidShow(async () => {
if (router.params.initiator && router.params.stageId) {
await fetchUserDetails({
userId: +router.params.initiator,
stageId: +router.params.stageId,
})
}
})
return ( return (
<View className={styles.container}> <View className={styles.container}>
...@@ -22,7 +39,10 @@ const AcceptPk = () => { ...@@ -22,7 +39,10 @@ const AcceptPk = () => {
style={{ left: 0 }} style={{ left: 0 }}
src={assetsMainNext['pk-flash.png'].u} src={assetsMainNext['pk-flash.png'].u}
/> />
<Image className={styles.pk} src={assetsMainNext['pk-logo.png'].u} /> <Image
className={styles.pk}
src={assetsMainNext['pk-logo.png'].u}
/>
<Image <Image
className={styles.flash} className={styles.flash}
style={{ right: 0 }} style={{ right: 0 }}
...@@ -39,11 +59,13 @@ const AcceptPk = () => { ...@@ -39,11 +59,13 @@ const AcceptPk = () => {
<View className={styles.inner}> <View className={styles.inner}>
<View className={styles.userSection}> <View className={styles.userSection}>
<Text className={styles.userName}>用户名称用户名</Text> <Text className={styles.userName}>
{details?.nickName || '-'}
</Text>
<Text className={styles.challenge}>向你发起挑战</Text> <Text className={styles.challenge}>向你发起挑战</Text>
</View> </View>
<Text>关卡-连加连减</Text> <Text>关卡-{details?.stageName}</Text>
<Image <Image
className={styles.avatar} className={styles.avatar}
...@@ -56,10 +78,15 @@ const AcceptPk = () => { ...@@ -56,10 +78,15 @@ const AcceptPk = () => {
src={assetsPk[badgeImages.bronze.default].u} src={assetsPk[badgeImages.bronze.default].u}
className={styles.badgeIcon} className={styles.badgeIcon}
/> />
<Text className={styles.rankText}>青铜</Text> <Text className={styles.rankText}>
{details?.userRanks.level}
</Text>
</View> </View>
<Text>当前战绩:胜 2 负 3</Text> <Text>
<Text>最佳表现:全对 | 29.3s</Text> 当前战绩:胜 {details?.winPkNum || 0} 负
{(details?.allPkNum || 0) - (details?.winPkNum || 0)}
</Text>
<Text>最佳表现:全对 | {details?.resultTime || 0}s</Text>
</View> </View>
</View> </View>
</View> </View>
......
...@@ -80,6 +80,7 @@ ...@@ -80,6 +80,7 @@
.gameResult { .gameResult {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
text-align: center;
gap: 16px; gap: 16px;
max-height: 500px; max-height: 500px;
} }
...@@ -112,3 +113,9 @@ ...@@ -112,3 +113,9 @@
.lose { .lose {
background-color: #FEEDED; background-color: #FEEDED;
} }
.emptyText {
margin-top: 48px;
font-size: 14PX;
color: rgba(70, 81, 100, 0.50);
}
\ No newline at end of file
import { useEffect } from 'react'
import { View, Text, Image, ScrollView } from '@tarojs/components' import { View, Text, Image, ScrollView } from '@tarojs/components'
import classNames from 'classnames' import classNames from 'classnames'
import Modal from '@/components/Modal' import Modal from '@/components/Modal'
...@@ -12,31 +13,19 @@ import gameResultStyles from './game-result.module.scss' ...@@ -12,31 +13,19 @@ import gameResultStyles from './game-result.module.scss'
const BattlesModal = () => { const BattlesModal = () => {
const isVisible = useStoreState(state => state.battlesModel.modalIsVisible) const isVisible = useStoreState(state => state.battlesModel.modalIsVisible)
const setModalIsVisible = useStoreActions(actions => actions.battlesModel.setModalIsVisible) const setModalIsVisible = useStoreActions(actions => actions.battlesModel.setModalIsVisible)
const details = useStoreState((state) => state.battlesModel.details)
const records = useStoreState((state) => state.battlesModel.records)
const levelInfo = { const fetchUserDetails = useStoreActions(
name: '关卡', (actions) => actions.battlesModel.fetchUserDetails
result: true, )
date: '9月22日 12:22', const fetchUserRecords = useStoreActions(
} (actions) => actions.battlesModel.fetchUserRecords
)
const levelInfo2 = {
name: '关卡名称关卡名称',
result: false,
date: '9月22日 12:22',
}
const players = [ useEffect(() => {
{ Promise.allSettled([fetchUserDetails({}), fetchUserRecords({})])
name: '用户名称用', }, [fetchUserDetails, fetchUserRecords])
icon: 'string',
level: '青铜Ⅰ',
},
{
name: '用户2',
icon: 'string',
level: '青铜Ⅰ',
},
]
return ( return (
<Modal <Modal
...@@ -65,55 +54,60 @@ const BattlesModal = () => { ...@@ -65,55 +54,60 @@ const BattlesModal = () => {
className={styles.badgeIcon} className={styles.badgeIcon}
/> />
<View className={styles.detailsRight}> <View className={styles.detailsRight}>
<Text className={styles.badgeText}>青铜 1</Text> <Text className={styles.badgeText}>
{details?.userRanks.level || '-'}
</Text>
<View className={styles.badgeBar}> <View className={styles.badgeBar}>
{[...Array(3)].map((_, index) => (
<Text <Text
className={classNames(styles.badgeBarItem, styles.active)} key={index}
className={classNames(
styles.badgeBarItem,
index < (details?.userRanks.star || 0) ? styles.active : null
)}
></Text> ></Text>
<Text className={classNames(styles.badgeBarItem)}></Text> ))}
<Text className={classNames(styles.badgeBarItem)}></Text>
</View> </View>
</View> </View>
</View> </View>
<ScrollView className={styles.gameResult} scrollY> <ScrollView className={styles.gameResult} scrollY>
<GameResult levelInfo={levelInfo} players={players} /> {records.length > 0
<GameResult levelInfo={levelInfo2} players={players} /> ? records.map((item) => <GameResult key={item.id} record={item} />)
<GameResult levelInfo={levelInfo} players={players} /> : <Text className={styles.emptyText}>暂无PK记录</Text>
<GameResult levelInfo={levelInfo2} players={players} /> }
<GameResult levelInfo={levelInfo} players={players} />
</ScrollView> </ScrollView>
</View> </View>
</Modal> </Modal>
) )
} }
const GameResult = ({ players, levelInfo }: GameResultProps) => { const GameResult = ({ record }: GameResultProps) => {
return ( return (
<View className={gameResultStyles.gameResult}> <View className={gameResultStyles.gameResult}>
<View <View
className={classNames( className={classNames(
gameResultStyles.levelInfo, gameResultStyles.levelInfo,
levelInfo.result ? gameResultStyles.win : gameResultStyles.lose record.result ? gameResultStyles.win : gameResultStyles.lose
)} )}
> >
<Text className={gameResultStyles.levelName}>{levelInfo.name}</Text> <Text className={gameResultStyles.levelName}>{record.stageName}</Text>
<Image <Image
mode="widthFix" mode="widthFix"
src={levelInfo.result ? assets['win.png'].u : assets['lose.png'].u} src={record.result ? assets['win.png'].u : assets['lose.png'].u}
className={gameResultStyles.levelResult} className={gameResultStyles.levelResult}
/> />
<Text className={gameResultStyles.levelDate}>{levelInfo.date}</Text> <Text className={gameResultStyles.levelDate}>{record.createTime}</Text>
</View> </View>
<View className={styles.gameBody}> <View className={styles.gameBody}>
<View className={styles.playerSection}> <View className={styles.playerSection}>
<View className={classNames(styles.userInfo, levelInfo.result ? styles.win : styles.lose)}> <View className={classNames(styles.userInfo, record.result ? styles.win : styles.lose)}>
<UserInfo {...players[0]} /> <UserInfo name={record.initiatorName} />
</View> </View>
<Image className={gameResultStyles.vs} src={assets['vs.png'].u} /> <Image className={gameResultStyles.vs} src={assets['vs.png'].u} />
<View className={classNames(styles.userInfo, !levelInfo.result ? styles.win : styles.lose)}> <View className={classNames(styles.userInfo, !record.result ? styles.win : styles.lose)}>
<UserInfo style={{ alignItems: 'flex-end' }} {...players[1]} /> <UserInfo style={{ alignItems: 'flex-end' }} name={record.recipientName} />
</View> </View>
</View> </View>
</View> </View>
......
...@@ -3,71 +3,96 @@ import { View, Text, Image } from '@tarojs/components' ...@@ -3,71 +3,96 @@ import { View, Text, Image } from '@tarojs/components'
import classNames from 'classnames' import classNames from 'classnames'
import assets from '@/assets/oss/assets-pk' import assets from '@/assets/oss/assets-pk'
import assets2 from '@/assets/oss/assets-prepare' import assets2 from '@/assets/oss/assets-prepare'
import { PkRecord } from '@/api/pk'
import { badgeImages } from '../const' import { badgeImages } from '../const'
import styles from './game-result.module.scss' import styles from './game-result.module.scss'
export interface LevelInfo {
name: string;
result: boolean;
date: string;
}
interface Player {
name: string;
icon: string;
level: string;
}
interface Stat {
score: string;
label: string;
value: string;
}
export interface GameResultProps { export interface GameResultProps {
levelInfo: LevelInfo; record: PkRecord
players: Player[];
gameStats?: Stat[];
} }
const GameResult = ({ players, levelInfo }: GameResultProps) => { const GameResult = ({ record }: GameResultProps) => {
return ( return (
<View className={styles.gameResult}> <View className={styles.gameResult}>
<View className={classNames(styles.levelInfo, levelInfo.result ? styles.win : styles.lose)}> <View
<Text className={styles.levelName}>{levelInfo.name}</Text> className={classNames(
<Image mode="widthFix" src={assets[levelInfo.result ? 'win.png' : 'lose.png'].u} className={styles.levelResult} /> styles.levelInfo,
<Text className={styles.levelDate}>{levelInfo.date}</Text> record.result ? styles.win : styles.lose
)}
>
<Text className={styles.levelName}>{record.stageName}</Text>
<Image
mode="widthFix"
src={assets[record.result ? 'win.png' : 'lose.png'].u}
className={styles.levelResult}
/>
<Text className={styles.levelDate}>{record.createTime}</Text>
</View> </View>
<View className={styles.gameBody}> <View className={styles.gameBody}>
<View className={styles.playerSection}> <View className={styles.playerSection}>
<UserInfo {...players[0]} /> <UserInfo name={record.initiatorName} />
<Image className={styles.vs} src={assets['vs.png'].u} /> <Image className={styles.vs} src={assets['vs.png'].u} />
<UserInfo style={{ alignItems: 'flex-end' }} {...players[1]} /> <UserInfo
style={{ alignItems: 'flex-end' }}
name={record.recipientName}
/>
</View> </View>
<GameStats result={levelInfo.result} /> <GameStats
result={record.result}
initiator={{
err: record.initiatorErrNum,
time: record.initiatorResultTime,
}}
recipient={{
err: record.recipientErrNum,
time: record.recipientResultTime,
}}
/>
</View> </View>
</View> </View>
) )
} }
export const UserInfo = (player: Player & { style?: CSSProperties }) => ( export const UserInfo = (user: { name: string; style?: CSSProperties }) => (
<View style={player.style} className={styles.userInfo}> <View style={user.style} className={styles.userInfo}>
<Text className={styles.userName}>{player.name}</Text> <Text className={styles.userName}>{user.name}</Text>
<View className={styles.userBadge}> <View className={styles.userBadge}>
<Image className={styles.userIcon} src={assets[badgeImages.diamond.small].u} /> <Image
<Text className={styles.userLevel}>{player.level}</Text> className={styles.userIcon}
src={assets[badgeImages.diamond.small].u}
/>
<Text className={styles.userLevel}>{user.name}</Text>
</View> </View>
</View> </View>
) )
const GameStats = ({ result }: { result: boolean }) => { export type StatParams = {
result: boolean | string
initiator: {
err: number
time: number
}
recipient: {
err: number
time: number
}
}
const GameStats = ({ initiator, recipient, result }: StatParams) => {
return ( return (
<View className={styles.gameStats}> <View className={styles.gameStats}>
<View className={classNames(styles.stats, result ? styles.statsWin : styles.statsLose)}> <View
<Text className={styles.value}>全队</Text> className={classNames(
<Text className={styles.value}>13.2s</Text> styles.stats,
result ? styles.statsWin : styles.statsLose
)}
>
<Text className={styles.value}>
{initiator.err > 0 ? `错${initiator.err}题` : '全对'}
</Text>
<Text className={styles.value}>{initiator.time}s</Text>
<View className={classNames(styles.value)}> <View className={classNames(styles.value)}>
<Image className={styles.diamond} src={assets2['diamond.png'].u} /> <Image className={styles.diamond} src={assets2['diamond.png'].u} />
<Text>+10</Text> <Text>+10</Text>
...@@ -78,9 +103,16 @@ const GameStats = ({ result }: { result: boolean }) => { ...@@ -78,9 +103,16 @@ const GameStats = ({ result }: { result: boolean }) => {
<Text className={styles.value}>答题用时</Text> <Text className={styles.value}>答题用时</Text>
<Text className={styles.value}>PK奖励</Text> <Text className={styles.value}>PK奖励</Text>
</View> </View>
<View className={classNames(styles.stats, !result ? styles.statsWin : styles.statsLose)}> <View
<Text className={styles.value}>错2题</Text> className={classNames(
<Text className={styles.value}>23.2s</Text> styles.stats,
!result ? styles.statsWin : styles.statsLose
)}
>
<Text className={styles.value}>
{recipient.err > 0 ? `错${recipient.err}题` : '全对'}
</Text>
<Text className={styles.value}>{recipient.time}s</Text>
<View className={styles.value}> <View className={styles.value}>
<Image className={styles.diamond} src={assets2['diamond.png'].u} /> <Image className={styles.diamond} src={assets2['diamond.png'].u} />
<Text>+15</Text> <Text>+15</Text>
......
...@@ -43,15 +43,16 @@ ...@@ -43,15 +43,16 @@
display: flex; display: flex;
gap: 32px; gap: 32px;
margin: 0 38px; margin: 0 38px;
justify-content: center;
.stats, .rank { .stats {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
flex: 1;
border-radius: 12px; border-radius: 12px;
border: 4px solid #57627D; border: 4px solid #57627D;
padding: 12px 32px; padding: 12px 32px;
width: 380px;
.icon { .icon {
width: 56px; width: 56px;
......
import { View, Image, Text } from '@tarojs/components' import { View, Image, Text } from '@tarojs/components'
import classNames from 'classnames' import classNames from 'classnames'
import { useStoreState } from '@/store/hooks'
import assets from '@/assets/oss/assets-pk' import assets from '@/assets/oss/assets-pk'
import styles from './player-details.module.scss' import styles from './player-details.module.scss'
import { badgeImages } from '../const' import { badgeImages } from '../const'
const PlayerDetails = () => { const PlayerDetails = () => {
const details = useStoreState((state) => state.battlesModel.details)
return ( return (
<View className={styles.player}> <View className={styles.player}>
<View className={styles.playerHeader}> <View className={styles.playerHeader}>
<Image src={assets[badgeImages.platinum.default].u} className={styles.badgeIcon}></Image> <Image
<Text className={styles.badgeText}>青铜 1</Text> src={assets[badgeImages.bronze.default].u}
className={styles.badgeIcon}
></Image>
<Text className={styles.badgeText}>
{details?.userRanks.level || '-'}
</Text>
<View className={styles.badgeBar}> <View className={styles.badgeBar}>
<Text className={classNames(styles.badgeBarItem, styles.active)}></Text> {[...Array(3)].map((_, index) => (
<Text className={classNames(styles.badgeBarItem)}></Text> <Text
<Text className={classNames(styles.badgeBarItem)}></Text> key={index}
className={classNames(
styles.badgeBarItem,
index < (details?.userRanks.star || 0) ? styles.active : null
)}
></Text>
))}
</View> </View>
</View> </View>
<View className={styles.playerFooter}> <View className={styles.playerFooter}>
<View className={styles.stats}> <View className={styles.stats}>
<View>胜<Text className={styles.winText}>4</Text></View> <View>
胜<Text className={styles.winText}>{details?.winPkNum || 0}</Text>
</View>
<Image className={styles.icon} src={assets['stats.png'].u} /> <Image className={styles.icon} src={assets['stats.png'].u} />
<View>负<Text className={styles.loseText}>4</Text></View> <View>
负
<Text className={styles.loseText}>
{(details?.allPkNum || 0) - (details?.winPkNum || 0)}
</Text>
</View>
</View> </View>
<View className={styles.rank}> {/* <View className={styles.rank}>
<Image className={styles.icon} src={assets['rank.png'].u} /> <Image className={styles.icon} src={assets['rank.png'].u} />
<View>排名第<Text className={styles.rankText}>32</Text>名</View> <View>
第<Text className={styles.rankText}>32</Text>名
</View> </View>
</View> */}
</View> </View>
</View> </View>
) )
......
.wrapper {
background-color: #F0F2F9;
min-height: 100vh;
}
.pk { .pk {
margin-top: -60px; margin-top: -60px;
display: flex; display: flex;
...@@ -63,3 +68,10 @@ ...@@ -63,3 +68,10 @@
.bottomHoverButton { .bottomHoverButton {
background-image: url('https://cdn.jkwljy.com/pk-math/3UiwFgrVHVQEcaPdxdf1XinBb64o/343x56'); background-image: url('https://cdn.jkwljy.com/pk-math/3UiwFgrVHVQEcaPdxdf1XinBb64o/343x56');
} }
.emptyText {
margin-top: 48px;
text-align: center;
font-size: 14PX;
color: rgba(70, 81, 100, 0.50);
}
\ No newline at end of file
import { useMemo } from 'react' import { useMemo } from 'react'
import { getMenuButtonBoundingClientRect } from '@tarojs/taro' import { getMenuButtonBoundingClientRect, useDidShow } from '@tarojs/taro'
import { View, Text, Image } from '@tarojs/components' import { View, Text, Image } from '@tarojs/components'
import Button from '@/components/Button' import Button from '@/components/Button'
import { useStoreState, useStoreActions } from '@/store/hooks'
import assets from '@/assets/oss/assets-pk' import assets from '@/assets/oss/assets-pk'
import TopHeader from './components/top-header' import TopHeader from './components/top-header'
import PlayerDetails from './components/player-details' import PlayerDetails from './components/player-details'
...@@ -9,37 +10,31 @@ import GameResult from './components/game-result' ...@@ -9,37 +10,31 @@ import GameResult from './components/game-result'
import styles from './index.module.scss' import styles from './index.module.scss'
const levelInfo = { const Battles = () => {
name: '关卡', const nav = useMemo(getMenuButtonBoundingClientRect, [])
result: true, const payload = { stageId: 1 }
date: '9月22日 12:22', const records = useStoreState((state) => state.battlesModel.records)
}
const levelInfo2 = { const fetchUserDetails = useStoreActions(
name: '关卡名称关卡名称', (actions) => actions.battlesModel.fetchUserDetails
result: false, )
date: '9月22日 12:22', const fetchUserRecords = useStoreActions(
} (actions) => actions.battlesModel.fetchUserRecords
)
const players = [ useDidShow(() => {
{ Promise.allSettled([fetchUserDetails(payload), fetchUserRecords(payload)])
name: '用户名称用', })
icon: 'string',
level: '青铜Ⅰ'
},
{
name: '用户2',
icon: 'string',
level: '青铜Ⅰ'
}
]
const Battles = () => {
const nav = useMemo(getMenuButtonBoundingClientRect, [])
return ( return (
<View style={{ backgroundColor: '#F0F2F9' }}> <View className={styles.wrapper}>
<TopHeader /> <TopHeader />
<View style={{ paddingTop: `${nav.height + nav.top + 5}px`, paddingBottom: 100 }}> <View
style={{
paddingTop: `${nav.height + nav.top + 5}px`,
paddingBottom: 100,
}}
>
<PlayerDetails /> <PlayerDetails />
<View className={styles.pk}> <View className={styles.pk}>
...@@ -55,12 +50,18 @@ const Battles = () => { ...@@ -55,12 +50,18 @@ const Battles = () => {
</View> </View>
<View className={styles.gameResult}> <View className={styles.gameResult}>
<GameResult levelInfo={levelInfo} players={players} /> {records.length > 0
<GameResult levelInfo={levelInfo2} players={players} /> ? records.map((item) => <GameResult key={item.id} record={item} />)
: <Text className={styles.emptyText}>暂无PK记录</Text>
}
</View> </View>
</View> </View>
<View className={styles.bottom}> <View className={styles.bottom}>
<Button size="large" image={styles.bottomButton} hoverImage={styles.bottomHoverButton}> <Button
size="large"
image={styles.bottomButton}
hoverImage={styles.bottomHoverButton}
>
<Image src={assets['pk.png'].u} className={styles.bottomText} /> <Image src={assets['pk.png'].u} className={styles.bottomText} />
</Button> </Button>
</View> </View>
......
import { Action, action } from 'easy-peasy' import { Action, Thunk, action, thunk } from 'easy-peasy'
import { fetchUserDetails, fetchUserRecords, type PkParams, type PkDetails, type PkRecord } from '@/api/pk'
interface BattlesModel { interface BattlesModel {
details: PkDetails | null,
records: PkRecord[];
modalIsVisible: boolean; modalIsVisible: boolean;
setModalIsVisible: Action<BattlesModel, boolean>; setModalIsVisible: Action<BattlesModel, boolean>;
setUserDetails: Action<BattlesModel, PkDetails>;
setUserRecords: Action<BattlesModel, PkRecord[]>;
fetchUserDetails: Thunk<BattlesModel, PkParams>;
fetchUserRecords: Thunk<BattlesModel, PkParams>;
} }
const battlesModel: BattlesModel = { const battlesModel: BattlesModel = {
details: null,
records: [],
modalIsVisible: true, modalIsVisible: true,
setModalIsVisible: action((state, payload) => { setModalIsVisible: action((state, payload) => {
state.modalIsVisible = payload state.modalIsVisible = payload
}) }),
setUserDetails: action((state, payload) => {
state.details = payload
}),
setUserRecords: action((state, payload) => {
state.records = payload
}),
fetchUserDetails: thunk(async (actions, payload) => {
try {
const res = await fetchUserDetails(payload)
if (res.code === 200) {
console.log('res', res)
actions.setUserDetails(res.data)
}
} catch (err) {
}
}),
fetchUserRecords: thunk(async (actions, payload) => {
try {
const res = await fetchUserRecords(payload)
if (res.code === 200) {
console.log('res', res)
actions.setUserRecords(res.data.records)
}
} catch (err) {
}
}),
} }
export default battlesModel export default battlesModel
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment