Skip to content

Commit

Permalink
Update how skillmap handles preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
thsparks committed Mar 6, 2025
1 parent 11e9b41 commit 3d23568
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions skillmap/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ class AppImpl extends React.Component<AppProps, AppState> {
changeTheme(theme: pxt.ColorThemeInfo) {
pxt.tickEvent(`skillmap.menu.theme.changetheme`, { theme: theme.id });
this.themeManager.switchColorTheme(theme.id);
authClient.setColorThemeIdAsync(theme.id);
}

render() {
Expand Down
3 changes: 1 addition & 2 deletions skillmap/src/components/makecodeFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ class MakeCodeFrameImpl extends React.Component<MakeCodeFrameProps, MakeCodeFram
{
type: "pxteditor",
action: "setcolorthemebyid",
colorThemeId,
savePreference: true
colorThemeId
} as pxt.editor.EditorMessageSetColorThemeRequest
);
}
Expand Down
21 changes: 19 additions & 2 deletions skillmap/src/lib/authClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,26 @@ export async function getBadgeStateAsync(): Promise<pxt.auth.UserBadgeState | un
}

export async function getColorThemeIdAsync(): Promise<string | undefined> {
const prefs = await userPreferencesAsync();
if(prefs) {
return prefs?.colorThemeIds?.[pxt.appTarget.id];
}
}

export async function setColorThemeIdAsync(themeId: string): Promise<void> {
const cli = await clientAsync();
const prefs = await cli?.userPreferencesAsync();
return prefs?.colorThemeIds?.[pxt.appTarget.id];
if (cli) {
const currentPrefs = await cli.userPreferencesAsync();
const newColorThemePref = {
...currentPrefs?.colorThemeIds,
[pxt.appTarget.id]: themeId
};
await cli.patchUserPreferencesAsync({
op: 'replace',
path: ['colorThemeIds'],
value: newColorThemePref
});
}
}

export async function userPreferencesAsync(): Promise<pxt.auth.UserPreferences | undefined> {
Expand Down

0 comments on commit 3d23568

Please sign in to comment.