Skip to content

Commit

Permalink
Refactor user profile data retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
miggi92 committed Dec 8, 2023
1 parent c9d8202 commit e9cf61c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 32 deletions.
20 changes: 4 additions & 16 deletions components/user/Avatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,10 @@ const user = useSupabaseUser()
const supabase = useSupabaseClient()
const userData = user.value;
var userAvatar = "";
await supabase
.from('profiles')
.select('id, avatar_url')
.eq('id', userData?.id)
.then(({ data, error }) => {
if (error) {
useToast().add({ title: 'User read failed', description: error.message })
console.log(error)
} else {
if (data.length > 0) {
userAvatar = data[0].avatar_url;
}
}
})
const { data: userAvatar } = await useAsyncData('userAvatar', async () => {
const { data } = await supabase.from('profiles').select('id, avatar_url').eq('id', userData?.id).single();
return data.avatar_url
});
</script>

Expand Down
24 changes: 9 additions & 15 deletions components/user/ProfileCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,15 @@ const state = reactive({
username: ""
})
await supabase
.from('profiles')
.select('id, username')
.eq('id', userData?.id)
.then(({ data, error }) => {
if (error) {
console.log(error)
} else {
if (data.length > 0) {
state.username = data[0].username;
}
}
})
const { data: userName, error } = await useAsyncData('userName', async () => {
const { data } = await supabase.from('profiles').select('id, username').eq('id', userData?.id).single();
return data?.username
});
state.username = userName;
// if (error) {
// console.log(error)
// useToast().add({ title: 'Get username failed', description: error.message })
// }
const onUpdate = async () => {
const updates = {
Expand Down
1 change: 0 additions & 1 deletion pages/teams.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
</template>

<script setup lang="ts">
import type { Team } from '~/types';
const supabase = useSupabaseClient();
const { pending, data: teams } = await useAsyncData('teams', async () => {
Expand Down

0 comments on commit e9cf61c

Please sign in to comment.