Add local dir

This commit is contained in:
Jordan Eldredge 2019-02-06 17:40:10 -05:00
parent c8570973b2
commit 98ca95749c
3 changed files with 32 additions and 0 deletions

View file

@ -2,12 +2,27 @@ type Teardown = (() => void) | { dispose: () => void };
export default class Disposable {
_teardowns: Teardown[] = [];
disposed: boolean;
constructor() {
this.disposed = false;
}
add(...teardowns: Teardown[]): void {
if (this.disposed) {
throw new Error(
"Attempted to add a new teardown to a disposed disposable."
);
}
this._teardowns.push(...teardowns);
}
dispose() {
if (this.disposed) {
throw new Error(
"Attempted to dispose disposable which is already disposed."
);
}
this._teardowns.forEach(teardown => {
if (typeof teardown === "function") {
teardown();
@ -15,5 +30,6 @@ export default class Disposable {
teardown.dispose();
}
});
this.disposed = true;
}
}

View file

@ -42,6 +42,12 @@ export function initializePresets(presetOptions: any): Dispatchable {
};
}
export function appendPresetFileList(presets: FileList[]): Dispatchable {
return async dispatch => {
dispatch({ type: GOT_BUTTERCHURN_PRESETS, presets });
};
}
export function selectNextPreset(): Dispatchable {
return (dispatch, getState) => {
const state = getState();

View file

@ -161,6 +161,16 @@ class PresetOverlay extends React.Component<Props, State> {
}
};
async loadLocalDir() {
const fileReferences = await promptForFileReferences({ directory: true });
if (this._disposable.disposed) {
return;
}
// TODO: Technically there is a race condition here, since the component
// could get unmounted before the promise resolves.
this.props.loadPresets(fileReferences);
}
render() {
const { height, width } = this.props;
if (this.props.presetKeys == null) {