Skip to content

Commit

Permalink
refactor: remove unused main variable
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1p committed Jan 4, 2021
1 parent 3bd38fd commit bc31cc0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
3 changes: 0 additions & 3 deletions src/Ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import UserListView from './views/UserList';
import theme from './shared/theme';
import { useStore, StoreProvider } from './store';
import Header from './components/Header';
import { DEFAULT_SERVER_URL } from './shared/constants';

onmessage = (message) => {
if (message.data.pluginMessage) {
Expand Down Expand Up @@ -197,8 +196,6 @@ const init = () => {
useEffect(() => {
if (store.settings.url) {
initSocketConnection(store.settings.url);
} else {
sendMainMessage('set-server-url', DEFAULT_SERVER_URL);
}
// check focus
window.addEventListener('focus', onFocus);
Expand Down
18 changes: 12 additions & 6 deletions src/code.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DEFAULT_SERVER_URL } from './shared/constants';
import { generateString } from './shared/utils';

let isMinimized = false;
Expand All @@ -19,6 +20,7 @@ figma.root.setRelaunchData({

async function main() {
const timestamp = +new Date();

// random user id for current user
let instanceId = await figma.clientStorage.getAsync('id');
// figma.root.setPluginData('history', '');
Expand All @@ -27,6 +29,15 @@ async function main() {
let secret = figma.root.getPluginData('secret');
// const ownerId = figma.root.getPluginData('ownerId');

const settings = await figma.clientStorage.getAsync('user-settings');

if (!settings.url) {
await figma.clientStorage.setAsync('user-settings', {
...settings,
url: DEFAULT_SERVER_URL
});
}

try {
JSON.parse(history);
} catch {
Expand Down Expand Up @@ -186,13 +197,8 @@ main().then(({ roomName, secret, history, instanceId }) => {
figma.notify(message.payload);
}
break;
case 'set-server-url':
await figma.clientStorage.setAsync('server-url', message.payload);
break;
case 'initialize':
const url = await figma.clientStorage.getAsync('server-url');

postMessage('initialize', url || '');
postMessage('initialize');

sendRootData({ roomName, secret, history, instanceId });
break;
Expand Down
3 changes: 1 addition & 2 deletions src/store/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class RootStore {
}
}

persistSettings(settings, socket, isInit = false) {
persistSettings(settings, socket?, isInit = false) {
const oldUrl = this.settings.url;

this.settings = {
Expand All @@ -137,7 +137,6 @@ class RootStore {

// set server URL
if (!isInit && settings.url && settings.url !== oldUrl) {
sendMainMessage('set-server-url', settings.url);
this.addNotification('Updated server-URL');
}

Expand Down

0 comments on commit bc31cc0

Please sign in to comment.