drop settingsToggleShowDocs

We can change the event handler in App.tsx do we no longer need the
settingsToggleShowDocs action or related sagas.
This commit is contained in:
David Lechner
2022-03-25 18:05:03 -05:00
parent 3c48d115d7
commit 0715ce3de1
5 changed files with 4 additions and 72 deletions
-9
View File
@@ -1,9 +0,0 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors
import { createAction } from '../actions';
/** Requests to toggle the showDocs setting. */
export const settingsToggleShowDocs = createAction(() => ({
type: 'editor.action.toggleShowDocs',
}));
-23
View File
@@ -1,23 +0,0 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors
//
// Tests for settings sagas.
import { AsyncSaga } from '../../test';
import { settingsToggleShowDocs } from './actions';
import settings from './sagas';
describe('handleToggleShowDocs', () => {
it('should toggle the showDocs setting', async () => {
const key = 'setting.showDocs';
const saga = new AsyncSaga(settings);
saga.put(settingsToggleShowDocs());
expect(localStorage.getItem(key)).toBe('true');
saga.put(settingsToggleShowDocs());
expect(localStorage.getItem(key)).toBe('false');
await saga.end();
});
});
-32
View File
@@ -1,32 +0,0 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors
// This manages settings by storing them in local storage whenever the app
// request to set a setting. When local storage changes, it triggers a did
// change action that can be used by reducers to compute the new state.
import { call, takeEvery } from 'typed-redux-saga/macro';
import { settingsToggleShowDocs } from './actions';
/**
* Hack to wire editor action to settings hook.
*
* There are a few places where using toggleIsSettingShowDocsEnabled() doesn't
* work because it needs to be called from outside of a React component that
* doesn't get updated when state changes.
*/
function* handleToggleShowDocs(): Generator {
// HACK: This depends on the implementation detail that
// useSettingIsShowDocsEnabled() uses useLocalStorage() internally.
yield* call(() => {
const key = 'setting.showDocs';
const oldValue = localStorage.getItem(key);
const newValue = JSON.stringify(!(oldValue && JSON.parse(oldValue)));
localStorage.setItem(key, newValue);
window.dispatchEvent(new Event('local-storage'));
});
}
export default function* (): Generator {
yield* takeEvery(settingsToggleShowDocs, handleToggleShowDocs);
}