Skip to content

Commit

Permalink
Fix issue where adding a new song wouldn't warn about unsaved changes…
Browse files Browse the repository at this point in the history
… in current song
  • Loading branch information
chrismaltby committed Sep 12, 2024
1 parent d3b0017 commit 63290c0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- Fix issue where adding a new song wouldn't warn about unsaved changes in current song
- Fix issue where adding a song with an already existing name wouldn't auto select the newly created song

## [4.1.2] - 2024-09-09

### Added
Expand Down
4 changes: 2 additions & 2 deletions src/components/music/NavigatorSongs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import useSplitPane from "ui/hooks/use-split-pane";
import styled from "styled-components";
import { SplitPaneVerticalDivider } from "ui/splitpane/SplitPaneDivider";
import { NoSongsMessage } from "./NoSongsMessage";
import { addNewSongFile } from "store/features/trackerDocument/trackerDocumentState";
import { requestAddNewSongFile } from "store/features/trackerDocument/trackerDocumentState";
import trackerActions from "store/features/tracker/trackerActions";
import API from "renderer/lib/api";
import { useAppDispatch, useAppSelector } from "store/hooks";
Expand Down Expand Up @@ -503,7 +503,7 @@ export const NavigatorSongs = ({
const path = assetPath("music", {
filename: `${stripInvalidPathCharacters(filename)}.uge`,
});
dispatch(addNewSongFile(path));
dispatch(requestAddNewSongFile(path));
}
setAddSongMode(false);
}}
Expand Down
9 changes: 1 addition & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1583,14 +1583,7 @@ ipcMain.handle(
newFilename = filename.replace(/\d+$/, `${number}`);
}
const newPath = `${newFilename}.uge`;
await copy2(oPath, newPath);

const data = await loadMusicData(projectRoot)(newPath);
if (!data) {
console.error(`Unable to load asset ${filename}`);
}

return data;
return await copy2(oPath, newPath);
}
} catch (e) {
console.error(e);
Expand Down
15 changes: 13 additions & 2 deletions src/store/features/trackerDocument/trackerDocumentMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { RootState } from "store/configureStore";
import editorActions from "store/features/editor/editorActions";
import { musicSelectors } from "store/features/entities/entitiesState";
import navigationActions from "store/features/navigation/navigationActions";
import { saveSongFile } from "./trackerDocumentState";
import {
addNewSongFile,
requestAddNewSongFile,
saveSongFile,
} from "./trackerDocumentState";
import trackerDocumentActions from "./trackerDocumentActions";
import electronActions from "store/features/electron/electronActions";
import l10n from "shared/lib/lang/l10n";
Expand All @@ -18,7 +22,8 @@ const trackerMiddleware: ThunkMiddleware<RootState> =
(navigationActions.setSection.match(action) &&
action.payload !== "music") ||
(editorActions.setSelectedSongId.match(action) &&
action.payload !== state.editor.selectedSongId)
action.payload !== state.editor.selectedSongId) ||
requestAddNewSongFile.match(action)
) {
if (state.trackerDocument.present.modified) {
// Display confirmation and stop action if
Expand All @@ -43,6 +48,12 @@ const trackerMiddleware: ThunkMiddleware<RootState> =
}
}

// Delay creation until confirmUnsavedChangesTrackerDialog has
// had a chance to ask about unsaved changes
if (requestAddNewSongFile.match(action)) {
store.dispatch(addNewSongFile(action.payload));
}

if (
projectActions.saveProject.pending.match(action) &&
state.trackerDocument.present.modified
Expand Down
5 changes: 5 additions & 0 deletions src/store/features/trackerDocument/trackerDocumentState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
createAsyncThunk,
createSlice,
PayloadAction,
createAction,
} from "@reduxjs/toolkit";
import cloneDeep from "lodash/cloneDeep";
import { PatternCell } from "shared/lib/uge/song/PatternCell";
Expand Down Expand Up @@ -32,6 +33,10 @@ export const initialState: TrackerDocumentState = {
modified: false,
};

export const requestAddNewSongFile = createAction<string>(
"tracker/requestAddNewSong"
);

export const addNewSongFile = createAsyncThunk<
{ data: MusicAssetData },
string
Expand Down

0 comments on commit 63290c0

Please sign in to comment.