Skip to content

Comments

Multi user sync local storage#3254

Draft
akshay-gupta7 wants to merge 9 commits intomainfrom
multi-user-sync-local-storage
Draft

Multi user sync local storage#3254
akshay-gupta7 wants to merge 9 commits intomainfrom
multi-user-sync-local-storage

Conversation

@akshay-gupta7
Copy link
Contributor

Why does this PR exist?

Draft PR for Multi User sync(local storage)

What does this pull request do?

Testing this change

Additional Notes (if any)

@changeset-bot
Copy link

changeset-bot bot commented Jan 28, 2025

⚠️ No Changeset found

Latest commit: 48c89ef

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Jan 28, 2025

⤵️ 📦 ✨ The artifact was successfully created! Want to test it? Download it here 👀 🎁

@github-actions
Copy link
Contributor

github-actions bot commented Jan 28, 2025

Commit SHA:7e047e023a1da56f72177ca6b2b7649fc471082f

Test coverage results 🧪

Code coverage diff between base branch:main and head branch: multi-user-sync-local-storage 
Status File % Stmts % Branch % Funcs % Lines
🔴 total 66.9 (-0.11) 57.78 (-0.22) 63.87 (-0.02) 67.27 (-0.12)
🔴 packages/tokens-studio-for-figma/src/app/components/Initiator.tsx 66.66 (-7.25) 45.45 (-20.33) 66.66 (0) 66 (-7.33)
🟢 packages/tokens-studio-for-figma/src/figmaStorage/FigmaStorageProperty.ts 92.85 (0) 90.9 (4.54) 80 (0) 95.83 (0)
✨ 🆕 packages/tokens-studio-for-figma/src/figmaStorage/LastModifiedBy.ts 100 100 100 100
🟢 packages/tokens-studio-for-figma/src/plugin/controller.ts 98.11 (0.04) 100 (0) 75 (0) 100 (0)
✨ 🆕 packages/tokens-studio-for-figma/src/plugin/asyncMessageHandlers/syncSharedTokens.ts 33.33 0 0 33.33
🟢 packages/tokens-studio-for-figma/src/plugin/asyncMessageHandlers/update.ts 93.33 (0) 80 (2.23) 100 (0) 93.33 (0)

@github-actions
Copy link
Contributor

github-actions bot commented Jan 28, 2025

Commit SHA:7e047e023a1da56f72177ca6b2b7649fc471082f
Current PR reduces the test coverage percentage by 1 for some tests

Comment on lines 113 to 127
React.useEffect(() => {
function handleTokenSync(event: MessageEvent) {
if (event.data.pluginMessage?.type === 'sync_tokens') {
console.log('Received token update:', event.data.pluginMessage.tokens);
dispatch.tokenState.setTokenData({ values: event.data.pluginMessage.tokens });
}
}

window.addEventListener('message', handleTokenSync);

return () => {
window.removeEventListener('message', handleTokenSync);
};
});

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets not do this inside Tokens.tsx, but rather inside packages/tokens-studio-for-figma/src/app/components/Initiator.tsx

this is where we have all the plugin message listeners - thats where we can emit this

export async function sendDocumentChange(event: DocumentChangeEvent) {
if (event.documentChanges.length === 1 && event.documentChanges[0].type === 'PROPERTY_CHANGE' && event.documentChanges[0].id === '0:0') {
return;
const relevantChanges = event.documentChanges.filter((change) => change.type === 'PROPERTY_CHANGE' && change.properties?.includes('pluginData'));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you verify once if this only includes changes from another user? I want to make sure the changes you as a user make to not trigger this event

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, will check for any other filters that we can leverage

console.log('sharedTokens', sharedTokens?.global);
postToUI({
type: MessageFromPluginTypes.SYNC_TOKENS,
tokens: sharedTokens?.global,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the global here? I think we should sync all sets, not just the global set - i might be wrong here!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found the token data sent inside an object called global here, will check if its the set or in general its sent in that manner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants