mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-15 02:54:07 +00:00
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:
@@ -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',
|
||||
}));
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user