feat: implement pin/unpin temporarilly

This commit is contained in:
jinhojang6 2024-10-23 02:56:39 +09:00
parent 3b7179e3ed
commit da3c5fc2d2
6 changed files with 39 additions and 13 deletions

View File

@ -1,9 +1,14 @@
import styled from '@emotion/styled' import styled from '@emotion/styled'
import { useQueryClient } from '@tanstack/react-query'
import { useAtomValue } from 'jotai'
import Link from 'next/link' import Link from 'next/link'
import React, { useState } from 'react' import React, { useState } from 'react'
import useGetUserInfo from '../../../../apis/operators/useGetUserInfo'
import { usePinOperator } from '../../../../apis/operators/usePinOperator' import { usePinOperator } from '../../../../apis/operators/usePinOperator'
import { useStakeOperator } from '../../../../apis/operators/useStakeOperator' import { useStakeOperator } from '../../../../apis/operators/useStakeOperator'
import { useUnstakeOperator } from '../../../../apis/operators/useUnstakeOperator' import { useUnstakeOperator } from '../../../../apis/operators/useUnstakeOperator'
import { userInfoAtom } from '../../../../atoms/userInfo'
import { walletAddressAtom } from '../../../../atoms/wallet'
import { ProcessedOperator } from '../../../../types/operators' import { ProcessedOperator } from '../../../../types/operators'
interface OperatorCardProps { interface OperatorCardProps {
@ -13,24 +18,40 @@ interface OperatorCardProps {
const OperatorCard: React.FC<OperatorCardProps> = ({ const OperatorCard: React.FC<OperatorCardProps> = ({
operator, operator,
}: OperatorCardProps) => { }: OperatorCardProps) => {
const user = useAtomValue(userInfoAtom)
const [isStaked, setIsStaked] = useState(operator.isStaked) const [isStaked, setIsStaked] = useState(operator.isStaked)
const [isPinned, setIsPinned] = useState(operator.isPinned) const [isPinned, setIsPinned] = useState(operator.isPinned)
const queryClient = useQueryClient()
const walletAddress = useAtomValue(walletAddressAtom)
const stake = useStakeOperator() const stake = useStakeOperator()
const unstake = useUnstakeOperator() const unstake = useUnstakeOperator()
const pin = usePinOperator() const pin = usePinOperator()
const { refetch, updateCache } = useGetUserInfo({
walletAddress,
})
const handleStake = (operatorId: string) => { const handleStake = (operatorId: string) => {
if (isStaked) { if (isStaked) {
unstake.mutate({ unstake.mutate({
operator_id: operatorId, operator_id: operatorId,
setIsStaked, setIsStaked,
}) })
queryClient.invalidateQueries('getUserInfo' as any)
refetch()
} else { } else {
stake.mutate({ stake.mutate({
operator_id: operatorId, operator_id: operatorId,
setIsStaked, setIsStaked,
}) })
queryClient.invalidateQueries('getUserInfo' as any)
refetch()
} }
} }
@ -38,14 +59,19 @@ const OperatorCard: React.FC<OperatorCardProps> = ({
pin.mutate({ pin.mutate({
operator_id: operatorId, operator_id: operatorId,
}) })
window.location.reload()
setIsPinned(!isPinned)
} }
return ( return (
<Container key={operator.id}> <Container key={operator.id}>
<Link href={`/operators/${operator.id}`} key={operator.id}> <Link href={`/operators/${operator.id}`} key={operator.id}>
<OperatorImage src={operator.image} alt={operator.name} /> <OperatorImage
src={operator?.gif}
data-src={operator?.gif}
alt={`Operator ${operator.name}`}
loading="lazy"
className="lazyload"
/>
</Link> </Link>
<OperatorInfo> <OperatorInfo>
<OperatorName>{operator.name}</OperatorName> <OperatorName>{operator.name}</OperatorName>

View File

@ -28,7 +28,6 @@ interface OperatorPanelProps {}
const OperatorPanel: React.FC<OperatorPanelProps> = () => { const OperatorPanel: React.FC<OperatorPanelProps> = () => {
const user = useAtomValue(userInfoAtom) const user = useAtomValue(userInfoAtom)
console.log('user', user)
const handleCopyAddress = () => { const handleCopyAddress = () => {
navigator.clipboard.writeText(user?.address) navigator.clipboard.writeText(user?.address)
@ -45,18 +44,18 @@ const OperatorPanel: React.FC<OperatorPanelProps> = () => {
{user?.pinned_operator && ( {user?.pinned_operator && (
<Profile> <Profile>
<OperatorImage <OperatorImage
src="/dashboard/mock/operators/pinned.gif" src={user?.pinned_operator?.image_400_url}
alt="Operator" alt="Operator"
/> />
<OperatorInfo> <OperatorInfo>
<OperatorType>Quantum Recursive Memetic</OperatorType> <OperatorType>{user?.pinned_operator?.name}</OperatorType>
</OperatorInfo> </OperatorInfo>
</Profile> </Profile>
)} )}
<InfoRow> <InfoRow>
<Label>Archetype</Label> <Label>Archetype</Label>
<Value>Memetic</Value> <Value>{user?.pinned_operator?.archetype}</Value>
</InfoRow> </InfoRow>
<CallSignContainer> <CallSignContainer>

View File

@ -1,8 +1,10 @@
import { breakpoints } from '@/configs/ui.configs' import { breakpoints } from '@/configs/ui.configs'
import { numberWithCommas } from '@/utils/general.utils' import { numberWithCommas } from '@/utils/general.utils'
import styled from '@emotion/styled' import styled from '@emotion/styled'
import { useAtomValue } from 'jotai'
import React from 'react' import React from 'react'
import useGetEpochs from '../../../../apis/general/useGetEpochs' import useGetEpochs from '../../../../apis/general/useGetEpochs'
import { userInfoAtom } from '../../../../atoms/userInfo'
interface ProgressBarProps { interface ProgressBarProps {
progress: number // Current progress of the epoch progress: number // Current progress of the epoch
@ -14,6 +16,7 @@ const ProgressBar: React.FC<ProgressBarProps> = ({
claimPosition = 76, claimPosition = 76,
}) => { }) => {
const { data: epochs } = useGetEpochs() const { data: epochs } = useGetEpochs()
const user = useAtomValue(userInfoAtom)
// const { data: currentBlock } = useGetCurrentBTCBlock() // const { data: currentBlock } = useGetCurrentBTCBlock()
// const { data: pillars } = useGetPillars() // const { data: pillars } = useGetPillars()
@ -58,7 +61,7 @@ const ProgressBar: React.FC<ProgressBarProps> = ({
<EarnedReward> <EarnedReward>
<Label>Total Points</Label> <Label>Total Points</Label>
<Value color="#F29AE9" backgroundColor="#320430"> <Value color="#F29AE9" backgroundColor="#320430">
{`${numberWithCommas(40278)}`} {`${numberWithCommas(user?.total_xp)}`}
</Value> </Value>
</EarnedReward> </EarnedReward>
<EarnedReward> <EarnedReward>

View File

@ -51,8 +51,6 @@ export async function signWalletMessage(address: string) {
message: WALLET_SIGN_MESSAGE_REQUEST, message: WALLET_SIGN_MESSAGE_REQUEST,
}, },
onFinish: (response) => { onFinish: (response) => {
console.log('onFinish response, ', response)
resolve(response) resolve(response)
}, },
onCancel: () => { onCancel: () => {

View File

@ -3,7 +3,7 @@ import { OperatorPanel } from '@/components/Dashboard/OperatorPanel'
import { ProgressBar } from '@/components/Dashboard/ProgressBar' import { ProgressBar } from '@/components/Dashboard/ProgressBar'
import { breakpoints } from '@/configs/ui.configs' import { breakpoints } from '@/configs/ui.configs'
import styled from '@emotion/styled' import styled from '@emotion/styled'
import { useAtom, useSetAtom } from 'jotai' import { useAtom } from 'jotai'
import React, { useEffect } from 'react' import React, { useEffect } from 'react'
import useGetUserInfo from '../../../apis/operators/useGetUserInfo' import useGetUserInfo from '../../../apis/operators/useGetUserInfo'
import { userInfoAtom } from '../../../atoms/userInfo' import { userInfoAtom } from '../../../atoms/userInfo'
@ -19,7 +19,7 @@ const DashboardContainer: React.FC<DashboardPageProps> = ({
children, children,
...props ...props
}) => { }) => {
const setUserInfo = useSetAtom(userInfoAtom) const [userInfo, setUserInfo] = useAtom(userInfoAtom)
const [walletAddress, setWalletAddress] = useAtom(walletAddressAtom) const [walletAddress, setWalletAddress] = useAtom(walletAddressAtom)

View File

@ -40,7 +40,7 @@ export function processMyOperators(operators: any[]) {
} }
return operators?.map((operator) => ({ return operators?.map((operator) => ({
id: operator.id.toString(), id: operator.id,
arcgetypeId: operator.archetype_id, arcgetypeId: operator.archetype_id,
image: operator.image_400_jpeg_url, image: operator.image_400_jpeg_url,
gif: operator.image_400_url, gif: operator.image_400_url,