diff --git a/src/app/game/berry-dash/chatroom/page.tsx b/src/app/game/berry-dash/chatroom/page.tsx index 2453435..6486c1a 100644 --- a/src/app/game/berry-dash/chatroom/page.tsx +++ b/src/app/game/berry-dash/chatroom/page.tsx @@ -8,7 +8,6 @@ import { getCookie } from '@/util/cookie' import { formatHumanTime } from '@/util/time' import { faPencil, faTrashCan } from '@fortawesome/free-solid-svg-icons' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' -import axios from 'axios' import { useEffect, useRef, useState } from 'react' interface WSMessage { @@ -35,18 +34,12 @@ interface Message { editing: boolean } -export interface CustomIconEntry { - data: string - id: string -} - export default function BerryDashChatroom () { const [connected, setConnected] = useState(false) const [loggedIn, setLoggedIn] = useState(false) const [editing, setEditing] = useState(false) const [token, setToken] = useState(null) const [messages, setMessages] = useState([]) - const [customIconCache, setCustomIconCache] = useState([]) const [ws, setWs] = useState(null) const messagesDiv = useRef(null) @@ -119,42 +112,6 @@ export default function BerryDashChatroom () { if (messagesDiv.current) { messagesDiv.current.scrollTop = messagesDiv.current.scrollHeight } - const all = customIconCache.map(icon => icon.id) - const allFromMessages = Array.from( - new Set( - messages - .filter(icon => icon.customIcon != null) - .map(icon => icon.customIcon as string) - ) - ) - const notInAllIds = allFromMessages - .filter(id => !all.includes(id)) - .map(id => `"${id}"`) - .join(',') - - if (notInAllIds.length != 0) { - ;(async () => { - const result = await axios.get( - `/api/berrydash/icon-marketplace/icon?ids=[${notInAllIds}]` - ) - if (result.data.success) { - const add: CustomIconEntry[] = [] - for (const item of result.data.data) { - add.push({ - data: item.data, - id: item.id - }) - } - setCustomIconCache(prev => [ - ...prev, - ...result.data.data.map((item: CustomIconEntry) => ({ - data: item.data, - id: item.id - })) - ]) - } - })() - } }, [messages]) return ( @@ -181,11 +138,9 @@ export default function BerryDashChatroom () { ? GetIconForUser(item.userId) : item.icon }.png` - : customIconCache.find(i => i.id === item.customIcon) - ? 'data:image/png;base64,' + - customIconCache.find(i => i.id === item.customIcon) - ?.data - : 'https://games-r2.lncvrt.xyz/game-assets/berrydash/other/loading.png' + : '/api/berrydash/icon-marketplace/icon?id=' + + item.customIcon + + '&raw=true' } className='pointer-events-none' width={48} diff --git a/src/app/game/berry-dash/icon-marketplace/page.tsx b/src/app/game/berry-dash/icon-marketplace/page.tsx index 1fd072c..a88f57e 100644 --- a/src/app/game/berry-dash/icon-marketplace/page.tsx +++ b/src/app/game/berry-dash/icon-marketplace/page.tsx @@ -5,7 +5,6 @@ import axios from 'axios' import { BackButton } from '@/app/components/BackButton' import { ReloadButton } from '@/app/components/ReloadButton' import { UploadButton } from '@/app/components/UploadButton' -import { CustomIconEntry } from '../chatroom/page' interface MarketplaceIcon { username: string @@ -20,7 +19,6 @@ interface MarketplaceIcon { export default function BerryDashIconMarketplace () { const [response, setResponse] = useState(null) - const [customIconCache, setCustomIconCache] = useState([]) async function Refresh () { try { @@ -36,42 +34,6 @@ export default function BerryDashIconMarketplace () { Refresh() }, []) - useEffect(() => { - if (response == null || response == -1) return - const all = customIconCache.map(icon => icon.id) - const allFromMessages = Array.from( - new Set(response.filter(icon => icon.id != null).map(icon => icon.id)) - ) - const notInAllIds = allFromMessages - .filter(id => !all.includes(id)) - .map(id => `"${id}"`) - .join(',') - - if (notInAllIds.length != 0) { - ;(async () => { - const result = await axios.get( - `/api/berrydash/icon-marketplace/icon?ids=[${notInAllIds}]` - ) - if (result.data.success) { - const add: CustomIconEntry[] = [] - for (const item of result.data.data) { - add.push({ - data: item.data, - id: item.id - }) - } - setCustomIconCache(prev => [ - ...prev, - ...result.data.data.map((item: CustomIconEntry) => ({ - data: item.data, - id: item.id - })) - ]) - } - })() - } - }, [response]) - return (
@@ -95,10 +57,9 @@ export default function BerryDashIconMarketplace () {
i.id === icon.id) - ? 'data:image/png;base64,' + - customIconCache.find(i => i.id === icon.id)?.data - : 'https://games-r2.lncvrt.xyz/game-assets/berrydash/other/loading.png' + '/api/berrydash/icon-marketplace/icon?id=' + + icon.id + + '&raw=true' } width={96} height={96} diff --git a/src/app/game/berry-dash/leaderboards/page.tsx b/src/app/game/berry-dash/leaderboards/page.tsx index 6b96809..9b72075 100644 --- a/src/app/game/berry-dash/leaderboards/page.tsx +++ b/src/app/game/berry-dash/leaderboards/page.tsx @@ -3,7 +3,7 @@ import { BackButton } from '@/app/components/BackButton' import { DiscordButton } from '@/app/components/DiscordButton' import { useEffect, useState } from 'react' -import { BirdColor, CustomIconEntry } from '../chatroom/page' +import { BirdColor } from '../chatroom/page' import axios from 'axios' import { GetIconForUser } from '@/util/bd' @@ -23,7 +23,6 @@ export default function BerryDashLeaderboards () { const [selectedBerryOption, setSelectedBerryOption] = useState(0) const [gettingEntries, setGettingEntries] = useState(false) const [entries, setEntries] = useState([]) - const [customIconCache, setCustomIconCache] = useState([]) const Refresh = async () => { setGettingEntries(true) @@ -57,45 +56,6 @@ export default function BerryDashLeaderboards () { if (selected != -1) Refresh() }, [selected]) - useEffect(() => { - const all = customIconCache.map(icon => icon.id) - const allFromMessages = Array.from( - new Set( - entries - .filter(icon => icon.customIcon != null) - .map(icon => icon.customIcon as string) - ) - ) - const notInAllIds = allFromMessages - .filter(id => !all.includes(id)) - .map(id => `"${id}"`) - .join(',') - - if (notInAllIds.length != 0) { - ;(async () => { - const result = await axios.get( - `/api/berrydash/icon-marketplace/icon?ids=[${notInAllIds}]` - ) - if (result.data.success) { - const add: CustomIconEntry[] = [] - for (const item of result.data.data) { - add.push({ - data: item.data, - id: item.id - }) - } - setCustomIconCache(prev => [ - ...prev, - ...result.data.data.map((item: CustomIconEntry) => ({ - data: item.data, - id: item.id - })) - ]) - } - })() - } - }, [entries]) - return (
{selected == -1 ? ( @@ -145,11 +105,9 @@ export default function BerryDashLeaderboards () { ? GetIconForUser(item.id) : item.icon }.png` - : customIconCache.find(i => i.id === item.customIcon) - ? 'data:image/png;base64,' + - customIconCache.find(i => i.id === item.customIcon) - ?.data - : 'https://games-r2.lncvrt.xyz/game-assets/berrydash/other/loading.png' + : '/api/berrydash/icon-marketplace/icon?id=' + + item.customIcon + + '&raw=true' } className='pointer-events-none' width={48}