Implements #31

This commit is contained in:
Stefano Brilli 2021-01-20 14:40:17 +01:00
parent 468e512f94
commit b79b1916d4
3 changed files with 8 additions and 6 deletions

View File

@ -68,7 +68,7 @@ export const ConvertDialog = (props: { files: File[] }) => {
if (newFormat === null) {
return;
}
dispatch(convertDialogActions.setFormat(newFormat as string));
dispatch(convertDialogActions.setFormat(newFormat));
},
[dispatch]
);

View File

@ -11,7 +11,7 @@ import { Wireformat, getTracks } from 'netmd-js';
import { AnyAction } from '@reduxjs/toolkit';
import { getAvailableCharsForTrackTitle, framesToSec, sleepWithProgressCallback, sleep } from '../utils';
import * as mm from 'music-metadata-browser';
import { TitleSourceType, TitleFormatType } from './convert-dialog-feature';
import { TitleSourceType, TitleFormatType, UploadFormat } from './convert-dialog-feature';
export function control(action: 'play' | 'stop' | 'next' | 'prev' | 'goto', params?: unknown) {
return async function(dispatch: AppDispatch, getState: () => RootState) {
@ -264,7 +264,7 @@ async function getTrackNameFromMediaTags(file: File, titleFormat: TitleFormatTyp
}
}
export function convertAndUpload(files: File[], format: string, titleSource: TitleSourceType, titleFormat: TitleFormatType) {
export function convertAndUpload(files: File[], format: UploadFormat, titleSource: TitleSourceType, titleFormat: TitleFormatType) {
return async function(dispatch: AppDispatch, getState: () => RootState) {
const { audioExportService, netmdService } = serviceRegistry;
const wireformat = WireformatDict[format];

View File

@ -4,17 +4,18 @@ import { savePreference, loadPreference } from '../utils';
export type TitleSourceType = 'file' | 'media';
export type TitleFormatType = 'title' | 'album-title' | 'artist-title' | 'artist-album-title';
export type UploadFormat = 'SP' | 'LP2' | 'LP4';
export interface ConvertDialogFeature {
visible: boolean;
format: string;
format: UploadFormat;
titleSource: TitleSourceType;
titleFormat: TitleFormatType;
}
const initialState: ConvertDialogFeature = {
visible: false,
format: `LP2`,
format: loadPreference('uploadFormat', 'LP2') as UploadFormat,
titleSource: loadPreference('trackTitleSource', 'file') as TitleSourceType,
titleFormat: loadPreference('trackTitleFormat', 'title') as TitleFormatType,
};
@ -26,8 +27,9 @@ const slice = createSlice({
setVisible: (state, action: PayloadAction<boolean>) => {
state.visible = action.payload;
},
setFormat: (state, action: PayloadAction<string>) => {
setFormat: (state, action: PayloadAction<UploadFormat>) => {
state.format = action.payload;
savePreference('uploadFormat', state.format);
},
setTitleSource: (state, action: PayloadAction<TitleSourceType>) => {
state.titleSource = action.payload;