Skip to content

Commit

Permalink
feat(reset): add menu to reset chat data, if the plugin does not start
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1p committed Nov 6, 2021
1 parent 6f6c090 commit e0027a2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/plugin/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ const currentUser = {
delete currentUser.sessionId;

if (isReset) {
figma.root.setPluginData('history', '[]');
figma.clientStorage.setAsync('figma-chat', '{}');
figma.root.setPluginData('roomName', generateString(20));
figma.root.setPluginData('secret', generateString(20));

figma.notify('Figma Chat successfully reset!');
figma.closePlugin();
} else {
figma.showUI(__html__, {
width: 333,
Expand All @@ -30,13 +37,10 @@ if (isReset) {
});

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

// random user id for current user
let history = figma.root.getPluginData('history');
let roomName = figma.root.getPluginData('roomName');
let secret = figma.root.getPluginData('secret');
// const ownerId = figma.root.getPluginData('ownerId');

if (!history) {
history = '[]';
Expand All @@ -51,7 +55,7 @@ if (isReset) {
}

if (!roomName) {
const randomRoomName = timestamp + '-' + generateString(15);
const randomRoomName = generateString(20);
figma.root.setPluginData('roomName', randomRoomName);
roomName = randomRoomName;
}
Expand Down

0 comments on commit e0027a2

Please sign in to comment.