@instructure/canvas-rce
Version:
A component wrapping Canvas's usage of Tinymce
50 lines (49 loc) • 1.54 kB
JavaScript
/*
* Copyright (C) 2022 - present Instructure, Inc.
*
* This file is part of Canvas.
*
* Canvas is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, version 3 of the License.
*
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
export const STORAGE_KEY = 'NEE_should_reopen_advanced';
function wrapInErrorHandling(func) {
try {
return {
state: 'success',
returnValue: func()
};
} catch (exception) {
// eslint-disable-next-line no-console
console.warn('Store interaction failed: ', exception);
return {
state: 'failure'
};
}
}
export const isSet = () => {
const result = wrapInErrorHandling(() => {
const value = window.sessionStorage.getItem(STORAGE_KEY) || 'null';
return !!JSON.parse(value);
});
return result.state === 'success' ? result.returnValue : false;
};
export const set = () => {
wrapInErrorHandling(() => {
window.sessionStorage.setItem(STORAGE_KEY, 'true');
});
};
export const remove = () => {
wrapInErrorHandling(() => {
window.sessionStorage.removeItem(STORAGE_KEY);
});
};