Skip to content

Commit d8b7149

Browse files
authored
Merge pull request #55 from BeatBuzzer/feat/total-games
Feat/total games
2 parents d6dfa40 + 8c017f1 commit d8b7149

File tree

6 files changed

+780
-22
lines changed

6 files changed

+780
-22
lines changed

components/profile/ProfileInformation.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
<script setup lang="ts">
22
33
const session = useSupabaseSession()
4-
const { user, loading, error, fetchUser } = useUser()
4+
const { user, loading, error, fetchUser, fetchTotalGames } = useUser()
5+
const { fetchGames } = useGame()
6+
7+
const totalGames = useState<string | null>('userTotalGames', () => null)
58
69
onMounted(async () => {
710
if (session.value) {
8-
await fetchUser()
11+
await fetchUser();
12+
await fetchGames();
13+
await fetchTotalGames();
914
}
1015
})
1116
@@ -33,7 +38,8 @@ const formatDate = (dateString: string) => {
3338

3439
<div class="grid grid-cols-2 gap-2">
3540
<div class="bg-gray-200 h-8 rounded-3xl bg-yellow-500 px-2 flex items-center">
36-
Games played
41+
<Icon name="mdi:controller" class="text-2xl mr-2 text-red-600" />
42+
{{ totalGames }} Games
3743
</div>
3844
<div class="bg-gray-200 h-8 rounded-3xl bg-yellow-500 px-2 flex items-center">
3945
<Icon name="mdi:fire" class="text-2xl mr-2 text-red-600" />

composables/useSpotify.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ export default function useSpotify(playlistId: string) {
118118
}
119119
}
120120

121-
122121
async function getTrackCover(trackId: string): Promise<string> {
123122
try {
124123
const res = await fetch(`https://api.spotify.com/v1/tracks/${trackId}`, {

composables/useUser.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type {GetUserResponse} from "@/types/api/users";
22

33
export const useUser = () => {
44
const user = useState<GetUserResponse | null>('user', () => null)
5+
const totalGames = useState<number>('userTotalGames', () => 0)
6+
const games = useState<string | null>('games', () => null)
57
const loading = useState<boolean>('userLoading', () => false)
68
const error = useState<string | null>('userError', () => null)
79

@@ -21,11 +23,27 @@ export const useUser = () => {
2123
}
2224
}
2325

26+
const fetchTotalGames = async () => {
27+
try {
28+
totalGames.value = 0;
29+
games.value.past.forEach(item => {
30+
if (item.players[0].id === user.value?.id || item.players[1].id === user.value?.id) {
31+
totalGames.value++;
32+
}
33+
});
34+
} catch (err) {
35+
error.value = 'An error occurred';
36+
console.error('Error fetching user', err)
37+
}
38+
}
39+
2440
return {
2541
user,
42+
totalGames,
2643
loading,
2744
error,
28-
fetchUser
45+
fetchUser,
46+
fetchTotalGames
2947
}
3048
}
3149

0 commit comments

Comments
 (0)