Add rename disc feature (in top right menu)
This commit is contained in:
parent
b7c45ed34e
commit
b634772f2d
|
@ -2,7 +2,7 @@ import React from 'react';
|
||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch } from 'react-redux';
|
||||||
import { useShallowEqualSelector } from '../utils';
|
import { useShallowEqualSelector } from '../utils';
|
||||||
import { actions as renameDialogActions } from '../redux/rename-dialog-feature';
|
import { actions as renameDialogActions } from '../redux/rename-dialog-feature';
|
||||||
import { renameTrack } from '../redux/actions';
|
import { renameTrack, renameDisc } from '../redux/actions';
|
||||||
|
|
||||||
import Dialog from '@material-ui/core/Dialog';
|
import Dialog from '@material-ui/core/Dialog';
|
||||||
import DialogActions from '@material-ui/core/DialogActions';
|
import DialogActions from '@material-ui/core/DialogActions';
|
||||||
|
@ -23,12 +23,18 @@ export const RenameDialog = (props: {}) => {
|
||||||
let renameDialogTitle = useShallowEqualSelector(state => state.renameDialog.title);
|
let renameDialogTitle = useShallowEqualSelector(state => state.renameDialog.title);
|
||||||
let renameDialogIndex = useShallowEqualSelector(state => state.renameDialog.index);
|
let renameDialogIndex = useShallowEqualSelector(state => state.renameDialog.index);
|
||||||
|
|
||||||
|
const what = renameDialogIndex < 0 ? `Disc` : `Track`;
|
||||||
|
|
||||||
const handleCancelRename = () => {
|
const handleCancelRename = () => {
|
||||||
dispatch(renameDialogActions.setVisible(false));
|
dispatch(renameDialogActions.setVisible(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDoRename = () => {
|
const handleDoRename = () => {
|
||||||
|
if (renameDialogIndex < 0) {
|
||||||
|
dispatch(renameDisc({ newName: renameDialogTitle }));
|
||||||
|
} else {
|
||||||
dispatch(renameTrack({ index: renameDialogIndex, newName: renameDialogTitle }));
|
dispatch(renameTrack({ index: renameDialogIndex, newName: renameDialogTitle }));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -40,12 +46,12 @@ export const RenameDialog = (props: {}) => {
|
||||||
TransitionComponent={Transition as any}
|
TransitionComponent={Transition as any}
|
||||||
aria-labelledby="rename-dialog-title"
|
aria-labelledby="rename-dialog-title"
|
||||||
>
|
>
|
||||||
<DialogTitle id="rename-dialog-title">Rename Track</DialogTitle>
|
<DialogTitle id="rename-dialog-title">Rename {what}</DialogTitle>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<TextField
|
<TextField
|
||||||
autoFocus
|
autoFocus
|
||||||
id="name"
|
id="name"
|
||||||
label="Track Name"
|
label={`${what} Name`}
|
||||||
type="text"
|
type="text"
|
||||||
fullWidth
|
fullWidth
|
||||||
value={renameDialogTitle}
|
value={renameDialogTitle}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch } from 'react-redux';
|
||||||
|
import { batchActions } from 'redux-batched-actions';
|
||||||
|
|
||||||
import IconButton from '@material-ui/core/IconButton';
|
import IconButton from '@material-ui/core/IconButton';
|
||||||
import Menu from '@material-ui/core/Menu';
|
import Menu from '@material-ui/core/Menu';
|
||||||
|
@ -8,6 +9,7 @@ import MoreVertIcon from '@material-ui/icons/MoreVert';
|
||||||
|
|
||||||
import { wipeDisc, listContent } from '../redux/actions';
|
import { wipeDisc, listContent } from '../redux/actions';
|
||||||
import { actions as appActions } from '../redux/app-feature';
|
import { actions as appActions } from '../redux/app-feature';
|
||||||
|
import { actions as renameDialogActions } from '../redux/rename-dialog-feature';
|
||||||
import { useShallowEqualSelector } from '../utils';
|
import { useShallowEqualSelector } from '../utils';
|
||||||
import Link from '@material-ui/core/Link';
|
import Link from '@material-ui/core/Link';
|
||||||
|
|
||||||
|
@ -15,6 +17,7 @@ export const TopMenu = function() {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
let { mainView } = useShallowEqualSelector(state => state.appState);
|
let { mainView } = useShallowEqualSelector(state => state.appState);
|
||||||
|
let disc = useShallowEqualSelector(state => state.main.disc);
|
||||||
|
|
||||||
const [menuAnchorEl, setMenuAnchorEl] = React.useState<null | HTMLElement>(null);
|
const [menuAnchorEl, setMenuAnchorEl] = React.useState<null | HTMLElement>(null);
|
||||||
const menuOpen = Boolean(menuAnchorEl);
|
const menuOpen = Boolean(menuAnchorEl);
|
||||||
|
@ -36,6 +39,17 @@ export const TopMenu = function() {
|
||||||
handleMenuClose();
|
handleMenuClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleRenameDisc = () => {
|
||||||
|
dispatch(
|
||||||
|
batchActions([
|
||||||
|
renameDialogActions.setVisible(true),
|
||||||
|
renameDialogActions.setCurrentName(disc?.title ?? ``),
|
||||||
|
renameDialogActions.setIndex(-1),
|
||||||
|
])
|
||||||
|
);
|
||||||
|
handleMenuClose();
|
||||||
|
};
|
||||||
|
|
||||||
const handleExit = () => {
|
const handleExit = () => {
|
||||||
dispatch(appActions.setState('WELCOME'));
|
dispatch(appActions.setState('WELCOME'));
|
||||||
handleMenuClose();
|
handleMenuClose();
|
||||||
|
@ -52,6 +66,11 @@ export const TopMenu = function() {
|
||||||
Refresh
|
Refresh
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
);
|
);
|
||||||
|
menuItems.push(
|
||||||
|
<MenuItem key="title" onClick={handleRenameDisc}>
|
||||||
|
Rename Disc
|
||||||
|
</MenuItem>
|
||||||
|
);
|
||||||
menuItems.push(
|
menuItems.push(
|
||||||
<MenuItem key="wipe" onClick={handleWipeDisc}>
|
<MenuItem key="wipe" onClick={handleWipeDisc}>
|
||||||
Wipe Disc
|
Wipe Disc
|
||||||
|
|
|
@ -60,6 +60,15 @@ export function renameTrack({ index, newName }: { index: number; newName: string
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function renameDisc({ newName }: { newName: string }) {
|
||||||
|
return async function(dispatch: AppDispatch) {
|
||||||
|
const { netmdService } = serviceRegistry;
|
||||||
|
await netmdService!.renameDisc(newName);
|
||||||
|
dispatch(renameDialogActions.setVisible(false));
|
||||||
|
listContent()(dispatch);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function deleteTracks(indexes: number[]) {
|
export function deleteTracks(indexes: number[]) {
|
||||||
return async function(dispatch: AppDispatch) {
|
return async function(dispatch: AppDispatch) {
|
||||||
const { netmdService } = serviceRegistry;
|
const { netmdService } = serviceRegistry;
|
||||||
|
|
|
@ -10,6 +10,7 @@ export interface NetMDService {
|
||||||
getDeviceName(): Promise<string>;
|
getDeviceName(): Promise<string>;
|
||||||
finalize(): Promise<void>;
|
finalize(): Promise<void>;
|
||||||
renameTrack(index: number, newTitle: string): Promise<void>;
|
renameTrack(index: number, newTitle: string): Promise<void>;
|
||||||
|
renameDisc(newName: string): Promise<void>;
|
||||||
deleteTrack(index: number): Promise<void>;
|
deleteTrack(index: number): Promise<void>;
|
||||||
wipeDisc(): Promise<void>;
|
wipeDisc(): Promise<void>;
|
||||||
upload(
|
upload(
|
||||||
|
@ -57,6 +58,15 @@ export class NetMDUSBService implements NetMDService {
|
||||||
await this.netmdInterface!.setTrackTitle(index, newTitle);
|
await this.netmdInterface!.setTrackTitle(index, newTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async renameDisc(newName: string) {
|
||||||
|
const oldName = await this.netmdInterface!.getDiscTitle();
|
||||||
|
let newNameWithGroups = await this.netmdInterface!._getDiscTitle();
|
||||||
|
newNameWithGroups = newNameWithGroups.replace(oldName, newName);
|
||||||
|
await this.netmdInterface!.cacheTOC();
|
||||||
|
await this.netmdInterface!.setDiscTitle(newNameWithGroups);
|
||||||
|
await this.netmdInterface!.syncTOC();
|
||||||
|
}
|
||||||
|
|
||||||
async deleteTrack(index: number) {
|
async deleteTrack(index: number) {
|
||||||
await this.netmdInterface!.eraseTrack(index);
|
await this.netmdInterface!.eraseTrack(index);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue