You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

41 lines
1021 B

import { useRef } from "react";
import { set_like } from "~/api";
import store from "~/store";
import { MarketNFTData } from "~/types/store";
const useLike = () => {
const throttle = useRef(false)
/**
* @description 設置喜歡的NFT
* @param id nftid
* 1.喜歡 2.取消喜歡
*/
const setLike = async (id: number) => {
if (!store.state.token) return store.setVisibleUnLogin(true);
if(throttle.current)return
throttle.current = true
let item = store.state.likeNft.find((v) => v.id === id);
let status = item ? 2 : 1;
let res: any = await set_like(id, status);
throttle.current = false
if (res && res.code === 0) {
store.getMyNft("likeNft");
}
};
/**
* 判斷喜歡的NFt
*/
const isLike = (id: number, likeNft: MarketNFTData[]) => {
const item = likeNft.find((v) => v.id === id);
if (item) return true;
return false;
};
return {
setLike,
isLike,
};
};
export default useLike;