Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi user sync local storage #3254

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

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)

Copy link

changeset-bot bot commented Jan 28, 2025

⚠️ No Changeset found

Latest commit: f7ca9ec

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

Copy link
Contributor

github-actions bot commented Jan 28, 2025

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

Copy link
Contributor

github-actions bot commented Jan 28, 2025

Commit SHA:e4eb90ed650e35b29c78840b13ad4498239618fb

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 67 (-0.01) 57.99 (-0.02) 63.93 (0.04) 67.37 (-0.02)
🟢 packages/tokens-studio-for-figma/src/app/components/Tokens.tsx 72.72 (-0.13) 28.2 (1.18) 63.63 (5.74) 71.62 (-0.02)
🟢 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

Copy link
Contributor

github-actions bot commented Jan 28, 2025

Commit SHA:e4eb90ed650e35b29c78840b13ad4498239618fb
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