Skip to content

Commit 613478b

Browse files
committed
Add routing
1 parent bcf1a1b commit 613478b

5 files changed

Lines changed: 67 additions & 12 deletions

File tree

frontend/package-lock.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@mdi/font": "^7.4.47",
1616
"sql.js": "^1.13.0",
1717
"vue": "^3.5.25",
18+
"vue-router": "^4.6.4",
1819
"vuetify": "^3.11.4"
1920
},
2021
"devDependencies": {

frontend/src/App.vue

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
<script setup>
22
import { ref, onMounted } from 'vue'
3+
import { useRoute, useRouter } from 'vue-router'
34
import initSqlJs from 'sql.js';
45
import FileUploaderView from './components/FileUploaderView.vue'
56
import CoinListView from "@/components/CoinListView.vue";
67
import AboutView from "@/components/AboutView.vue";
78
89
const selectedFile = ref(null)
910
const coinsList = ref([])
11+
let isOpened = false;
1012
1113
const db = ref(null);
1214
const status = ref('');
1315
1416
let SQL = null;
1517
16-
const currentComponent = ref('OpenFile');
1718
const drawer = ref(false)
1819
20+
const router = useRouter()
21+
const route = useRoute()
22+
1923
onMounted(async () => {
2024
try {
2125
SQL = await initSqlJs({
@@ -32,7 +36,8 @@ const handleFileUpload = async (file) => {
3236
if (!file) return;
3337
3438
status.value = 'Loading database...';
35-
currentComponent.value = 'CoinList';
39+
router.replace('/')
40+
isOpened = true;
3641
selectedFile.value = file;
3742
3843
const reader = new FileReader();
@@ -73,12 +78,12 @@ const handleFileUpload = async (file) => {
7378
<template>
7479
<v-layout>
7580
<v-app-bar color="primary">
76-
<v-app-bar-nav-icon v-if="currentComponent === 'OpenFile' || currentComponent === 'CoinList'"
81+
<v-app-bar-nav-icon v-if="route.name === 'home' || (route.name === 'open' && !isOpened)"
7782
@click="drawer = !drawer"
7883
></v-app-bar-nav-icon>
7984
<v-app-bar-nav-icon v-else
8085
icon="mdi-chevron-left"
81-
@click="currentComponent = 'OpenFile'"
86+
@click="router.back()"
8287
></v-app-bar-nav-icon>
8388

8489
<v-toolbar-title>OpenNumismat</v-toolbar-title>
@@ -90,27 +95,27 @@ const handleFileUpload = async (file) => {
9095
prepend-icon="mdi-cloud-upload"
9196
title="Open"
9297
value="open"
93-
@click="currentComponent = 'OpenFile'; drawer = false"
94-
:active="currentComponent === 'OpenFile'"
98+
@click="router.push('/open'); drawer = false"
99+
:active="route.name === 'open'"
95100
></v-list-item>
96101
<v-list-item
97102
prepend-icon="mdi-information"
98103
title="About"
99104
value="about"
100-
@click="currentComponent = 'About'; drawer = false"
101-
:active="currentComponent === 'About'"
105+
@click="router.push('about'); drawer = false"
106+
:active="route.name === 'about'"
102107
></v-list-item>
103108
</v-list>
104109
</v-navigation-drawer>
105110

106111
<v-main>
107-
<div v-if="currentComponent === 'OpenFile'">
112+
<div v-if="(route.name === 'home' && !isOpened) || route.name === 'open'">
108113
<FileUploaderView :onFileUploaded="handleFileUpload" />
109114
</div>
110-
<div v-if="currentComponent === 'CoinList'">
115+
<div v-if="route.name === 'home' && isOpened">
111116
<CoinListView :file_name="selectedFile.name" :coins_list="coinsList" />
112117
</div>
113-
<div v-if="currentComponent === 'About'">
118+
<div v-if="route.name === 'about'">
114119
<AboutView />
115120
</div>
116121
<div v-if="status" class="status">{{ status }}</div>

frontend/src/main.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ import * as directives from 'vuetify/directives'
1111

1212
// Components
1313
import App from './App.vue'
14+
import router from './router'
1415

1516
const vuetify = createVuetify({
1617
components,
1718
directives,
1819
})
1920

20-
createApp(App).use(vuetify).mount('#app')
21+
const app = createApp(App)
22+
app.use(router)
23+
app.use(vuetify)
24+
app.mount('#app')

frontend/src/router/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { createRouter, createWebHashHistory } from 'vue-router'
2+
3+
const routes = [
4+
{
5+
path: '/',
6+
name: 'home',
7+
},
8+
{
9+
path: '/open',
10+
name: 'open',
11+
},
12+
{
13+
path: '/about',
14+
name: 'about',
15+
},
16+
]
17+
18+
const router = createRouter({
19+
history: createWebHashHistory(),
20+
routes
21+
})
22+
23+
export default router

0 commit comments

Comments
 (0)