Skip to content

Commit

Permalink
feat(UI): allow enabling/disabling AI from UI (editor settings screen)
Browse files Browse the repository at this point in the history
  • Loading branch information
hatemhosny committed Feb 7, 2024
1 parent 39916cf commit c422ded
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
23 changes: 20 additions & 3 deletions src/livecodes/UI/editor-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const createEditorSettingsUI = async ({

interface FormField {
title?: string;
name: keyof UserConfig | `editorTheme-${Config['editor']}-${Config['theme']}`;
name: keyof UserConfig | `editorTheme-${Config['editor']}-${Config['theme']}` | 'enableAI';
options: Array<{ label?: string; value: string; checked?: boolean }>;
help?: string;
}
Expand Down Expand Up @@ -204,6 +204,12 @@ export const createEditorSettingsUI = async ({
name: 'trailingComma',
options: [{ value: 'true' }],
},
{
title: 'Enable AI Code Assistant',
name: 'enableAI',
options: [{ value: 'true' }],
help: `${process.env.DOCS_BASE_URL}features/ai`,
},
];

const editorOptions: EditorOptions = {
Expand Down Expand Up @@ -287,7 +293,9 @@ export const createEditorSettingsUI = async ({

const name = `editor-settings-${field.name}`;
const optionValue = String(
(editorOptions as any)[field.name] ?? (defaultConfig as any)[field.name] ?? '',
(editorOptions as any)[field.name === 'enableAI' ? 'disableAI' : field.name] ??
(defaultConfig as any)[field.name] ??
'',
);

if (field.options.length > 4) {
Expand Down Expand Up @@ -341,7 +349,12 @@ export const createEditorSettingsUI = async ({
input.id = id;
input.value = option.value;
input.checked =
field.name === 'theme' ? optionValue === 'dark' : optionValue === option.value;
field.name === 'theme'
? optionValue === 'dark'
: field.name === 'enableAI'
? optionValue !== 'true'
: optionValue === option.value;

optionContainer.appendChild(input);

if (isCheckBox) {
Expand Down Expand Up @@ -392,6 +405,10 @@ export const createEditorSettingsUI = async ({
if (key === 'theme') {
formData.theme = (formData.theme as any) === true ? 'dark' : 'light';
}
if (key === 'enableAI') {
formData.disableAI = !(formData as any).enableAI;
delete (formData as any).enableAI;
}
});

formData.editorTheme = allThemes
Expand Down
2 changes: 1 addition & 1 deletion src/livecodes/vendors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const cm6ThemeSolarizedDarkUrl = /* @__PURE__ */ getUrl(
);

export const codeiumProviderUrl = /* @__PURE__ */ getUrl(
'@live-codes/monaco-codeium-provider@0.1.0/dist/index.js',
'@live-codes/monaco-codeium-provider@0.1.2/dist/index.js',
);

export const coffeeScriptUrl = /* @__PURE__ */ getUrl(
Expand Down

0 comments on commit c422ded

Please sign in to comment.