From 40734b793353dd42bf902565fa0017f9421cf578 Mon Sep 17 00:00:00 2001 From: Supreme2580 Date: Wed, 27 Nov 2024 08:51:07 +0100 Subject: [PATCH 01/13] canvas-# --- backend/routes/canvas.go | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/backend/routes/canvas.go b/backend/routes/canvas.go index a6d46858..1eb02263 100644 --- a/backend/routes/canvas.go +++ b/backend/routes/canvas.go @@ -2,6 +2,7 @@ package routes import ( "context" + "fmt" "net/http" "github.com/keep-starknet-strange/art-peace/backend/core" @@ -19,7 +20,16 @@ func initCanvas(w http.ResponseWriter, r *http.Request) { return } - if core.ArtPeaceBackend.Databases.Redis.Exists(context.Background(), "canvas").Val() == 0 { + // Get round number from query params + roundNumber := r.URL.Query().Get("round") + if roundNumber == "" { + routeutils.WriteErrorJson(w, http.StatusBadRequest, "Round number is required") + return + } + + canvasKey := fmt.Sprintf("canvas-%s", roundNumber) + + if core.ArtPeaceBackend.Databases.Redis.Exists(context.Background(), canvasKey).Val() == 0 { totalBitSize := core.ArtPeaceBackend.CanvasConfig.Canvas.Width * core.ArtPeaceBackend.CanvasConfig.Canvas.Height * core.ArtPeaceBackend.CanvasConfig.ColorsBitWidth totalByteSize := (totalBitSize / 8) if totalBitSize%8 != 0 { @@ -30,23 +40,32 @@ func initCanvas(w http.ResponseWriter, r *http.Request) { // Create canvas canvas := make([]byte, totalByteSize) ctx := context.Background() - err := core.ArtPeaceBackend.Databases.Redis.Set(ctx, "canvas", canvas, 0).Err() + err := core.ArtPeaceBackend.Databases.Redis.Set(ctx, canvasKey, canvas, 0).Err() if err != nil { routeutils.WriteErrorJson(w, http.StatusInternalServerError, "Failed to initialize canvas") return } - routeutils.WriteResultJson(w, "Canvas initialized") + routeutils.WriteResultJson(w, fmt.Sprintf("Canvas for round %s initialized", roundNumber)) } else { - routeutils.WriteErrorJson(w, http.StatusConflict, "Canvas already initialized") + routeutils.WriteErrorJson(w, http.StatusConflict, fmt.Sprintf("Canvas for round %s already initialized", roundNumber)) } } func getCanvas(w http.ResponseWriter, r *http.Request) { routeutils.SetupAccessHeaders(w) + // Get round number from query params, default to latest round if not specified + roundNumber := r.URL.Query().Get("round") + if roundNumber == "" { + // TODO: Implement logic to get latest round number + roundNumber = "1" // Default to round 1 for now + } + + canvasKey := fmt.Sprintf("canvas-%s", roundNumber) + ctx := context.Background() - val, err := core.ArtPeaceBackend.Databases.Redis.Get(ctx, "canvas").Result() + val, err := core.ArtPeaceBackend.Databases.Redis.Get(ctx, canvasKey).Result() if err != nil { routeutils.WriteErrorJson(w, http.StatusInternalServerError, "Failed to get canvas") return From 6572ba577809fe79253acf231733fa99f971a767 Mon Sep 17 00:00:00 2001 From: Supreme2580 Date: Wed, 27 Nov 2024 15:21:27 +0100 Subject: [PATCH 02/13] wip --- frontend/src/services/apiService.js | 7 ++++ frontend/src/tabs/nfts/NFTs.js | 61 +++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/frontend/src/services/apiService.js b/frontend/src/services/apiService.js index e2a27919..5dad1d35 100644 --- a/frontend/src/services/apiService.js +++ b/frontend/src/services/apiService.js @@ -113,6 +113,13 @@ export const getHotNftsFn = async (params) => { ); }; +export const getRoundNftsFn = async (params) => { + const { page, pageLength, queryAddress, roundNumber } = params; + return await fetchWrapper( + `get-round-nfts?address=${queryAddress}&page=${page}&pageLength=${pageLength}&round=${roundNumber}` + ); +}; + export const getChainFactionMembers = async (query) => { return await fetchWrapper( `get-chain-faction-members?factionId=${query.factionId}&page=${query.page}&pageLength=${query.pageLength}` diff --git a/frontend/src/tabs/nfts/NFTs.js b/frontend/src/tabs/nfts/NFTs.js index aebcc33a..7fa96c53 100644 --- a/frontend/src/tabs/nfts/NFTs.js +++ b/frontend/src/tabs/nfts/NFTs.js @@ -9,7 +9,8 @@ import { getNftsFn, getNewNftsFn, getTopNftsFn, - getHotNftsFn + getHotNftsFn, + getRoundNftsFn } from '../../services/apiService.js'; import { PaginationView } from '../../ui/pagination.js'; @@ -94,9 +95,42 @@ const NFTsMainSection = (props) => { }; const NFTsExpandedSection = (props) => { - const roundNumber = process.env.REACT_APP_ROUND_NUMBER || '0'; - const imageURL = `${nftUrl}/nft/round-${roundNumber}/images/`; - const metadataURL = `${nftUrl}/nft/round-${roundNumber}/metadata/`; + const [currentRound, setCurrentRound] = useState(parseInt('100')); + const imageURL = `${nftUrl}/nft/round-${currentRound}/images/`; + const metadataURL = `${nftUrl}/nft/round-${currentRound}/metadata/`; + + const handleRoundChange = (direction) => { + const maxRound = parseInt('100'); + + if (direction === 'prev' && currentRound > 1) { + setCurrentRound((prev) => prev - 1); + props.setAllNftPagination((prev) => ({ ...prev, page: 1 })); + } else if (direction === 'next' && currentRound < maxRound) { + setCurrentRound((prev) => prev + 1); + props.setAllNftPagination((prev) => ({ ...prev, page: 1 })); + } + }; + + useEffect(() => { + async function fetchRoundNfts() { + try { + const result = await getRoundNftsFn({ + page: props.allNftPagination.page, + pageLength: props.allNftPagination.pageLength, + queryAddress: props.queryAddress, + roundNumber: currentRound + }); + + if (result.data) { + props.setAllNFTs(result.data); + } + } catch (error) { + console.log('Error fetching round NFTs:', error); + } + } + + fetchRoundNfts(); + }, [currentRound, props.allNftPagination.page, props.queryAddress]); return (
@@ -116,9 +150,23 @@ const NFTsExpandedSection = (props) => {
); })} +
handleRoundChange('prev')} + > + {'<'} +
+
+ {`Round ${currentRound}`} +
+
handleRoundChange('next')} + > + {'>'} +
-
{props.allNfts.map((nft, index) => { @@ -178,7 +226,6 @@ const NFTs = (props) => { const response = await fetchWrapper(getNFTByTokenId, { mode: 'cors' }); if (response.data) { let newNFTs = [response.data, ...myNFTs]; - // Remove duplicate tokenIds let uniqueNFTs = newNFTs.filter( (nft, index, self) => index === self.findIndex((t) => t.tokenId === nft.tokenId) @@ -298,7 +345,7 @@ const NFTs = (props) => { } } getNfts(); - }, [props.queryAddress, expanded, allNftPagination]); + }, [props.queryAddress, expanded, allNftPagination, activeFilter]); const resetPagination = () => { setAllNftPagination((prev) => ({ From 2267b990fea2b1a66abf90ad147371bc0ad34d71 Mon Sep 17 00:00:00 2001 From: Supreme2580 Date: Thu, 28 Nov 2024 23:26:38 +0100 Subject: [PATCH 03/13] round filter --- backend/routes/nft.go | 84 +++++++++++++++++++- frontend/src/services/apiService.js | 17 ++-- frontend/src/tabs/nfts/NFTs.js | 117 ++++++++++++++++++---------- 3 files changed, 166 insertions(+), 52 deletions(-) diff --git a/backend/routes/nft.go b/backend/routes/nft.go index de6f7762..b6a2d0a7 100644 --- a/backend/routes/nft.go +++ b/backend/routes/nft.go @@ -26,6 +26,7 @@ func InitNFTRoutes() { // http.HandleFunc("/unlike-nft", UnLikeNFT) http.HandleFunc("/get-top-nfts", getTopNFTs) http.HandleFunc("/get-hot-nfts", getHotNFTs) + http.HandleFunc("/get-round-nfts", getRoundNFTs) if !core.ArtPeaceBackend.BackendConfig.Production { http.HandleFunc("/mint-nft-devnet", mintNFTDevnet) http.HandleFunc("/like-nft-devnet", likeNFTDevnet) @@ -153,6 +154,11 @@ func getNFTs(w http.ResponseWriter, r *http.Request) { } offset := (page - 1) * pageLength + roundNumber, err := strconv.Atoi(r.URL.Query().Get("round")) + if err != nil { + roundNumber = -1 + } + query := ` SELECT nfts.*, @@ -169,9 +175,10 @@ func getNFTs(w http.ResponseWriter, r *http.Request) { GROUP BY nftKey ) nftlikes ON nfts.token_id = nftlikes.nftKey + WHERE ($4 < 0 OR nfts.day_index = $4) ORDER BY nfts.token_id DESC LIMIT $2 OFFSET $3` - nfts, err := core.PostgresQueryJson[NFTData](query, address, pageLength, offset) + nfts, err := core.PostgresQueryJson[NFTData](query, address, pageLength, offset, roundNumber) if err != nil { routeutils.WriteErrorJson(w, http.StatusInternalServerError, "Failed to retrieve NFTs") return @@ -197,6 +204,11 @@ func getNewNFTs(w http.ResponseWriter, r *http.Request) { } offset := (page - 1) * pageLength + roundNumber, err := strconv.Atoi(r.URL.Query().Get("round")) + if err != nil { + roundNumber = -1 + } + query := ` SELECT nfts.*, @@ -213,9 +225,10 @@ func getNewNFTs(w http.ResponseWriter, r *http.Request) { GROUP BY nftKey ) nftlikes ON nfts.token_id = nftlikes.nftKey + WHERE ($4 < 0 OR nfts.day_index = $4) ORDER BY nfts.token_id DESC LIMIT $2 OFFSET $3` - nfts, err := core.PostgresQueryJson[NFTData](query, address, pageLength, offset) + nfts, err := core.PostgresQueryJson[NFTData](query, address, pageLength, offset, roundNumber) if err != nil { routeutils.WriteErrorJson(w, http.StatusInternalServerError, "Failed to retrieve NFTs") return @@ -406,6 +419,11 @@ func getTopNFTs(w http.ResponseWriter, r *http.Request) { } offset := (page - 1) * pageLength + roundNumber, err := strconv.Atoi(r.URL.Query().Get("round")) + if err != nil { + roundNumber = -1 + } + query := ` SELECT nfts.*, @@ -422,10 +440,11 @@ func getTopNFTs(w http.ResponseWriter, r *http.Request) { GROUP BY nftKey ) nftlikes ON nfts.token_id = nftlikes.nftKey + WHERE ($4 < 0 OR nfts.day_index = $4) ORDER BY likes DESC LIMIT $2 OFFSET $3` - nfts, err := core.PostgresQueryJson[NFTData](query, address, pageLength, offset) + nfts, err := core.PostgresQueryJson[NFTData](query, address, pageLength, offset, roundNumber) if err != nil { routeutils.WriteErrorJson(w, http.StatusInternalServerError, "Failed to retrieve NFTs") return @@ -511,6 +530,11 @@ func getHotNFTs(w http.ResponseWriter, r *http.Request) { } offset := (page - 1) * pageLength + roundNumber, err := strconv.Atoi(r.URL.Query().Get("round")) + if err != nil { + roundNumber = -1 + } + query := ` SELECT nfts.*, @@ -536,12 +560,64 @@ func getHotNFTs(w http.ResponseWriter, r *http.Request) { ) latestlikes GROUP BY nftkey ) rank ON nfts.token_id = rank.nftkey + WHERE ($5 < 0 OR nfts.day_index = $5) ORDER BY COALESCE(rank, 0) DESC LIMIT $3 OFFSET $4;` - nfts, err := core.PostgresQueryJson[NFTData](query, address, hotLimit, pageLength, offset) + nfts, err := core.PostgresQueryJson[NFTData](query, address, hotLimit, pageLength, offset, roundNumber) if err != nil { routeutils.WriteErrorJson(w, http.StatusInternalServerError, "Failed to retrieve Hot NFTs") return } routeutils.WriteDataJson(w, string(nfts)) } + +func getRoundNFTs(w http.ResponseWriter, r *http.Request) { + address := r.URL.Query().Get("address") + if address == "" { + address = "0" + } + roundNumber, err := strconv.Atoi(r.URL.Query().Get("round")) + if err != nil || roundNumber <= 0 { + routeutils.WriteErrorJson(w, http.StatusBadRequest, "Invalid round number") + return + } + pageLength, err := strconv.Atoi(r.URL.Query().Get("pageLength")) + if err != nil || pageLength <= 0 { + pageLength = 25 + } + if pageLength > 50 { + pageLength = 50 + } + page, err := strconv.Atoi(r.URL.Query().Get("page")) + if err != nil || page <= 0 { + page = 1 + } + offset := (page - 1) * pageLength + + query := ` + SELECT + nfts.*, + COALESCE(like_count, 0) AS likes, + COALESCE((SELECT true FROM nftlikes WHERE liker = $1 AND nftlikes.nftkey = nfts.token_id), false) as liked + FROM + nfts + LEFT JOIN ( + SELECT + nftKey, + COUNT(*) AS like_count + FROM + nftlikes + GROUP BY + nftKey + ) nftlikes ON nfts.token_id = nftlikes.nftKey + WHERE + nfts.day_index = $2 + ORDER BY nfts.token_id DESC + LIMIT $3 OFFSET $4` + nfts, err := core.PostgresQueryJson[NFTData](query, address, roundNumber, pageLength, offset) + if err != nil { + routeutils.WriteErrorJson(w, http.StatusInternalServerError, "Failed to retrieve NFTs") + return + } + routeutils.WriteDataJson(w, string(nfts)) +} diff --git a/frontend/src/services/apiService.js b/frontend/src/services/apiService.js index 5dad1d35..4a0f1818 100644 --- a/frontend/src/services/apiService.js +++ b/frontend/src/services/apiService.js @@ -67,9 +67,10 @@ export const getMyNftsFn = async (query) => { * @param {number} query.page - The page number to fetch. * @returns {Promise} The response from the fetch call. */ -export const getNftsFn = async (query) => { +export const getNftsFn = async (params) => { + const { page, pageLength, queryAddress, roundNumber } = params; return await fetchWrapper( - `get-nfts?pageLength=${query.pageLength}&page=${query.page}` + `get-nfts?address=${queryAddress}&page=${page}&pageLength=${pageLength}&round=${roundNumber}` ); }; @@ -84,9 +85,9 @@ export const getChainFactions = async (query) => { }; export const getNewNftsFn = async (params) => { - const { page, pageLength, queryAddress } = params; + const { page, pageLength, queryAddress, roundNumber } = params; return await fetchWrapper( - `get-new-nfts?address=${queryAddress}&page=${page}&pageLength=${pageLength}` + `get-new-nfts?address=${queryAddress}&page=${page}&pageLength=${pageLength}&round=${roundNumber}` ); }; @@ -100,16 +101,16 @@ export const getNewNftsFn = async (params) => { * @returns {Promise} The response from the fetch call. */ export const getTopNftsFn = async (params) => { - const { page, pageLength, queryAddress } = params; + const { page, pageLength, queryAddress, roundNumber } = params; return await fetchWrapper( - `get-top-nfts?address=${queryAddress}&page=${page}&pageLength=${pageLength}` + `get-top-nfts?address=${queryAddress}&page=${page}&pageLength=${pageLength}&round=${roundNumber}` ); }; export const getHotNftsFn = async (params) => { - const { page, pageLength, queryAddress } = params; + const { page, pageLength, queryAddress, roundNumber } = params; return await fetchWrapper( - `get-hot-nfts?address=${queryAddress}&page=${page}&pageLength=${pageLength}` + `get-hot-nfts?address=${queryAddress}&page=${page}&pageLength=${pageLength}&round=${roundNumber}` ); }; diff --git a/frontend/src/tabs/nfts/NFTs.js b/frontend/src/tabs/nfts/NFTs.js index 7fa96c53..9db7b0af 100644 --- a/frontend/src/tabs/nfts/NFTs.js +++ b/frontend/src/tabs/nfts/NFTs.js @@ -95,12 +95,13 @@ const NFTsMainSection = (props) => { }; const NFTsExpandedSection = (props) => { - const [currentRound, setCurrentRound] = useState(parseInt('100')); + const [currentRound, setCurrentRound] = useState(1); + const dayIndex = currentRound - 1; const imageURL = `${nftUrl}/nft/round-${currentRound}/images/`; const metadataURL = `${nftUrl}/nft/round-${currentRound}/metadata/`; const handleRoundChange = (direction) => { - const maxRound = parseInt('100'); + const maxRound = 100; if (direction === 'prev' && currentRound > 1) { setCurrentRound((prev) => prev - 1); @@ -112,44 +113,88 @@ const NFTsExpandedSection = (props) => { }; useEffect(() => { - async function fetchRoundNfts() { + async function getNfts() { try { - const result = await getRoundNftsFn({ - page: props.allNftPagination.page, - pageLength: props.allNftPagination.pageLength, - queryAddress: props.queryAddress, - roundNumber: currentRound - }); + let result; + if (props.activeFilter === 'hot') { + result = await getHotNftsFn({ + page: props.allNftPagination.page, + pageLength: props.allNftPagination.pageLength, + queryAddress: props.queryAddress, + roundNumber: dayIndex + }); + } else if (props.activeFilter === 'new') { + result = await getNewNftsFn({ + page: props.allNftPagination.page, + pageLength: props.allNftPagination.pageLength, + queryAddress: props.queryAddress, + roundNumber: dayIndex + }); + } else if (props.activeFilter === 'top') { + result = await getTopNftsFn({ + page: props.allNftPagination.page, + pageLength: props.allNftPagination.pageLength, + queryAddress: props.queryAddress, + roundNumber: dayIndex + }); + } else { + result = await getRoundNftsFn({ + page: props.allNftPagination.page, + pageLength: props.allNftPagination.pageLength, + queryAddress: props.queryAddress, + roundNumber: dayIndex + }); + } if (result.data) { - props.setAllNFTs(result.data); + const roundNfts = result.data.filter( + (nft) => nft.dayIndex === dayIndex + ); + + if (props.allNftPagination.page === 1) { + props.setAllNFTs(roundNfts); + } else { + const newNfts = roundNfts.filter( + (nft) => + !props.allNfts.some( + (existingNft) => existingNft.tokenId === nft.tokenId + ) + ); + props.setAllNFTs([...props.allNfts, ...newNfts]); + } } } catch (error) { - console.log('Error fetching round NFTs:', error); + console.log('Error fetching NFTs:', error); } } - fetchRoundNfts(); - }, [currentRound, props.allNftPagination.page, props.queryAddress]); + if (props.expanded) { + getNfts(); + } + }, [ + currentRound, + props.allNftPagination, + props.activeFilter, + props.queryAddress, + props.expanded + ]); return (

Explore

- {props.filters.map((filter, index) => { - return ( -
props.setActiveFilter(filter)} - > - {filter} -
- ); - })} + {props.filters.map((filter, index) => ( +
props.setActiveFilter(filter)} + > + {filter} +
+ ))}
handleRoundChange('prev')} @@ -169,37 +214,29 @@ const NFTsExpandedSection = (props) => {
- {props.allNfts.map((nft, index) => { - return ( + {props.allNfts + .filter((nft) => nft.dayIndex === dayIndex) + .map((nft, index) => ( - ); - })} + ))}
nft.dayIndex === dayIndex)} setState={props.setAllNftPagination} stateValue={props.allNftPagination} /> From ea48a261a92b5456686517392175bea224690713 Mon Sep 17 00:00:00 2001 From: Supreme2580 Date: Fri, 29 Nov 2024 01:01:05 +0100 Subject: [PATCH 04/13] like filter --- backend/routes/nft.go | 71 ++++++++++++++++++++++++++++- frontend/src/services/apiService.js | 9 +++- frontend/src/tabs/nfts/NFTs.js | 37 +++++++++------ 3 files changed, 101 insertions(+), 16 deletions(-) diff --git a/backend/routes/nft.go b/backend/routes/nft.go index b6a2d0a7..e2b62ede 100644 --- a/backend/routes/nft.go +++ b/backend/routes/nft.go @@ -27,6 +27,7 @@ func InitNFTRoutes() { http.HandleFunc("/get-top-nfts", getTopNFTs) http.HandleFunc("/get-hot-nfts", getHotNFTs) http.HandleFunc("/get-round-nfts", getRoundNFTs) + http.HandleFunc("/get-liked-nfts", getLikedNFTs) if !core.ArtPeaceBackend.BackendConfig.Production { http.HandleFunc("/mint-nft-devnet", mintNFTDevnet) http.HandleFunc("/like-nft-devnet", likeNFTDevnet) @@ -95,6 +96,11 @@ func getMyNFTs(w http.ResponseWriter, r *http.Request) { } offset := (page - 1) * pageLength + roundNumber, err := strconv.Atoi(r.URL.Query().Get("round")) + if err != nil { + roundNumber = -1 + } + query := ` SELECT nfts.*, @@ -113,9 +119,10 @@ func getMyNFTs(w http.ResponseWriter, r *http.Request) { ) nftlikes ON nfts.token_id = nftlikes.nftKey WHERE nfts.owner = $1 + AND ($4 < 0 OR nfts.day_index = $4) ORDER BY nfts.token_id DESC LIMIT $2 OFFSET $3` - nfts, err := core.PostgresQueryJson[NFTData](query, address, pageLength, offset) + nfts, err := core.PostgresQueryJson[NFTData](query, address, pageLength, offset, roundNumber) if err != nil { routeutils.WriteErrorJson(w, http.StatusInternalServerError, "Failed to retrieve NFTs") return @@ -577,7 +584,7 @@ func getRoundNFTs(w http.ResponseWriter, r *http.Request) { address = "0" } roundNumber, err := strconv.Atoi(r.URL.Query().Get("round")) - if err != nil || roundNumber <= 0 { + if err != nil || roundNumber < 0 { routeutils.WriteErrorJson(w, http.StatusBadRequest, "Invalid round number") return } @@ -621,3 +628,63 @@ func getRoundNFTs(w http.ResponseWriter, r *http.Request) { } routeutils.WriteDataJson(w, string(nfts)) } + +func getLikedNFTs(w http.ResponseWriter, r *http.Request) { + address := r.URL.Query().Get("address") + if address == "" || address == "0" { + routeutils.WriteErrorJson(w, http.StatusBadRequest, "Valid address required for liked NFTs") + return + } + + pageLength, err := strconv.Atoi(r.URL.Query().Get("pageLength")) + if err != nil || pageLength <= 0 { + pageLength = 25 + } + if pageLength > 50 { + pageLength = 50 + } + + page, err := strconv.Atoi(r.URL.Query().Get("page")) + if err != nil || page <= 0 { + page = 1 + } + offset := (page - 1) * pageLength + + roundNumber, err := strconv.Atoi(r.URL.Query().Get("round")) + if err != nil { + roundNumber = -1 + } + + query := ` + SELECT + nfts.*, + COALESCE(like_count, 0) AS likes, + true as liked + FROM + nfts + LEFT JOIN ( + SELECT + nftKey, + COUNT(*) AS like_count + FROM + nftlikes + GROUP BY + nftKey + ) nftlikes ON nfts.token_id = nftlikes.nftKey + WHERE + nfts.token_id IN ( + SELECT nftkey + FROM nftlikes + WHERE liker = $1 + ) + AND ($4 < 0 OR nfts.day_index = $4) + ORDER BY nfts.token_id DESC + LIMIT $2 OFFSET $3` + + nfts, err := core.PostgresQueryJson[NFTData](query, address, pageLength, offset, roundNumber) + if err != nil { + routeutils.WriteErrorJson(w, http.StatusInternalServerError, "Failed to retrieve liked NFTs") + return + } + routeutils.WriteDataJson(w, string(nfts)) +} diff --git a/frontend/src/services/apiService.js b/frontend/src/services/apiService.js index 4a0f1818..c1f23183 100644 --- a/frontend/src/services/apiService.js +++ b/frontend/src/services/apiService.js @@ -55,7 +55,7 @@ export const addFactionTemplateDevnet = async (metadata) => { */ export const getMyNftsFn = async (query) => { return await fetchWrapper( - `get-my-nfts?address=${query.queryAddress}&pageLength=${query.pageLength}&page=${query.page}` + `get-my-nfts?address=${query.queryAddress}&pageLength=${query.pageLength}&page=${query.page}&round=${query.roundNumber}` ); }; @@ -114,6 +114,13 @@ export const getHotNftsFn = async (params) => { ); }; +export const getLikedNftsFn = async (params) => { + const { page, pageLength, queryAddress, roundNumber } = params; + return await fetchWrapper( + `get-liked-nfts?address=${queryAddress}&page=${page}&pageLength=${pageLength}&round=${roundNumber}` + ); +}; + export const getRoundNftsFn = async (params) => { const { page, pageLength, queryAddress, roundNumber } = params; return await fetchWrapper( diff --git a/frontend/src/tabs/nfts/NFTs.js b/frontend/src/tabs/nfts/NFTs.js index 9db7b0af..1d332f12 100644 --- a/frontend/src/tabs/nfts/NFTs.js +++ b/frontend/src/tabs/nfts/NFTs.js @@ -10,7 +10,8 @@ import { getNewNftsFn, getTopNftsFn, getHotNftsFn, - getRoundNftsFn + getRoundNftsFn, + getLikedNftsFn } from '../../services/apiService.js'; import { PaginationView } from '../../ui/pagination.js'; @@ -184,17 +185,21 @@ const NFTsExpandedSection = (props) => {

Explore

- {props.filters.map((filter, index) => ( -
props.setActiveFilter(filter)} - > - {filter} -
- ))} + {props.activeFilter === 'liked' && props.allNfts.length === 0 + ? null + : props.filters.map((filter, index) => ( +
props.setActiveFilter(filter)} + > + {filter} +
+ ))}
handleRoundChange('prev')} @@ -328,7 +333,7 @@ const NFTs = (props) => { }, [props.queryAddress, myNftPagination.page, myNftPagination.pageLength]); const [expanded, setExpanded] = useState(false); - const filters = ['hot', 'new', 'top']; + const filters = ['hot', 'new', 'top', 'liked']; const [activeFilter, setActiveFilter] = useState(filters[0]); useEffect(() => { @@ -356,6 +361,12 @@ const NFTs = (props) => { pageLength: allNftPagination.pageLength, queryAddress: props.queryAddress }); + } else if (activeFilter === 'liked') { + result = await getLikedNftsFn({ + page: allNftPagination.page, + pageLength: allNftPagination.pageLength, + queryAddress: props.queryAddress + }); } else { result = await getNftsFn({ page: allNftPagination.page, From 2ff1eed0813d07fde4d8c95e6f85e827aea89a9f Mon Sep 17 00:00:00 2001 From: Supreme2580 Date: Fri, 29 Nov 2024 01:16:25 +0100 Subject: [PATCH 05/13] like filter --- frontend/src/tabs/nfts/NFTs.js | 76 ++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 35 deletions(-) diff --git a/frontend/src/tabs/nfts/NFTs.js b/frontend/src/tabs/nfts/NFTs.js index 1d332f12..21541647 100644 --- a/frontend/src/tabs/nfts/NFTs.js +++ b/frontend/src/tabs/nfts/NFTs.js @@ -138,6 +138,13 @@ const NFTsExpandedSection = (props) => { queryAddress: props.queryAddress, roundNumber: dayIndex }); + } else if (props.activeFilter === 'liked') { + result = await getLikedNftsFn({ + page: props.allNftPagination.page, + pageLength: props.allNftPagination.pageLength, + queryAddress: props.queryAddress, + roundNumber: dayIndex + }); } else { result = await getRoundNftsFn({ page: props.allNftPagination.page, @@ -163,6 +170,8 @@ const NFTsExpandedSection = (props) => { ); props.setAllNFTs([...props.allNfts, ...newNfts]); } + } else { + props.setAllNFTs([]); } } catch (error) { console.log('Error fetching NFTs:', error); @@ -185,21 +194,17 @@ const NFTsExpandedSection = (props) => {

Explore

- {props.activeFilter === 'liked' && props.allNfts.length === 0 - ? null - : props.filters.map((filter, index) => ( -
props.setActiveFilter(filter)} - > - {filter} -
- ))} + {props.filters.map((filter, index) => ( +
props.setActiveFilter(filter)} + > + {filter} +
+ ))}
handleRoundChange('prev')} @@ -219,26 +224,27 @@ const NFTsExpandedSection = (props) => {
- {props.allNfts - .filter((nft) => nft.dayIndex === dayIndex) - .map((nft, index) => ( - - ))} + {(props.allNfts.length > 0 || props.activeFilter !== 'liked') && + props.allNfts + .filter((nft) => nft.dayIndex === dayIndex) + .map((nft, index) => ( + + ))}
nft.dayIndex === dayIndex)} From 6d976159a08bd98eb437b4197dc20926049eb965 Mon Sep 17 00:00:00 2001 From: Supreme2580 Date: Fri, 29 Nov 2024 01:18:11 +0100 Subject: [PATCH 06/13] like filter --- frontend/src/tabs/nfts/NFTs.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/frontend/src/tabs/nfts/NFTs.js b/frontend/src/tabs/nfts/NFTs.js index 21541647..64cea0f0 100644 --- a/frontend/src/tabs/nfts/NFTs.js +++ b/frontend/src/tabs/nfts/NFTs.js @@ -96,18 +96,17 @@ const NFTsMainSection = (props) => { }; const NFTsExpandedSection = (props) => { - const [currentRound, setCurrentRound] = useState(1); + const round = process.env.REACT_APP_ROUND_NUMBER || 1; + const [currentRound, setCurrentRound] = useState(round); const dayIndex = currentRound - 1; const imageURL = `${nftUrl}/nft/round-${currentRound}/images/`; const metadataURL = `${nftUrl}/nft/round-${currentRound}/metadata/`; const handleRoundChange = (direction) => { - const maxRound = 100; - if (direction === 'prev' && currentRound > 1) { setCurrentRound((prev) => prev - 1); props.setAllNftPagination((prev) => ({ ...prev, page: 1 })); - } else if (direction === 'next' && currentRound < maxRound) { + } else if (direction === 'next' && currentRound < round) { setCurrentRound((prev) => prev + 1); props.setAllNftPagination((prev) => ({ ...prev, page: 1 })); } From c3693f698baaf9b6c79d2c381e40273addd7937b Mon Sep 17 00:00:00 2001 From: Supreme2580 Date: Tue, 3 Dec 2024 17:21:59 +0100 Subject: [PATCH 07/13] updated --- backend/routes/nft.go | 102 ++-------------------------- frontend/src/services/apiService.js | 40 +++++------ frontend/src/tabs/nfts/NFTs.js | 92 ++----------------------- 3 files changed, 30 insertions(+), 204 deletions(-) diff --git a/backend/routes/nft.go b/backend/routes/nft.go index e2b62ede..27713d0b 100644 --- a/backend/routes/nft.go +++ b/backend/routes/nft.go @@ -24,10 +24,9 @@ func InitNFTRoutes() { http.HandleFunc("/get-nft-pixel-data", getNftPixelData) // http.HandleFunc("/like-nft", LikeNFT) // http.HandleFunc("/unlike-nft", UnLikeNFT) + http.HandleFunc("/get-liked-nfts", getLikedNFTs) http.HandleFunc("/get-top-nfts", getTopNFTs) http.HandleFunc("/get-hot-nfts", getHotNFTs) - http.HandleFunc("/get-round-nfts", getRoundNFTs) - http.HandleFunc("/get-liked-nfts", getLikedNFTs) if !core.ArtPeaceBackend.BackendConfig.Production { http.HandleFunc("/mint-nft-devnet", mintNFTDevnet) http.HandleFunc("/like-nft-devnet", likeNFTDevnet) @@ -96,11 +95,6 @@ func getMyNFTs(w http.ResponseWriter, r *http.Request) { } offset := (page - 1) * pageLength - roundNumber, err := strconv.Atoi(r.URL.Query().Get("round")) - if err != nil { - roundNumber = -1 - } - query := ` SELECT nfts.*, @@ -119,10 +113,9 @@ func getMyNFTs(w http.ResponseWriter, r *http.Request) { ) nftlikes ON nfts.token_id = nftlikes.nftKey WHERE nfts.owner = $1 - AND ($4 < 0 OR nfts.day_index = $4) ORDER BY nfts.token_id DESC LIMIT $2 OFFSET $3` - nfts, err := core.PostgresQueryJson[NFTData](query, address, pageLength, offset, roundNumber) + nfts, err := core.PostgresQueryJson[NFTData](query, address, pageLength, offset) if err != nil { routeutils.WriteErrorJson(w, http.StatusInternalServerError, "Failed to retrieve NFTs") return @@ -161,11 +154,6 @@ func getNFTs(w http.ResponseWriter, r *http.Request) { } offset := (page - 1) * pageLength - roundNumber, err := strconv.Atoi(r.URL.Query().Get("round")) - if err != nil { - roundNumber = -1 - } - query := ` SELECT nfts.*, @@ -182,10 +170,9 @@ func getNFTs(w http.ResponseWriter, r *http.Request) { GROUP BY nftKey ) nftlikes ON nfts.token_id = nftlikes.nftKey - WHERE ($4 < 0 OR nfts.day_index = $4) ORDER BY nfts.token_id DESC LIMIT $2 OFFSET $3` - nfts, err := core.PostgresQueryJson[NFTData](query, address, pageLength, offset, roundNumber) + nfts, err := core.PostgresQueryJson[NFTData](query, address, pageLength, offset) if err != nil { routeutils.WriteErrorJson(w, http.StatusInternalServerError, "Failed to retrieve NFTs") return @@ -211,11 +198,6 @@ func getNewNFTs(w http.ResponseWriter, r *http.Request) { } offset := (page - 1) * pageLength - roundNumber, err := strconv.Atoi(r.URL.Query().Get("round")) - if err != nil { - roundNumber = -1 - } - query := ` SELECT nfts.*, @@ -232,10 +214,9 @@ func getNewNFTs(w http.ResponseWriter, r *http.Request) { GROUP BY nftKey ) nftlikes ON nfts.token_id = nftlikes.nftKey - WHERE ($4 < 0 OR nfts.day_index = $4) ORDER BY nfts.token_id DESC LIMIT $2 OFFSET $3` - nfts, err := core.PostgresQueryJson[NFTData](query, address, pageLength, offset, roundNumber) + nfts, err := core.PostgresQueryJson[NFTData](query, address, pageLength, offset) if err != nil { routeutils.WriteErrorJson(w, http.StatusInternalServerError, "Failed to retrieve NFTs") return @@ -426,11 +407,6 @@ func getTopNFTs(w http.ResponseWriter, r *http.Request) { } offset := (page - 1) * pageLength - roundNumber, err := strconv.Atoi(r.URL.Query().Get("round")) - if err != nil { - roundNumber = -1 - } - query := ` SELECT nfts.*, @@ -447,11 +423,10 @@ func getTopNFTs(w http.ResponseWriter, r *http.Request) { GROUP BY nftKey ) nftlikes ON nfts.token_id = nftlikes.nftKey - WHERE ($4 < 0 OR nfts.day_index = $4) ORDER BY likes DESC LIMIT $2 OFFSET $3` - nfts, err := core.PostgresQueryJson[NFTData](query, address, pageLength, offset, roundNumber) + nfts, err := core.PostgresQueryJson[NFTData](query, address, pageLength, offset) if err != nil { routeutils.WriteErrorJson(w, http.StatusInternalServerError, "Failed to retrieve NFTs") return @@ -537,11 +512,6 @@ func getHotNFTs(w http.ResponseWriter, r *http.Request) { } offset := (page - 1) * pageLength - roundNumber, err := strconv.Atoi(r.URL.Query().Get("round")) - if err != nil { - roundNumber = -1 - } - query := ` SELECT nfts.*, @@ -567,10 +537,9 @@ func getHotNFTs(w http.ResponseWriter, r *http.Request) { ) latestlikes GROUP BY nftkey ) rank ON nfts.token_id = rank.nftkey - WHERE ($5 < 0 OR nfts.day_index = $5) ORDER BY COALESCE(rank, 0) DESC LIMIT $3 OFFSET $4;` - nfts, err := core.PostgresQueryJson[NFTData](query, address, hotLimit, pageLength, offset, roundNumber) + nfts, err := core.PostgresQueryJson[NFTData](query, address, hotLimit, pageLength, offset) if err != nil { routeutils.WriteErrorJson(w, http.StatusInternalServerError, "Failed to retrieve Hot NFTs") return @@ -578,57 +547,6 @@ func getHotNFTs(w http.ResponseWriter, r *http.Request) { routeutils.WriteDataJson(w, string(nfts)) } -func getRoundNFTs(w http.ResponseWriter, r *http.Request) { - address := r.URL.Query().Get("address") - if address == "" { - address = "0" - } - roundNumber, err := strconv.Atoi(r.URL.Query().Get("round")) - if err != nil || roundNumber < 0 { - routeutils.WriteErrorJson(w, http.StatusBadRequest, "Invalid round number") - return - } - pageLength, err := strconv.Atoi(r.URL.Query().Get("pageLength")) - if err != nil || pageLength <= 0 { - pageLength = 25 - } - if pageLength > 50 { - pageLength = 50 - } - page, err := strconv.Atoi(r.URL.Query().Get("page")) - if err != nil || page <= 0 { - page = 1 - } - offset := (page - 1) * pageLength - - query := ` - SELECT - nfts.*, - COALESCE(like_count, 0) AS likes, - COALESCE((SELECT true FROM nftlikes WHERE liker = $1 AND nftlikes.nftkey = nfts.token_id), false) as liked - FROM - nfts - LEFT JOIN ( - SELECT - nftKey, - COUNT(*) AS like_count - FROM - nftlikes - GROUP BY - nftKey - ) nftlikes ON nfts.token_id = nftlikes.nftKey - WHERE - nfts.day_index = $2 - ORDER BY nfts.token_id DESC - LIMIT $3 OFFSET $4` - nfts, err := core.PostgresQueryJson[NFTData](query, address, roundNumber, pageLength, offset) - if err != nil { - routeutils.WriteErrorJson(w, http.StatusInternalServerError, "Failed to retrieve NFTs") - return - } - routeutils.WriteDataJson(w, string(nfts)) -} - func getLikedNFTs(w http.ResponseWriter, r *http.Request) { address := r.URL.Query().Get("address") if address == "" || address == "0" { @@ -650,11 +568,6 @@ func getLikedNFTs(w http.ResponseWriter, r *http.Request) { } offset := (page - 1) * pageLength - roundNumber, err := strconv.Atoi(r.URL.Query().Get("round")) - if err != nil { - roundNumber = -1 - } - query := ` SELECT nfts.*, @@ -677,11 +590,10 @@ func getLikedNFTs(w http.ResponseWriter, r *http.Request) { FROM nftlikes WHERE liker = $1 ) - AND ($4 < 0 OR nfts.day_index = $4) ORDER BY nfts.token_id DESC LIMIT $2 OFFSET $3` - nfts, err := core.PostgresQueryJson[NFTData](query, address, pageLength, offset, roundNumber) + nfts, err := core.PostgresQueryJson[NFTData](query, address, pageLength, offset) if err != nil { routeutils.WriteErrorJson(w, http.StatusInternalServerError, "Failed to retrieve liked NFTs") return diff --git a/frontend/src/services/apiService.js b/frontend/src/services/apiService.js index c1f23183..8bb36996 100644 --- a/frontend/src/services/apiService.js +++ b/frontend/src/services/apiService.js @@ -55,7 +55,7 @@ export const addFactionTemplateDevnet = async (metadata) => { */ export const getMyNftsFn = async (query) => { return await fetchWrapper( - `get-my-nfts?address=${query.queryAddress}&pageLength=${query.pageLength}&page=${query.page}&round=${query.roundNumber}` + `get-my-nfts?address=${query.queryAddress}&pageLength=${query.pageLength}&page=${query.page}` ); }; @@ -67,10 +67,9 @@ export const getMyNftsFn = async (query) => { * @param {number} query.page - The page number to fetch. * @returns {Promise} The response from the fetch call. */ -export const getNftsFn = async (params) => { - const { page, pageLength, queryAddress, roundNumber } = params; +export const getNftsFn = async (query) => { return await fetchWrapper( - `get-nfts?address=${queryAddress}&page=${page}&pageLength=${pageLength}&round=${roundNumber}` + `get-nfts?pageLength=${query.pageLength}&page=${query.page}` ); }; @@ -85,9 +84,9 @@ export const getChainFactions = async (query) => { }; export const getNewNftsFn = async (params) => { - const { page, pageLength, queryAddress, roundNumber } = params; + const { page, pageLength, queryAddress } = params; return await fetchWrapper( - `get-new-nfts?address=${queryAddress}&page=${page}&pageLength=${pageLength}&round=${roundNumber}` + `get-new-nfts?address=${queryAddress}&page=${page}&pageLength=${pageLength}` ); }; @@ -101,30 +100,16 @@ export const getNewNftsFn = async (params) => { * @returns {Promise} The response from the fetch call. */ export const getTopNftsFn = async (params) => { - const { page, pageLength, queryAddress, roundNumber } = params; + const { page, pageLength, queryAddress } = params; return await fetchWrapper( - `get-top-nfts?address=${queryAddress}&page=${page}&pageLength=${pageLength}&round=${roundNumber}` + `get-top-nfts?address=${queryAddress}&page=${page}&pageLength=${pageLength}` ); }; export const getHotNftsFn = async (params) => { - const { page, pageLength, queryAddress, roundNumber } = params; + const { page, pageLength, queryAddress } = params; return await fetchWrapper( - `get-hot-nfts?address=${queryAddress}&page=${page}&pageLength=${pageLength}&round=${roundNumber}` - ); -}; - -export const getLikedNftsFn = async (params) => { - const { page, pageLength, queryAddress, roundNumber } = params; - return await fetchWrapper( - `get-liked-nfts?address=${queryAddress}&page=${page}&pageLength=${pageLength}&round=${roundNumber}` - ); -}; - -export const getRoundNftsFn = async (params) => { - const { page, pageLength, queryAddress, roundNumber } = params; - return await fetchWrapper( - `get-round-nfts?address=${queryAddress}&page=${page}&pageLength=${pageLength}&round=${roundNumber}` + `get-hot-nfts?address=${queryAddress}&page=${page}&pageLength=${pageLength}` ); }; @@ -139,3 +124,10 @@ export const getFactionMembers = async (query) => { `get-faction-members?factionId=${query.factionId}&page=${query.page}&pageLength=${query.pageLength}` ); }; + +export const getLikedNftsFn = async (params) => { + const { page, pageLength, queryAddress } = params; + return await fetchWrapper( + `get-liked-nfts?address=${queryAddress}&page=${page}&pageLength=${pageLength}` + ); +}; \ No newline at end of file diff --git a/frontend/src/tabs/nfts/NFTs.js b/frontend/src/tabs/nfts/NFTs.js index 64cea0f0..d64f877e 100644 --- a/frontend/src/tabs/nfts/NFTs.js +++ b/frontend/src/tabs/nfts/NFTs.js @@ -96,9 +96,8 @@ const NFTsMainSection = (props) => { }; const NFTsExpandedSection = (props) => { - const round = process.env.REACT_APP_ROUND_NUMBER || 1; - const [currentRound, setCurrentRound] = useState(round); - const dayIndex = currentRound - 1; + const maxRound = parseInt(process.env.REACT_APP_ROUND_NUMBER || '1'); + const [currentRound, setCurrentRound] = useState(maxRound); const imageURL = `${nftUrl}/nft/round-${currentRound}/images/`; const metadataURL = `${nftUrl}/nft/round-${currentRound}/metadata/`; @@ -106,88 +105,12 @@ const NFTsExpandedSection = (props) => { if (direction === 'prev' && currentRound > 1) { setCurrentRound((prev) => prev - 1); props.setAllNftPagination((prev) => ({ ...prev, page: 1 })); - } else if (direction === 'next' && currentRound < round) { + } else if (direction === 'next' && currentRound < maxRound) { setCurrentRound((prev) => prev + 1); props.setAllNftPagination((prev) => ({ ...prev, page: 1 })); } }; - useEffect(() => { - async function getNfts() { - try { - let result; - if (props.activeFilter === 'hot') { - result = await getHotNftsFn({ - page: props.allNftPagination.page, - pageLength: props.allNftPagination.pageLength, - queryAddress: props.queryAddress, - roundNumber: dayIndex - }); - } else if (props.activeFilter === 'new') { - result = await getNewNftsFn({ - page: props.allNftPagination.page, - pageLength: props.allNftPagination.pageLength, - queryAddress: props.queryAddress, - roundNumber: dayIndex - }); - } else if (props.activeFilter === 'top') { - result = await getTopNftsFn({ - page: props.allNftPagination.page, - pageLength: props.allNftPagination.pageLength, - queryAddress: props.queryAddress, - roundNumber: dayIndex - }); - } else if (props.activeFilter === 'liked') { - result = await getLikedNftsFn({ - page: props.allNftPagination.page, - pageLength: props.allNftPagination.pageLength, - queryAddress: props.queryAddress, - roundNumber: dayIndex - }); - } else { - result = await getRoundNftsFn({ - page: props.allNftPagination.page, - pageLength: props.allNftPagination.pageLength, - queryAddress: props.queryAddress, - roundNumber: dayIndex - }); - } - - if (result.data) { - const roundNfts = result.data.filter( - (nft) => nft.dayIndex === dayIndex - ); - - if (props.allNftPagination.page === 1) { - props.setAllNFTs(roundNfts); - } else { - const newNfts = roundNfts.filter( - (nft) => - !props.allNfts.some( - (existingNft) => existingNft.tokenId === nft.tokenId - ) - ); - props.setAllNFTs([...props.allNfts, ...newNfts]); - } - } else { - props.setAllNFTs([]); - } - } catch (error) { - console.log('Error fetching NFTs:', error); - } - } - - if (props.expanded) { - getNfts(); - } - }, [ - currentRound, - props.allNftPagination, - props.activeFilter, - props.queryAddress, - props.expanded - ]); - return (
@@ -223,11 +146,10 @@ const NFTsExpandedSection = (props) => {
- {(props.allNfts.length > 0 || props.activeFilter !== 'liked') && - props.allNfts - .filter((nft) => nft.dayIndex === dayIndex) - .map((nft, index) => ( - 0 || props.activeFilter !== 'liked') && + props.allNfts.map((nft, index) => ( + Date: Tue, 3 Dec 2024 17:42:20 +0100 Subject: [PATCH 08/13] prettier --- frontend/src/services/apiService.js | 2 +- frontend/src/tabs/nfts/NFTs.js | 32 ++++++++++++++--------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/frontend/src/services/apiService.js b/frontend/src/services/apiService.js index 8bb36996..b3bcafb0 100644 --- a/frontend/src/services/apiService.js +++ b/frontend/src/services/apiService.js @@ -130,4 +130,4 @@ export const getLikedNftsFn = async (params) => { return await fetchWrapper( `get-liked-nfts?address=${queryAddress}&page=${page}&pageLength=${pageLength}` ); -}; \ No newline at end of file +}; diff --git a/frontend/src/tabs/nfts/NFTs.js b/frontend/src/tabs/nfts/NFTs.js index d64f877e..7cc0063c 100644 --- a/frontend/src/tabs/nfts/NFTs.js +++ b/frontend/src/tabs/nfts/NFTs.js @@ -150,22 +150,22 @@ const NFTsExpandedSection = (props) => { (props.allNfts.length > 0 || props.activeFilter !== 'liked') && props.allNfts.map((nft, index) => ( - ))} + key={index} + {...nft} + address={props.address} + account={props.account} + estimateInvokeFee={props.estimateInvokeFee} + artPeaceContract={props.artPeaceContract} + canvasNftContract={props.canvasNftContract} + image={imageURL + 'nft-' + nft.tokenId + '.png'} + metadata={metadataURL + 'nft-' + nft.tokenId + '.json'} + queryAddress={props.queryAddress} + updateLikes={props.updateLikes} + setTemplateOverlayMode={props.setTemplateOverlayMode} + setOverlayTemplate={props.setOverlayTemplate} + setActiveTab={props.setActiveTab} + /> + ))}
nft.dayIndex === dayIndex)} From 0f6ff0dcaaaaaf923c54dd369dcfd92e5dbc59bb Mon Sep 17 00:00:00 2001 From: Supreme2580 Date: Tue, 3 Dec 2024 17:42:58 +0100 Subject: [PATCH 09/13] removed unused --- frontend/src/tabs/nfts/NFTs.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frontend/src/tabs/nfts/NFTs.js b/frontend/src/tabs/nfts/NFTs.js index 7cc0063c..8b2726b3 100644 --- a/frontend/src/tabs/nfts/NFTs.js +++ b/frontend/src/tabs/nfts/NFTs.js @@ -10,7 +10,6 @@ import { getNewNftsFn, getTopNftsFn, getHotNftsFn, - getRoundNftsFn, getLikedNftsFn } from '../../services/apiService.js'; import { PaginationView } from '../../ui/pagination.js'; @@ -168,7 +167,7 @@ const NFTsExpandedSection = (props) => { ))}
nft.dayIndex === dayIndex)} + data={props.allNfts} setState={props.setAllNftPagination} stateValue={props.allNftPagination} /> From 2fd98c458a39be32d62524d382611aa48f8f1b19 Mon Sep 17 00:00:00 2001 From: Supreme2580 Date: Wed, 4 Dec 2024 08:23:28 +0100 Subject: [PATCH 10/13] updated --- backend/config/canvas.go | 2 ++ backend/routes/canvas.go | 11 +++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/backend/config/canvas.go b/backend/config/canvas.go index 31466fee..ee18f1bd 100644 --- a/backend/config/canvas.go +++ b/backend/config/canvas.go @@ -15,6 +15,7 @@ type CanvasConfig struct { Colors []string `json:"colors"` VotableColors []string `json:"votableColors"` ColorsBitWidth uint `json:"colorsBitwidth"` + Round uint `json:"round"` } var DefaultCanvasConfig = &CanvasConfig{ @@ -42,6 +43,7 @@ var DefaultCanvasConfig = &CanvasConfig{ "#00DDDD", }, ColorsBitWidth: 5, + Round: 2, } var DefaultCanvasConfigPath = "../configs/canvas.config.json" diff --git a/backend/routes/canvas.go b/backend/routes/canvas.go index 1eb02263..faacf4a3 100644 --- a/backend/routes/canvas.go +++ b/backend/routes/canvas.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "net/http" + "strconv" "github.com/keep-starknet-strange/art-peace/backend/core" routeutils "github.com/keep-starknet-strange/art-peace/backend/routes/utils" @@ -20,11 +21,10 @@ func initCanvas(w http.ResponseWriter, r *http.Request) { return } - // Get round number from query params + // Get round number from query params, default to config round roundNumber := r.URL.Query().Get("round") if roundNumber == "" { - routeutils.WriteErrorJson(w, http.StatusBadRequest, "Round number is required") - return + roundNumber = strconv.FormatUint(uint64(core.ArtPeaceBackend.CanvasConfig.Round), 10) } canvasKey := fmt.Sprintf("canvas-%s", roundNumber) @@ -55,11 +55,10 @@ func initCanvas(w http.ResponseWriter, r *http.Request) { func getCanvas(w http.ResponseWriter, r *http.Request) { routeutils.SetupAccessHeaders(w) - // Get round number from query params, default to latest round if not specified + // Get round number from query params, default to config round roundNumber := r.URL.Query().Get("round") if roundNumber == "" { - // TODO: Implement logic to get latest round number - roundNumber = "1" // Default to round 1 for now + roundNumber = strconv.FormatUint(uint64(core.ArtPeaceBackend.CanvasConfig.Round), 10) } canvasKey := fmt.Sprintf("canvas-%s", roundNumber) From 40ef42dbe41ee71ec2b67322bd3c85308b3b97ce Mon Sep 17 00:00:00 2001 From: Supreme2580 Date: Wed, 4 Dec 2024 08:54:14 +0100 Subject: [PATCH 11/13] updated all config.json files --- configs/canvas.config.json | 3 ++- frontend/src/configs/canvas.config.json | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/configs/canvas.config.json b/configs/canvas.config.json index f16844e6..2504bd26 100644 --- a/configs/canvas.config.json +++ b/configs/canvas.config.json @@ -47,5 +47,6 @@ "898D90", "D4D7D9" ], - "colorsBitwidth": 5 + "colorsBitwidth": 5, + "round": 2 } diff --git a/frontend/src/configs/canvas.config.json b/frontend/src/configs/canvas.config.json index f16844e6..2504bd26 100644 --- a/frontend/src/configs/canvas.config.json +++ b/frontend/src/configs/canvas.config.json @@ -47,5 +47,6 @@ "898D90", "D4D7D9" ], - "colorsBitwidth": 5 + "colorsBitwidth": 5, + "round": 2 } From a8c16415e859a69ad8e0e398b8aa649ab96549ed Mon Sep 17 00:00:00 2001 From: Brandon Roberts Date: Wed, 4 Dec 2024 03:26:25 -0600 Subject: [PATCH 12/13] Update default round in docker compose files --- backend/routes/canvas.go | 15 +++++---------- docker-compose.yml | 6 +++--- main-docker-compose.yml | 6 +++--- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/backend/routes/canvas.go b/backend/routes/canvas.go index faacf4a3..e68899e2 100644 --- a/backend/routes/canvas.go +++ b/backend/routes/canvas.go @@ -21,13 +21,8 @@ func initCanvas(w http.ResponseWriter, r *http.Request) { return } - // Get round number from query params, default to config round - roundNumber := r.URL.Query().Get("round") - if roundNumber == "" { - roundNumber = strconv.FormatUint(uint64(core.ArtPeaceBackend.CanvasConfig.Round), 10) - } - - canvasKey := fmt.Sprintf("canvas-%s", roundNumber) + roundNumber := core.ArtPeaceBackend.CanvasConfig.Round + canvasKey := fmt.Sprintf("canvas-%d", roundNumber) if core.ArtPeaceBackend.Databases.Redis.Exists(context.Background(), canvasKey).Val() == 0 { totalBitSize := core.ArtPeaceBackend.CanvasConfig.Canvas.Width * core.ArtPeaceBackend.CanvasConfig.Canvas.Height * core.ArtPeaceBackend.CanvasConfig.ColorsBitWidth @@ -46,9 +41,9 @@ func initCanvas(w http.ResponseWriter, r *http.Request) { return } - routeutils.WriteResultJson(w, fmt.Sprintf("Canvas for round %s initialized", roundNumber)) + routeutils.WriteResultJson(w, fmt.Sprintf("Canvas for round %d initialized", roundNumber)) } else { - routeutils.WriteErrorJson(w, http.StatusConflict, fmt.Sprintf("Canvas for round %s already initialized", roundNumber)) + routeutils.WriteErrorJson(w, http.StatusConflict, fmt.Sprintf("Canvas for round %d already initialized", roundNumber)) } } @@ -58,7 +53,7 @@ func getCanvas(w http.ResponseWriter, r *http.Request) { // Get round number from query params, default to config round roundNumber := r.URL.Query().Get("round") if roundNumber == "" { - roundNumber = strconv.FormatUint(uint64(core.ArtPeaceBackend.CanvasConfig.Round), 10) + roundNumber = strconv.Itoa(int(core.ArtPeaceBackend.CanvasConfig.Round)) } canvasKey := fmt.Sprintf("canvas-%s", roundNumber) diff --git a/docker-compose.yml b/docker-compose.yml index b42dbe57..68a4309e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -35,7 +35,7 @@ services: - POSTGRES_PASSWORD=password - ART_PEACE_END_TIME=3000000000 - ART_PEACE_HOST=0328ced46664355fc4b885ae7011af202313056a7e3d44827fb24c9d3206aaa0 - - ROUND_NUMBER=1 + - ROUND_NUMBER=2 volumes: - nfts:/app/nfts consumer: @@ -50,7 +50,7 @@ services: restart: always environment: - POSTGRES_PASSWORD=password - - ROUND_NUMBER=1 + - ROUND_NUMBER=2 volumes: - nfts:/app/nfts - worlds:/app/worlds @@ -143,7 +143,7 @@ services: - devnet environment: - REACT_APP_BASE_PIXEL_TIMER=30000 - - REACT_APP_ROUND_NUMBER=1 + - REACT_APP_ROUND_NUMBER=2 volumes: - ./frontend/package.json:/app/package.json - ./frontend/package-lock.json:/app/package-lock.json diff --git a/main-docker-compose.yml b/main-docker-compose.yml index 55e12a46..c107881e 100644 --- a/main-docker-compose.yml +++ b/main-docker-compose.yml @@ -35,7 +35,7 @@ services: - POSTGRES_PASSWORD=password - ART_PEACE_END_TIME=3000000000 - ART_PEACE_HOST=0328ced46664355fc4b885ae7011af202313056a7e3d44827fb24c9d3206aaa0 - - ROUND_NUMBER=1 + - ROUND_NUMBER=2 consumer: build: dockerfile: backend/Dockerfile.consumer @@ -48,7 +48,7 @@ services: restart: always environment: - POSTGRES_PASSWORD=password - - ROUND_NUMBER=1 + - ROUND_NUMBER=2 volumes: - nfts:/app/nfts devnet: @@ -140,7 +140,7 @@ services: - devnet environment: - REACT_APP_BASE_PIXEL_TIMER=30000 - - REACT_APP_ROUND_NUMBER=1 + - REACT_APP_ROUND_NUMBER=2 volumes: - ./frontend/package.json:/app/package.json - ./frontend/package-lock.json:/app/package-lock.json From e5f99c13c302b5af865be183cfde1adc3e8afe95 Mon Sep 17 00:00:00 2001 From: Brandon Roberts Date: Wed, 4 Dec 2024 03:27:45 -0600 Subject: [PATCH 13/13] Go fmt --- backend/routes/canvas.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/routes/canvas.go b/backend/routes/canvas.go index e68899e2..41e22cfa 100644 --- a/backend/routes/canvas.go +++ b/backend/routes/canvas.go @@ -21,7 +21,7 @@ func initCanvas(w http.ResponseWriter, r *http.Request) { return } - roundNumber := core.ArtPeaceBackend.CanvasConfig.Round + roundNumber := core.ArtPeaceBackend.CanvasConfig.Round canvasKey := fmt.Sprintf("canvas-%d", roundNumber) if core.ArtPeaceBackend.Databases.Redis.Exists(context.Background(), canvasKey).Val() == 0 {