mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-27 01:25:52 -05:00
Use local storage to remember the panel state
This is mirroring from scratchr2
This commit is contained in:
parent
d243b5dad7
commit
0f823531b6
1 changed files with 11 additions and 0 deletions
|
@ -32,6 +32,8 @@ const frameless = require('../../lib/frameless');
|
||||||
const GUI = require('scratch-gui');
|
const GUI = require('scratch-gui');
|
||||||
const IntlGUI = injectIntl(GUI.default);
|
const IntlGUI = injectIntl(GUI.default);
|
||||||
|
|
||||||
|
const localStorageAvailable = 'localStorage' in window && window.localStorage !== null;
|
||||||
|
|
||||||
class Preview extends React.Component {
|
class Preview extends React.Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
@ -80,9 +82,12 @@ class Preview extends React.Component {
|
||||||
const singleCommentId = window.location.hash.indexOf(commentHashPrefix) !== -1 &&
|
const singleCommentId = window.location.hash.indexOf(commentHashPrefix) !== -1 &&
|
||||||
parseInt(window.location.hash.replace(commentHashPrefix, ''), 10);
|
parseInt(window.location.hash.replace(commentHashPrefix, ''), 10);
|
||||||
|
|
||||||
|
const adminPanelOpen = localStorageAvailable && localStorage.getItem('adminPanelToggled_projects') === 'open';
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
addToStudioOpen: false,
|
addToStudioOpen: false,
|
||||||
adminModalOpen: false,
|
adminModalOpen: false,
|
||||||
|
adminPanelOpen: adminPanelOpen || false,
|
||||||
extensions: [],
|
extensions: [],
|
||||||
favoriteCount: 0,
|
favoriteCount: 0,
|
||||||
justShared: false,
|
justShared: false,
|
||||||
|
@ -267,9 +272,15 @@ class Preview extends React.Component {
|
||||||
}
|
}
|
||||||
handleCloseAdminPanel () {
|
handleCloseAdminPanel () {
|
||||||
this.setState({adminPanelOpen: false});
|
this.setState({adminPanelOpen: false});
|
||||||
|
if (localStorageAvailable) {
|
||||||
|
localStorage.setItem('adminPanelToggled_projects', 'closed');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
handleOpenAdminPanel () {
|
handleOpenAdminPanel () {
|
||||||
this.setState({adminPanelOpen: true});
|
this.setState({adminPanelOpen: true});
|
||||||
|
if (localStorageAvailable) {
|
||||||
|
localStorage.setItem('adminPanelToggled_projects', 'open');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
handleMessage (messageEvent) {
|
handleMessage (messageEvent) {
|
||||||
if (messageEvent.data === 'showDialog') {
|
if (messageEvent.data === 'showDialog') {
|
||||||
|
|
Loading…
Reference in a new issue