11<script setup>
22import { ref , onMounted } from ' vue'
3+ import { useRoute , useRouter } from ' vue-router'
34import initSqlJs from ' sql.js' ;
45import FileUploaderView from ' ./components/FileUploaderView.vue'
56import CoinListView from " @/components/CoinListView.vue" ;
67import AboutView from " @/components/AboutView.vue" ;
78
89const selectedFile = ref (null )
910const coinsList = ref ([])
11+ let isOpened = false ;
1012
1113const db = ref (null );
1214const status = ref (' ' );
1315
1416let SQL = null ;
1517
16- const currentComponent = ref (' OpenFile' );
1718const drawer = ref (false )
1819
20+ const router = useRouter ()
21+ const route = useRoute ()
22+
1923onMounted (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 >
0 commit comments