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

When switching themes switch the figma native theme mode selector if possible #2336

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
10 changes: 10 additions & 0 deletions src/AsyncMessageChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Copy link
Collaborator

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

if ('activeTheme' in msg.message && 'themes' in msg.message) {
const { activeTheme } = msg.message;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const { activeTheme } = msg.message;
const { activeTheme, themes } = msg.message;

const { themes } = msg.message;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const { themes } = msg.message;
const themeToFind = Object.values(activeTheme)[0];

const activeMode = themes.filter((theme) => theme.id === Object.values(activeTheme)[0])[0];
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const activeMode = themes.filter((theme) => theme.id === Object.values(activeTheme)[0])[0];
const activeMode = themes.find((theme) => theme.id === themeToFind);

figma.currentPage.children.forEach((frame) => {
frame.setExplicitVariableModeForCollection(activeMode.$figmaCollectionId ?? '', activeMode.$figmaModeId ?? '');
});
}
}
resolve(msg.message);
} else {
reject(msg.error);
Expand Down
1 change: 1 addition & 0 deletions src/app/store/models/reducers/tokenState/setActiveTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function setActiveTheme(state: TokenState, { newActiveTheme }: { newActiv
[tokenSet, TokenSetStatus.DISABLED]
)),
);

return {
...state,
usedTokenSet: usedTokenSetsMap,
Expand Down
Loading