From b79b1916d4c959f2e1a0e7554607f0ee5f849114 Mon Sep 17 00:00:00 2001 From: Stefano Brilli Date: Wed, 20 Jan 2021 14:40:17 +0100 Subject: [PATCH] Implements #31 --- src/components/convert-dialog.tsx | 2 +- src/redux/actions.ts | 4 ++-- src/redux/convert-dialog-feature.ts | 8 +++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/components/convert-dialog.tsx b/src/components/convert-dialog.tsx index 9cda4bd..61deab0 100644 --- a/src/components/convert-dialog.tsx +++ b/src/components/convert-dialog.tsx @@ -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] ); diff --git a/src/redux/actions.ts b/src/redux/actions.ts index f7ef851..71922d5 100644 --- a/src/redux/actions.ts +++ b/src/redux/actions.ts @@ -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]; diff --git a/src/redux/convert-dialog-feature.ts b/src/redux/convert-dialog-feature.ts index 96647b2..61e1fa8 100644 --- a/src/redux/convert-dialog-feature.ts +++ b/src/redux/convert-dialog-feature.ts @@ -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) => { state.visible = action.payload; }, - setFormat: (state, action: PayloadAction) => { + setFormat: (state, action: PayloadAction) => { state.format = action.payload; + savePreference('uploadFormat', state.format); }, setTitleSource: (state, action: PayloadAction) => { state.titleSource = action.payload;