-
-
Notifications
You must be signed in to change notification settings - Fork 196
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
When switching themes switch the figma native theme mode selector if possible #2336
base: main
Are you sure you want to change the base?
When switching themes switch the figma native theme mode selector if possible #2336
Conversation
…into 2187-when-switching-themes-switch-the-figma-native-theme-mode-selector-if-possible
🦋 Changeset detectedLatest commit: 21f2ae5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
PR Analysis
PR Feedback
How to use
|
src/AsyncMessageChannel.ts
Outdated
@@ -122,6 +122,16 @@ export class AsyncMessageChannel { | |||
this.attachMessageListener((msg: IncomingMessageEvent<AsyncMessageResults & { type: Message['type'] }>['data']['pluginMessage']) => { | |||
if (msg.id === messageId) { | |||
if ('message' in msg) { | |||
if (msg.message.type === 'async/get-theme-info') { | |||
if ('activeTheme' in msg.message && 'themes' in msg.message) { | |||
const { activeTheme } = msg.message; |
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.
const { activeTheme } = msg.message; | |
const { activeTheme, themes } = msg.message; |
src/AsyncMessageChannel.ts
Outdated
if (msg.message.type === 'async/get-theme-info') { | ||
if ('activeTheme' in msg.message && 'themes' in msg.message) { | ||
const { activeTheme } = msg.message; | ||
const { themes } = msg.message; |
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.
const { themes } = msg.message; | |
const themeToFind = Object.values(activeTheme)[0]; |
src/AsyncMessageChannel.ts
Outdated
if ('activeTheme' in msg.message && 'themes' in msg.message) { | ||
const { activeTheme } = msg.message; | ||
const { themes } = msg.message; | ||
const activeMode = themes.filter((theme) => theme.id === Object.values(activeTheme)[0])[0]; |
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.
const activeMode = themes.filter((theme) => theme.id === Object.values(activeTheme)[0])[0]; | |
const activeMode = themes.find((theme) => theme.id === themeToFind); |
Can you add a changeset so we can inform the users about this change? Check to see if the fixes for the lookup fix the OOM error, otherwise we'll have to double check why that's occurring |
Tests are failing here |
…into 2187-when-switching-themes-switch-the-figma-native-theme-mode-selector-if-possible
…into 2187-when-switching-themes-switch-the-figma-native-theme-mode-selector-if-possible
Commit SHA:4c507f93be36defe7933184695662c0f75d72629 Test coverage results 🧪
|
Commit SHA:4c507f93be36defe7933184695662c0f75d72629 |
@@ -0,0 +1,5 @@ | |||
--- |
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.
This looks redundant?
const activeMode = themes.find((theme) => theme.id === themeToFind); | ||
if (figma.currentPage.children && figma.currentPage.children.length > 0) { | ||
figma.currentPage.children.forEach((frame) => { | ||
frame.setExplicitVariableModeForCollection(activeMode?.$figmaCollectionId ?? '', activeMode?.$figmaModeId ?? ''); |
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.
Shouldn't we be using an if around this and checking that the string id's exist? What happens when we these are invalid or null?
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.
yeah it could be that the information is outdated and then this will error. they'll likely not be invalid or null but it could be that it doesnt exist anymore causing an error.
let's check for if a) those are set and b) wrap so that we dont crash
@@ -122,6 +122,18 @@ export class AsyncMessageChannel { | |||
this.attachMessageListener((msg: IncomingMessageEvent<AsyncMessageResults & { type: Message['type'] }>['data']['pluginMessage']) => { | |||
if (msg.id === messageId) { | |||
if ('message' in msg) { | |||
if (msg.message.type === 'async/get-theme-info') { |
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.
i dont think this belongs here. this file doesnt have any of the other message handlers, this needs to go elsewhere where we define those.
switch (pluginMessage.type) { |
this feels like the right place
const activeMode = themes.find((theme) => theme.id === themeToFind); | ||
if (figma.currentPage.children && figma.currentPage.children.length > 0) { | ||
figma.currentPage.children.forEach((frame) => { | ||
frame.setExplicitVariableModeForCollection(activeMode?.$figmaCollectionId ?? '', activeMode?.$figmaModeId ?? ''); |
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.
yeah it could be that the information is outdated and then this will error. they'll likely not be invalid or null but it could be that it doesnt exist anymore causing an error.
let's check for if a) those are set and b) wrap so that we dont crash
const themeToFind = Object.values(activeTheme)[0]; | ||
const activeMode = themes.find((theme) => theme.id === themeToFind); | ||
if (figma.currentPage.children && figma.currentPage.children.length > 0) { | ||
figma.currentPage.children.forEach((frame) => { |
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.
this ignores the issue requirement completely and sets an active variable mode for every frame on the current page. this is not what we need. we need to apply way more logic here than that.
the issue states that it should have different behavior depending on the apply mode
if (msg.message.type === 'async/get-theme-info') { | ||
if ('activeTheme' in msg.message && 'themes' in msg.message) { | ||
const { activeTheme, themes } = msg.message; | ||
const themeToFind = Object.values(activeTheme)[0]; |
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.
we do not just want to switch the first theme, but all theme groups that are active
20231025_133845.mp4
Closes #2187