@@ -2,10 +2,23 @@ import { computed, reactive, ref, watch } from 'vue';
2
2
import { useSample } from './useSample' ;
3
3
import { useCsvFile } from './useCsvFile' ;
4
4
import { FileCardProps } from '../components/FileCard/FileCard.vue' ;
5
- import { League } from '../types' ;
5
+ import { CsvExt , League , isCsvExt , leagues } from '../types' ;
6
6
import { command } from '../command' ;
7
7
import { csvFile } from '../lib' ;
8
8
9
+ const prefixFilename = ( name : string , league : League ) : CsvExt => {
10
+ const UNDERSCORE_GLUE = '_' ;
11
+ const res : CsvExt = isCsvExt ( name ) ? name : `${ name } .csv` ;
12
+
13
+ for ( const old of leagues ) {
14
+ if ( res . startsWith ( `${ old } ${ UNDERSCORE_GLUE } ` ) ) {
15
+ return res . replace ( old , league ) as CsvExt ;
16
+ }
17
+ }
18
+
19
+ return `${ league } ${ UNDERSCORE_GLUE } ${ res } ` ;
20
+ } ;
21
+
9
22
export const useFileCard = ( file : File , league : League ) : FileCardProps => {
10
23
const { text : csv , name : filename , href } = useCsvFile ( file ) ;
11
24
const { data, error, isError } = useSample ( csv , league ) ;
@@ -18,7 +31,7 @@ export const useFileCard = (file: File, league: League): FileCardProps => {
18
31
valid,
19
32
selected,
20
33
sample : data ,
21
- filename,
34
+ filename : prefixFilename ( filename . value , league ) ,
22
35
href,
23
36
error,
24
37
isError,
@@ -47,6 +60,7 @@ export const useFileCard = (file: File, league: League): FileCardProps => {
47
60
( ) => props . league ,
48
61
async val => {
49
62
props . sample = await command ( 'league' , { league : val , sample : props . sample } ) ;
63
+ props . filename = prefixFilename ( props . filename , val ) ;
50
64
}
51
65
) ;
52
66
0 commit comments