-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(frontend) auth redirect to homepage
- Loading branch information
1 parent
2dfb4c4
commit c202664
Showing
4 changed files
with
67 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,46 @@ | ||
<!-- Home.vue --> | ||
<!-- views/HomePage.vue --> | ||
|
||
<template> | ||
<div class="container"> | ||
<h1>Welcome to the Home Page</h1> | ||
<p>You are logged in as {{ username }}</p> | ||
<h1>Home Page</h1> | ||
<p>Welcome to the Home Page, {{ username }}</p> | ||
<h2>Your Villages</h2> | ||
<ul> | ||
<li v-for="village in villages" :key="village.village_id"> | ||
<h3>{{ village.name }}</h3> | ||
<p>Population: {{ village.population }}</p> | ||
<p>Position ID: {{ village.position_id }}</p> | ||
</li> | ||
</ul> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent, computed } from 'vue'; | ||
import { defineComponent, computed, onMounted } from 'vue'; | ||
import { useAuthStore } from '@/store/auth'; | ||
import { useVillagesStore } from '@/store/villages'; | ||
export default defineComponent({ | ||
name: 'Home', | ||
name: 'HomePage', | ||
setup() { | ||
const authStore = useAuthStore(); | ||
const villagesStore = useVillagesStore(); | ||
const username = computed(() => authStore.username); | ||
const villages = computed(() => villagesStore.villages); | ||
onMounted(async () => { | ||
await villagesStore.fetchVillages(); | ||
}); | ||
return { | ||
username, | ||
villages, | ||
}; | ||
} | ||
}); | ||
</script> | ||
|
||
<style scoped> | ||
/* Add your scoped styles for Home */ | ||
/* Add your styles for HomePage */ | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// store/villages.ts | ||
|
||
import { defineStore } from 'pinia'; | ||
import { getAllVillages } from '@/api/api'; | ||
|
||
interface Village { | ||
village_id: number; | ||
name: string; | ||
owner_id: number; | ||
position_id: number; | ||
population: number; | ||
} | ||
|
||
interface VillagesState { | ||
villages: Village[]; | ||
} | ||
|
||
export const useVillagesStore = defineStore('villages', { | ||
state: (): VillagesState => ({ | ||
villages: [] | ||
}), | ||
actions: { | ||
async fetchVillages() { | ||
try { | ||
const data = await getAllVillages(); | ||
this.villages = data.villages; | ||
} catch (error) { | ||
console.error('Failed to fetch villages:', error); | ||
} | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters