Lists and Leaderboards
One thing to keep in mind when working with decentralized systems is that there's very minimal support for things like APIs and databases. Instead, we use a combination of on-chain data (via NFTs and GraphQL tags on Arweave) and Koii Tasks running on decentralized nodes.
When constructing a leaderboard or list of content (such as a collection of an Artist's NFTs, or a personalized newsfeed), it's usually necessary to either configure an index or hijack an existing one.
Koii Tasks will go live in Q2 2022, at which point you'll be able to fully customize your system, but until then, the best course of action is likely to process the current Koii Leaderboard APIs clientside and construct your own newsfeed using filters.
View Filters
Filters can be applied to any list component as shown:
๐ฆsrc
โฃ ๐components
โ โ ๐filters
โ โ ๐TimeFilter
// Set up Time Filter components /src/components/TimeFilter
function TimeFilter() {
const [timeframe, setTimeframe] = useQueryParam<string>("t", withDefault(StringParam, "1w"));
const onTimeframeChange = (newValue: string) => {
setTimeframe(newValue, "replaceIn");
return (
<Flex>
<ToggleButtonGroup value={timeframe} defaultValue={timeframe} onChange={onTimeframeChange} name="timeframe" isAttached variant="outline" aria-label="Change timeframe">
<ToggleButton value="24h" aria-label="24 hours" children="24h" />
<ToggleButton value="1w" aria-label="1 week" children="1w" />
<ToggleButton value="1m" aria-label="1 month" children="1m" />
<ToggleButton value="1y" aria-label="1 year" children="1y" />
<ToggleButton value="all" aria-label="all time" children="all" />
</ToggleButtonGroup>
</Flex>
);
};
๐ฆsrc
โฃ ๐api
โ โ ๐hooks
โ โ ๐useNfts.ts
// Use Time Filter /src/api/hooks/useNfts.ts
const fetchNfts = async (timeframe: string = "1w") => {
try {
let nsfwList: any[] = [];
/* Get nsfw list */
await fetchNsfwList()
.then(res => {
nsfwList = res?.data?.NSFWList || [];
})
.catch(() => {}); // We don't want to catch anything.
/* Get nfts based on the timeframe */
const { data } = await axios.get(`/attention/nft-summaries?period=${timeframe}`);
const dataWithNsfwTag = data?.map((nft: any) => ({ ...nft, isNsfw: [...nsfwList].includes(nft?.id) }));
return dataWithNsfwTag;
} catch (error) {
return undefined;
}
};
export function useNfts({ timeframe = "1w" }: Props) {
const [isNsfw] = useQueryParam("nsfw");
return useQuery(`nfts-${timeframe}`, () => fetchNfts(timeframe), {
staleTime: 60 * 1000 * 5, // 5min cache
refetchOnWindowFocus: undefined,
select: data => {
return isNsfw ? data : [...data].filter((nft: any) => !nft.isNsfw);
}
});
}
The default list component fetches the fully Koii NFT list, so configuring views can allow you to select any content you like without rebuilding the Tasks API. If this doesn't work for your use case, please contact our support team and we can help you deploy an Indexing Task of your own!
NSFW
Koii currently manages an NSFW blocked content list which can be accessed using the same API as the main feed. NSFW content can be toggled in list views like this:
Search
Search is currently implemented using clientside libraries which draw from the same core NFT list, and can be customized by editing the Search Component, shown here.
Thumbnails
Since your app will live on decentralized storage, it can sometimes be difficult to generate thumbnail images on the fly for your NFT assets, and it can be even harder to set OpenGraph tags for sharing content.
To streamline this process, Koii has provided a thumbnail generation API powered by Koii Tasks, to which you can POST new NFTs so that they will have nicely formatted previews when sharing on social media.
Last updated
