@@ -14,6 +14,17 @@ export interface FabOption {
1414 getTextToCopy ?: ( ) => Promise < string > ;
1515}
1616
17+ type NavigationItem =
18+ | { type : 'all' ; value : 'all' }
19+ | { type : 'countrycode' | 'publicationcode' ; value : string }
20+ | { type : 'issuecodes' ; value : string [ ] } ;
21+
22+ const navigationItemsEqual = ( a : NavigationItem , b : NavigationItem ) =>
23+ a . type === b . type &&
24+ ( Array . isArray ( a . value ) && Array . isArray ( b . value )
25+ ? a . value . every ( ( value , index ) => value === b . value [ index ] )
26+ : a . value === b . value ) ;
27+
1728export const app = defineStore ( 'app' , ( ) => {
1829 const offlineBannerHeight = ref ( 0 ) ;
1930 const socket = ref < ReturnType < typeof useDmSocket > > ( ) ;
@@ -36,11 +47,7 @@ export const app = defineStore('app', () => {
3647
3748 const isCoaView = ref ( route . hash . startsWith ( '#coa-' ) ) ;
3849
39- const currentNavigationItem = ref <
40- | { type : 'all' ; value : 'all' }
41- | { type : 'countrycode' | 'publicationcode' ; value : string }
42- | { type : 'issuecodes' ; value : string [ ] }
43- > ( { type : 'all' , value : 'all' } ) ;
50+ const currentNavigationItem = ref < NavigationItem > ( { type : 'all' , value : 'all' } ) ;
4451
4552 watch (
4653 ( ) => route . hash ,
@@ -52,22 +59,20 @@ export const app = defineStore('app', () => {
5259 . replace ( / ^ # ( c o a - ) ? / , '' )
5360 . replaceAll ( '_' , ' ' )
5461 . split ( '=' ) ;
55- if ( parts . length === 1 ) {
56- currentNavigationItem . value = { type : 'all' , value : 'all' } ;
57- } else {
58- const [ type , value ] = parts as [ 'countrycode' | 'publicationcode' | 'issuecodes' , string ] ;
59- if ( type === 'issuecodes' ) {
60- currentNavigationItem . value = {
61- type,
62- value : value . split ( ',' ) ,
63- } ;
64- } else {
65- currentNavigationItem . value = {
66- type,
67- value,
68- } ;
69- }
62+ const nextItem =
63+ parts . length === 1
64+ ? ( { type : 'all' , value : 'all' } as const )
65+ : ( ( ) => {
66+ const [ type , value ] = parts as [ 'countrycode' | 'publicationcode' | 'issuecodes' , string ] ;
67+ if ( type === 'issuecodes' ) {
68+ return { type, value : value . split ( ',' ) } as const ;
69+ }
70+ return { type, value } as const ;
71+ } ) ( ) ;
72+ if ( navigationItemsEqual ( currentNavigationItem . value , nextItem ) ) {
73+ return ;
7074 }
75+ currentNavigationItem . value = nextItem ;
7176 } ,
7277 { immediate : true } ,
7378 ) ;
@@ -188,6 +193,9 @@ export const app = defineStore('app', () => {
188193 ) ?. replace ( / / g, '_' ) ;
189194 const hash = ( isCoaView . value ? '#coa-' : '#' ) + ( navigationItem ?. type ? `${ navigationItem ?. type } =${ value } ` : '' ) ;
190195 if ( route . name === 'Collection' ) {
196+ if ( route . hash === hash ) {
197+ return ;
198+ }
191199 window . location . hash = hash ;
192200 } else {
193201 await router . push ( {
0 commit comments