1
- import { UploadReport } from "@/types/uploads/UploadReport" ;
2
- import { useLocalStorage } from "@vueuse/core" ;
3
- import { defineStore } from "pinia" ;
4
- import { computed , onMounted } from "vue" ;
5
- import { useRoute } from "vue-router" ;
1
+ import { UploadReport } from "@/types/uploads/UploadReport" ;
2
+ import { useLocalStorage } from "@vueuse/core" ;
3
+ import { defineStore } from "pinia" ;
4
+ import { computed , onMounted } from "vue" ;
5
+ import { useRoute } from "vue-router" ;
6
6
import slugify from "slugify" ;
7
- import axios , { AxiosError } from "axios" ;
7
+ import axios , { AxiosError } from "axios" ;
8
8
9
9
export const useReportsStore = defineStore ( "reports" , ( ) => {
10
10
// List of uploaded reports in localstorage.
@@ -41,17 +41,17 @@ export const useReportsStore = defineStore("reports", () => {
41
41
}
42
42
43
43
// Get a report in the list by reportId.
44
- function getReportById ( reportId : string | undefined ) {
44
+ function getReportById ( reportId : string ) {
45
45
return reports . value . find ( ( r ) => r . reportId === reportId ) ;
46
46
}
47
47
48
48
// Get a report in the list by referenceId.
49
- function getReportByReferenceId ( referenceId : string | undefined ) {
49
+ function getReportByReferenceId ( referenceId : string ) {
50
50
return reports . value . find ( ( r ) => r . referenceId === referenceId ) ;
51
51
}
52
52
53
53
// Get the route for a given report id.
54
- function getReportRouteById ( reportId : string | undefined ) {
54
+ function getReportRouteById ( reportId : string ) {
55
55
const report = getReportById ( reportId ) ;
56
56
57
57
// If no report is found, return the home page.
@@ -64,28 +64,28 @@ export const useReportsStore = defineStore("reports", () => {
64
64
return {
65
65
name : "Overview" ,
66
66
params : {
67
- referenceId : report ? .referenceId ,
67
+ referenceId : report . referenceId ,
68
68
} ,
69
69
} ;
70
70
}
71
71
72
72
// Get the share route for a given report id.
73
- function getReportShareRouteById ( reportId : string | undefined ) {
73
+ function getReportShareRouteById ( reportId : string ) {
74
74
return {
75
75
name : "Share" ,
76
76
params : {
77
- reportId : reportId ?? "" ,
77
+ reportId : reportId ,
78
78
} ,
79
79
} ;
80
80
}
81
81
82
82
// Delete a report by reportId.
83
- function deleteReportById ( reportId : string | undefined ) {
83
+ function deleteReportById ( reportId : string ) {
84
84
reports . value = reports . value . filter ( ( r ) => r . reportId !== reportId ) ;
85
85
}
86
86
87
87
// Get the URL for a given report id.
88
- const getReportUrlById = ( reportId : string | undefined ) => {
88
+ const getReportUrlById = ( reportId : string ) => {
89
89
return `${ import . meta. env . VITE_API_URL } /reports/${ reportId } ` ;
90
90
} ;
91
91
@@ -117,8 +117,14 @@ export const useReportsStore = defineStore("reports", () => {
117
117
const route = useRoute ( ) ;
118
118
const currentReport = computed ( ( ) => {
119
119
const reportId = route . params . reportId as string | undefined ;
120
+ if ( reportId ) {
121
+ return getReportById ( reportId ) ;
122
+ }
120
123
const referenceId = route . params . referenceId as string | undefined ;
121
- return getReportById ( reportId ) ?? getReportByReferenceId ( referenceId ) ;
124
+ if ( referenceId ) {
125
+ return getReportByReferenceId ( referenceId ) ;
126
+ }
127
+ return undefined ;
122
128
} ) ;
123
129
124
130
return {
0 commit comments