|
|
|
@ -1,4 +1,4 @@ |
|
|
|
|
import React, { useEffect, useState } from 'react'; |
|
|
|
|
import React, { useEffect, useState, ReactFragment } from 'react'; |
|
|
|
|
import { WindowState, newWindowReducer, WindowType } from '../Windows'; |
|
|
|
|
import { Box, Typography, Chip, IconButton, useTheme, Button } from '@material-ui/core'; |
|
|
|
|
import LoyaltyIcon from '@material-ui/icons/Loyalty'; |
|
|
|
@ -12,6 +12,7 @@ import { v4 as genUuid } from 'uuid'; |
|
|
|
|
import { MainWindowStateActions } from '../../MainWindow'; |
|
|
|
|
import LocalOfferIcon from '@material-ui/icons/LocalOffer'; |
|
|
|
|
import { songGetters } from '../../../lib/songGetters'; |
|
|
|
|
import Alert from '@material-ui/lab/Alert'; |
|
|
|
|
var _ = require('lodash'); |
|
|
|
|
|
|
|
|
|
export interface ManageTagsWindowState extends WindowState { |
|
|
|
@ -20,12 +21,14 @@ export interface ManageTagsWindowState extends WindowState { |
|
|
|
|
// to the database.
|
|
|
|
|
fetchedTags: Record<string, any> | null, |
|
|
|
|
pendingChanges: TagChange[], |
|
|
|
|
alert: ReactFragment | null, // For notifications such as errors
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export enum ManageTagsWindowActions { |
|
|
|
|
SetFetchedTags = "SetFetchedTags", |
|
|
|
|
SetPendingChanges = "SetPendingChanges", |
|
|
|
|
Reset = "Reset", |
|
|
|
|
SetAlert = "SetAlert", |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function ManageTagsWindowReducer(state: ManageTagsWindowState, action: any) { |
|
|
|
@ -45,6 +48,12 @@ export function ManageTagsWindowReducer(state: ManageTagsWindowState, action: an |
|
|
|
|
...state, |
|
|
|
|
pendingChanges: [], |
|
|
|
|
fetchedTags: null, |
|
|
|
|
alert: null, |
|
|
|
|
} |
|
|
|
|
case ManageTagsWindowActions.SetAlert: |
|
|
|
|
return { |
|
|
|
|
...state, |
|
|
|
|
alert: action.value, |
|
|
|
|
} |
|
|
|
|
default: |
|
|
|
|
throw new Error("Unimplemented ManageTagsWindow state update.") |
|
|
|
@ -194,6 +203,10 @@ export function SingleTag(props: { |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}) |
|
|
|
|
props.dispatch({ |
|
|
|
|
type: ManageTagsWindowActions.SetAlert, |
|
|
|
|
value: null, |
|
|
|
|
}) |
|
|
|
|
}} |
|
|
|
|
onDelete={() => { |
|
|
|
|
props.dispatch({ |
|
|
|
@ -206,6 +219,10 @@ export function SingleTag(props: { |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}) |
|
|
|
|
props.dispatch({ |
|
|
|
|
type: ManageTagsWindowActions.SetAlert, |
|
|
|
|
value: null, |
|
|
|
|
}) |
|
|
|
|
}} |
|
|
|
|
onMove={(to: string | null) => { |
|
|
|
|
props.dispatch({ |
|
|
|
@ -219,6 +236,10 @@ export function SingleTag(props: { |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}) |
|
|
|
|
props.dispatch({ |
|
|
|
|
type: ManageTagsWindowActions.SetAlert, |
|
|
|
|
value: null, |
|
|
|
|
}) |
|
|
|
|
}} |
|
|
|
|
onMergeInto={(into: string) => { |
|
|
|
|
props.dispatch({ |
|
|
|
@ -232,6 +253,10 @@ export function SingleTag(props: { |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}) |
|
|
|
|
props.dispatch({ |
|
|
|
|
type: ManageTagsWindowActions.SetAlert, |
|
|
|
|
value: null, |
|
|
|
|
}) |
|
|
|
|
}} |
|
|
|
|
tag={tag} |
|
|
|
|
changedTags={props.changedTags} |
|
|
|
@ -382,21 +407,36 @@ export default function ManageTagsWindow(props: { |
|
|
|
|
> |
|
|
|
|
<ControlTagChanges |
|
|
|
|
changes={props.state.pendingChanges} |
|
|
|
|
onDiscard={() => props.dispatch({ |
|
|
|
|
onDiscard={() => { |
|
|
|
|
props.dispatch({ |
|
|
|
|
type: ManageTagsWindowActions.SetPendingChanges, |
|
|
|
|
value: [], |
|
|
|
|
})} |
|
|
|
|
}) |
|
|
|
|
props.dispatch({ |
|
|
|
|
type: ManageTagsWindowActions.SetAlert, |
|
|
|
|
value: null, |
|
|
|
|
}) |
|
|
|
|
}} |
|
|
|
|
onSave={() => { |
|
|
|
|
submitTagChanges(props.state.pendingChanges).then(() => { |
|
|
|
|
console.log("reset!") |
|
|
|
|
props.dispatch({ |
|
|
|
|
type: ManageTagsWindowActions.Reset |
|
|
|
|
}); |
|
|
|
|
}).catch((e: Error) => { |
|
|
|
|
props.dispatch({ |
|
|
|
|
type: ManageTagsWindowActions.SetAlert, |
|
|
|
|
value: <Alert severity="error">Failed to save changes: {e.message}</Alert>, |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}} |
|
|
|
|
getTagDetails={(id: string) => tagsWithChanges[id]} |
|
|
|
|
/> |
|
|
|
|
</Box>} |
|
|
|
|
{props.state.alert && <Box |
|
|
|
|
m={1} |
|
|
|
|
mt={4} |
|
|
|
|
width="80%" |
|
|
|
|
>{props.state.alert}</Box>} |
|
|
|
|
<Box |
|
|
|
|
m={1} |
|
|
|
|
mt={4} |
|
|
|
|