Skip to content

Commit 55f0136

Browse files
committed
refactor
1 parent 034538c commit 55f0136

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

src/pages/Content/helpers/SidebarHelper.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import $ from 'jquery';
22
import React from 'react';
33
import ReactDOM from 'react-dom';
44
import Frame from '../modules/frame/frame';
5-
import { SIDEBAR_CONTAINER_ID } from '../../../shared/constants';
5+
import {
6+
SIDEBAR_CONTAINER_ID,
7+
APP_NAME_SHORT,
8+
} from '../../../shared/constants';
69

710
document.body.style.transition = 'margin .25s cubic-bezier(0, 0, 0.3, 1)';
811

@@ -17,8 +20,10 @@ const setSidebarWidth = (width) => {
1720
sidebarWidth = width;
1821
};
1922

20-
chrome.storage.sync.get(['vt-sidebar-width'], (result) => {
21-
let widthObj = result['vt-sidebar-width'];
23+
const SIDEBAR_WIDTH_KEY = `${APP_NAME_SHORT}-sidebar-width`;
24+
25+
chrome.storage.sync.get([SIDEBAR_WIDTH_KEY], (result) => {
26+
let widthObj = result[SIDEBAR_WIDTH_KEY];
2227
if (widthObj !== undefined) {
2328
sidebarWidth = JSON.parse(widthObj).width;
2429
}

src/pages/Content/modules/frame/frame.jsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import { node, object, string, number, func } from 'prop-types';
55

66
import { Resizable } from 're-resizable';
77

8-
import { SIDEBAR_CONTAINER_ID } from '../../../../shared/constants';
8+
import {
9+
SIDEBAR_CONTAINER_ID,
10+
APP_NAME_SHORT,
11+
} from '../../../../shared/constants';
912

1013
const iframeClass = css`
1114
border: none;
@@ -70,6 +73,8 @@ const containerLeftMinimizedClass = css`
7073
const FRAME_TOGGLE_FUNCTION = 'chromeIframeSidebarToggle';
7174
const FRAME_FIX_SHRINK_BODY_FUNCTION = 'chromeIframeFixShrinkBody';
7275

76+
const SIDEBAR_WIDTH_KEY = `${APP_NAME_SHORT}-sidebar-width`;
77+
7378
export class Frame extends Component {
7479
state = {
7580
isVisible: false,
@@ -125,22 +130,22 @@ export class Frame extends Component {
125130
}, delay);
126131

127132
try {
128-
chrome.storage.sync.get(['vt-sidebar-width'], (result) => {
129-
let widthObj = result['vt-sidebar-width'];
133+
chrome.storage.sync.get([SIDEBAR_WIDTH_KEY], (result) => {
134+
let widthObj = result[SIDEBAR_WIDTH_KEY];
130135
if (widthObj !== undefined) {
131136
let width = JSON.parse(widthObj).width;
132137
if (width) {
133138
this.setState({ width });
134139
}
135140
}
136141
});
137-
// let widthObj = localStorage.getItem('vt-sidebar-width');
142+
// let widthObj = localStorage.getItem(SIDEBAR_WIDTH_KEY);
138143
// if (widthObj !== undefined) {
139144
// this.setState({ width: JSON.parse(widthObj).width });
140145
// }
141146
} catch (e) {
142-
chrome.storage.sync.remove(['vt-sidebar-width']);
143-
// localStorage.removeItem('vt-sidebar-width');
147+
chrome.storage.sync.remove([SIDEBAR_WIDTH_KEY]);
148+
// localStorage.removeItem(SIDEBAR_WIDTH_KEY);
144149
}
145150

146151
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
@@ -301,10 +306,10 @@ export class Frame extends Component {
301306
this.props.shrinkBody(true);
302307

303308
chrome.storage.sync.set({
304-
'vt-sidebar-width': JSON.stringify({ width: width }),
309+
[SIDEBAR_WIDTH_KEY]: JSON.stringify({ width: width }),
305310
});
306311
// localStorage.setItem(
307-
// 'vt-sidebar-width',
312+
// [SIDEBAR_WIDTH_KEY],
308313
// JSON.stringify({ width: width })
309314
// );
310315

@@ -344,7 +349,7 @@ export class Frame extends Component {
344349
}}
345350
>
346351
<iframe
347-
title={'vt-sidebar-iframe'}
352+
title={`${APP_NAME_SHORT}-sidebar-iframe`}
348353
className={cx({
349354
[iframeClass]: true,
350355
})}

src/shared/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export const APP_NAME_SHORT = 'vt';
22
export const APP_NAME_FULL = 'Vertical Tabs';
3-
export const SIDEBAR_CONTAINER_ID = 'vt-sidebar-container';
3+
export const SIDEBAR_CONTAINER_ID = `${APP_NAME_SHORT}-sidebar-container`;

0 commit comments

Comments
 (0)