Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
axiinyaa committed Dec 16, 2024
1 parent 0797132 commit 4b9ce59
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 43 deletions.
9 changes: 7 additions & 2 deletions app/database.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,19 @@ export async function GetLeaderboard(sortBy: string) {
const userPromises = result.map(async (doc) => {
const user = await GetDiscordData(doc._id);

if (user.username == '')
{
return null;
}

return { name: user.username, type: sortBy, data: { ...doc, wool: doc.wool.toLocaleString() } as UserData };
});

// Use Promise.all to wait for all promises to resolve
const leaderboardData = await Promise.all(userPromises);
const users = (await Promise.all(userPromises)).filter(user => user !== null);

// Push the resolved data to the leaderboard array
leaderboard.push(...leaderboardData);
leaderboard.push(...users);
} catch (error) {
console.error(error);
}
Expand Down
55 changes: 14 additions & 41 deletions app/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Desktop from "../components/desktop";
import Window from '../components/window';
import BackgroundSelection from "../components/profile/background-selector";
import languages from './languages.json';
import { DiscordLogIn } from "../discord";

export default function Profile() {

Expand Down Expand Up @@ -212,60 +213,32 @@ export default function Profile() {

if (!discordData?.access_token) { return } // If there's no access token then we don't need to do anything yet.

const response = await axios.get('https://discord.com/api/users/@me', { headers: { Authorization: `Bearer ${discordData.access_token}` } })
const data = await DiscordLogIn(discordData);

setUserID(response.data.id)
}
catch (error) {
console.error('Error fetching data from discord:', error);
setPageStatus('error')
}
}

login();

}, [discordData]);

useEffect(() => {
const fetchData = async () => {
try {

if (!userID) { return; } // Don't do anything if we don't have the userID yet.

if (pageStatus === 'success') { return; }

setPageStatus('authenticated')

const data = await fetchFromDatabase(userID);

if (!data) {
console.error('For some reason data was never fetched.');
setPageStatus('error'); // Run error scenario if data doesn't exist... for whatever reason.
return
if (data == null) {
setPageStatus('error');
return;
}

setUserData(data as UserData)
setUserData(data)

// Set fucking text length because haha funny react won't rerender unless i do this
setPageStatus('authenticated')

setTextLength(data.profile_description.length)
setChecked(data.badge_notifications);
setUserToUpdate({ ...data } as UserData)

let all_bgs: any[] = [];


setPageStatus('success');

} catch (error) {
console.error('Error fetching data from database:', error);
setPageStatus('error');
}

catch (error) {
console.error('Error fetching data from discord:', error);
setPageStatus('error')
}
}

fetchData();
login();

}, [userID])
}, [discordData]);

useEffect(() => {
const updateData = async () => {
Expand Down

0 comments on commit 4b9ce59

Please sign in to comment.