async updates for settings

This commit is contained in:
Elio Struyf
2022-10-07 13:32:49 +02:00
parent 8a8db67e82
commit b9a0c656d3
6 changed files with 13 additions and 11 deletions

View File

@@ -37,7 +37,7 @@ categories: []
await Settings.createTeamSettings();
// Add the default content type
Settings.update(SETTING_TAXONOMY_CONTENT_TYPES, [DEFAULT_CONTENT_TYPE], true);
await Settings.update(SETTING_TAXONOMY_CONTENT_TYPES, [DEFAULT_CONTENT_TYPE], true);
if (sampleTemplate !== undefined) {
await Project.createSampleTemplate();

View File

@@ -163,10 +163,10 @@ export const StepsToGetStarted: React.FunctionComponent<IStepsToGetStartedProps>
];
React.useEffect(() => {
if (settings.crntFramework) {
setFramework(settings.crntFramework);
if (settings.crntFramework || settings.framework?.name) {
setFramework(settings.crntFramework || settings.framework?.name || null);
}
}, [settings.crntFramework]);
}, [settings.crntFramework, settings.framework]);
return (
<nav aria-label="Progress">

View File

@@ -194,7 +194,7 @@ export class ContentType {
contentTypes.push(newContentType);
}
Settings.update(SETTING_TAXONOMY_CONTENT_TYPES, contentTypes, true);
await Settings.update(SETTING_TAXONOMY_CONTENT_TYPES, contentTypes, true);
const configPath = Settings.projectConfigPath;
const notificationAction = await Notifications.info(`Content type ${contentTypeName} has been ${overrideBool ? `updated` : `generated`}.`, configPath && await existsAsync(configPath) ? `Open settings` : undefined);
@@ -228,7 +228,7 @@ export class ContentType {
const index = contentTypes.findIndex(ct => ct.name === contentType.name);
contentTypes[index].fields = updatedFields;
Settings.update(SETTING_TAXONOMY_CONTENT_TYPES, contentTypes, true);
await Settings.update(SETTING_TAXONOMY_CONTENT_TYPES, contentTypes, true);
const configPath = Settings.projectConfigPath;
const notificationAction = await Notifications.info(`Content type ${contentType.name} has been updated.`, configPath && await existsAsync(configPath) ? `Open settings` : undefined);

View File

@@ -232,7 +232,7 @@ export class Extension {
ignoreFocusOut: true
});
Settings.update(SETTING_TEMPLATES_ENABLED, answer?.toLocaleLowerCase() === "yes", true);
await Settings.update(SETTING_TEMPLATES_ENABLED, answer?.toLocaleLowerCase() === "yes", true);
}
}
}

View File

@@ -186,7 +186,9 @@ export class Settings {
const localConfig = await readFileAsync(fmConfig, 'utf8');
Settings.globalConfig = jsoncParser.parse(localConfig);
Settings.globalConfig[`${CONFIG_KEY}.${name}`] = value;
await writeFileAsync(fmConfig, JSON.stringify(Settings.globalConfig, null, 2), 'utf8');
const content = JSON.stringify(Settings.globalConfig, null, 2);
await writeFileAsync(fmConfig, content, 'utf8');
const workspaceSettingValue = Settings.hasWorkspaceSettings<ContentType[]>(name);
if (workspaceSettingValue) {

View File

@@ -60,17 +60,17 @@ export class SettingsListener extends BaseListener {
* @param frameworkId
*/
public static async setFramework(frameworkId: string | null) {
Settings.update(SETTING_FRAMEWORK_ID, frameworkId, true);
await Settings.update(SETTING_FRAMEWORK_ID, frameworkId, true);
if (frameworkId) {
const allFrameworks = FrameworkDetector.getAll();
const framework = allFrameworks.find((f: Framework) => f.name === frameworkId);
if (framework) {
Settings.update(SETTING_CONTENT_STATIC_FOLDER, framework.static, true);
await Settings.update(SETTING_CONTENT_STATIC_FOLDER, framework.static, true);
await FrameworkDetector.checkDefaultSettings(framework);
} else {
Settings.update(SETTING_CONTENT_STATIC_FOLDER, "", true);
await Settings.update(SETTING_CONTENT_STATIC_FOLDER, "", true);
}
}