Store editor selection on a per-user rather than per-project basis (#16246)

* Store editor selection on a per-user rather than per-project basis

* set code editor if rich_text=false

* format fix

GitOrigin-RevId: 8efc33b682de211162e674839e6b891ec04e542e
This commit is contained in:
Domagoj Kriskovic
2023-12-19 09:04:31 +00:00
committed by Copybot
parent b0028a2789
commit da2f7ff153
3 changed files with 38 additions and 12 deletions
@@ -1,4 +1,5 @@
import { ReactScopeValueStore } from '@/features/ide-react/scope-value-store/react-scope-value-store'
import customLocalStorage from '@/infrastructure/local-storage'
export function populateEditorScope(
store: ReactScopeValueStore,
@@ -23,8 +24,25 @@ export function populateEditorScope(
newSourceEditor: true,
error_state: false,
})
store.persisted('editor.showVisual', false, `editor.mode.${projectId}`, {
toPersisted: showVisual => (showVisual ? 'rich-text' : 'source'),
fromPersisted: mode => mode === 'rich-text',
})
store.persisted(
'editor.showVisual',
showVisualFallbackValue(projectId),
`editor.lastUsedMode`,
{
toPersisted: showVisual => (showVisual ? 'visual' : 'code'),
fromPersisted: mode => mode === 'visual',
}
)
}
function showVisualFallbackValue(projectId: string) {
const editorModeKey = `editor.mode.${projectId}`
const editorModeVal = customLocalStorage.getItem(editorModeKey)
if (editorModeVal) {
// clean up the old key
customLocalStorage.removeItem(editorModeKey)
}
return editorModeVal === 'rich-text'
}