mirror of
https://github.com/acid-info/logos-ordinals-dashboard.git
synced 2025-02-05 18:13:47 +00:00
chore: improve pin UX
This commit is contained in:
parent
a430b0bb28
commit
726905328f
@ -1,6 +1,6 @@
|
|||||||
import styled from '@emotion/styled'
|
import styled from '@emotion/styled'
|
||||||
import { useQueryClient } from '@tanstack/react-query'
|
import { useQueryClient } from '@tanstack/react-query'
|
||||||
import { useAtomValue } from 'jotai'
|
import { useAtomValue, useSetAtom } 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 useGetUserInfo from '../../../../apis/operators/useGetUserInfo'
|
||||||
@ -18,10 +18,9 @@ interface OperatorCardProps {
|
|||||||
const OperatorCard: React.FC<OperatorCardProps> = ({
|
const OperatorCard: React.FC<OperatorCardProps> = ({
|
||||||
operator,
|
operator,
|
||||||
}: OperatorCardProps) => {
|
}: OperatorCardProps) => {
|
||||||
const user = useAtomValue(userInfoAtom)
|
const setUserInfo = useSetAtom(userInfoAtom)
|
||||||
|
|
||||||
const [isStaked, setIsStaked] = useState(operator.isStaked)
|
const [isStaked, setIsStaked] = useState(operator.isStaked)
|
||||||
const [isPinned, setIsPinned] = useState(operator.isPinned)
|
|
||||||
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
@ -36,8 +35,10 @@ const OperatorCard: React.FC<OperatorCardProps> = ({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const handleStake = (operatorId: string) => {
|
const handleStake = (operatorId: string) => {
|
||||||
|
setIsStaked((prev) => !prev)
|
||||||
|
|
||||||
if (isStaked) {
|
if (isStaked) {
|
||||||
unstake.mutate({
|
unstake.mutateAsync({
|
||||||
operator_id: operatorId,
|
operator_id: operatorId,
|
||||||
setIsStaked,
|
setIsStaked,
|
||||||
})
|
})
|
||||||
@ -45,7 +46,7 @@ const OperatorCard: React.FC<OperatorCardProps> = ({
|
|||||||
queryClient.invalidateQueries('getUserInfo' as any)
|
queryClient.invalidateQueries('getUserInfo' as any)
|
||||||
refetch()
|
refetch()
|
||||||
} else {
|
} else {
|
||||||
stake.mutate({
|
stake.mutateAsync({
|
||||||
operator_id: operatorId,
|
operator_id: operatorId,
|
||||||
setIsStaked,
|
setIsStaked,
|
||||||
})
|
})
|
||||||
@ -55,11 +56,18 @@ const OperatorCard: React.FC<OperatorCardProps> = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handledPin = (operatorId: string) => {
|
const handledPin = async (operatorId: string) => {
|
||||||
pin.mutate({
|
queryClient.invalidateQueries('getUserInfo' as any)
|
||||||
|
|
||||||
|
await pin.mutateAsync({
|
||||||
operator_id: operatorId,
|
operator_id: operatorId,
|
||||||
})
|
})
|
||||||
window.location.reload()
|
|
||||||
|
const res = await refetch()
|
||||||
|
|
||||||
|
const newUserInfo = res.data
|
||||||
|
|
||||||
|
setUserInfo(newUserInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -87,8 +95,11 @@ const OperatorCard: React.FC<OperatorCardProps> = ({
|
|||||||
>
|
>
|
||||||
{isStaked ? 'Unstake' : 'Stake'}
|
{isStaked ? 'Unstake' : 'Stake'}
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
<IconButton onClick={() => handledPin(operator.id)} isPinned={isPinned}>
|
<IconButton
|
||||||
{isPinned ? (
|
onClick={() => handledPin(operator.id)}
|
||||||
|
isPinned={operator.isPinned}
|
||||||
|
>
|
||||||
|
{operator.isPinned ? (
|
||||||
<img src="/assets/pinned.svg" alt="Pinned" />
|
<img src="/assets/pinned.svg" alt="Pinned" />
|
||||||
) : (
|
) : (
|
||||||
<img src="/assets/unpinned.svg" alt="Unpinned" />
|
<img src="/assets/unpinned.svg" alt="Unpinned" />
|
||||||
|
@ -58,7 +58,7 @@ const OperatorPanel: React.FC<OperatorPanelProps> = () => {
|
|||||||
const handleCallSignUpdate = () => {
|
const handleCallSignUpdate = () => {
|
||||||
setEditCallsign(false)
|
setEditCallsign(false)
|
||||||
|
|
||||||
updateCallSign.mutate({
|
updateCallSign.mutateAsync({
|
||||||
call_sign: callsign,
|
call_sign: callsign,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ const DashboardContainer: React.FC<DashboardPageProps> = ({
|
|||||||
enabled: !!walletAddress && walletAddress.length > 0,
|
enabled: !!walletAddress && walletAddress.length > 0,
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log('userXP', userXP)
|
// console.log('userXP', userXP)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container {...props}>
|
<Container {...props}>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user