-
-
Notifications
You must be signed in to change notification settings - Fork 198
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
base: main
Are you sure you want to change the base?
Changes from all commits
af17c9b
f5c0280
59dd433
ffec7c7
f7ca9ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { AsyncMessageChannelHandlers } from '@/AsyncMessageChannel'; | ||
import { AsyncMessageTypes } from '@/types/AsyncMessages'; | ||
import { ValuesProperty } from '@/figmaStorage/ValuesProperty'; | ||
|
||
export const syncSharedTokens: AsyncMessageChannelHandlers[AsyncMessageTypes.SYNC_SHARED_TOKENS] = async () => { | ||
const sharedTokens = await ValuesProperty.read(); | ||
return { sharedTokens: Object.values(sharedTokens || {}).flat() }; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,22 @@ | ||
import { sendSelectionChange } from './sendSelectionChange'; | ||
import { ValuesProperty } from '@/figmaStorage/ValuesProperty'; | ||
import { postToUI } from './notifiers'; | ||
import { MessageFromPluginTypes } from '@/types/messages'; | ||
|
||
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')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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('relevantChanges', relevantChanges); | ||
|
||
if (relevantChanges.length > 0) { | ||
const sharedTokens = await ValuesProperty.read(); | ||
console.log('sharedTokens', sharedTokens?.global); | ||
postToUI({ | ||
type: MessageFromPluginTypes.SYNC_TOKENS, | ||
tokens: sharedTokens?.global, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whats the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
}); | ||
} | ||
const changeNodeIds = event.documentChanges.filter((change) => change.origin === 'REMOTE' && change.type === 'PROPERTY_CHANGE').map((change) => change.id); | ||
if (!changeNodeIds.length) { | ||
|
||
if (event.documentChanges.length === 1 && event.documentChanges[0].type === 'PROPERTY_CHANGE' && event.documentChanges[0].id === '0:0') { | ||
return; | ||
} | ||
await sendSelectionChange(); | ||
|
There was a problem hiding this comment.
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