2023-11-16 06:56:54 -05:00
|
|
|
import { ReactScopeValueStore } from '@/features/ide-react/scope-value-store/react-scope-value-store'
|
2023-12-18 08:52:13 -05:00
|
|
|
import customLocalStorage from '@/infrastructure/local-storage'
|
2024-08-01 08:19:58 -04:00
|
|
|
import getMeta from '@/utils/meta'
|
2023-11-16 06:56:54 -05:00
|
|
|
|
|
|
|
export function populateEditorScope(
|
|
|
|
store: ReactScopeValueStore,
|
|
|
|
projectId: string
|
|
|
|
) {
|
|
|
|
// This value is not used in the React code. It's just here to prevent errors
|
|
|
|
// from EditorProvider
|
|
|
|
store.set('state.loading', false)
|
|
|
|
|
|
|
|
store.set('project.name', null)
|
|
|
|
|
|
|
|
store.set('editor', {
|
|
|
|
showSymbolPalette: false,
|
|
|
|
toggleSymbolPalette: () => {},
|
|
|
|
sharejs_doc: null,
|
|
|
|
open_doc_id: null,
|
|
|
|
open_doc_name: null,
|
|
|
|
opening: true,
|
|
|
|
trackChanges: false,
|
|
|
|
wantTrackChanges: false,
|
|
|
|
// No Ace here
|
|
|
|
newSourceEditor: true,
|
|
|
|
error_state: false,
|
|
|
|
})
|
2023-12-18 08:52:13 -05:00
|
|
|
store.persisted(
|
|
|
|
'editor.showVisual',
|
2024-08-01 08:19:58 -04:00
|
|
|
getMeta('ol-usedLatex') === 'never' || showVisualFallbackValue(projectId),
|
2023-12-18 08:52:13 -05:00
|
|
|
`editor.lastUsedMode`,
|
|
|
|
{
|
|
|
|
toPersisted: showVisual => (showVisual ? 'visual' : 'code'),
|
|
|
|
fromPersisted: mode => mode === 'visual',
|
|
|
|
}
|
|
|
|
)
|
2024-08-01 08:19:58 -04:00
|
|
|
|
|
|
|
store.persisted(
|
|
|
|
'editor.codeEditorOpened',
|
|
|
|
codeEditorOpenedFallbackValue(),
|
|
|
|
'editor.codeEditorOpened'
|
|
|
|
)
|
|
|
|
store.watch('editor.showVisual', showVisual => {
|
|
|
|
if (store.get('editor.codeEditorOpened') !== true && showVisual === false) {
|
|
|
|
store.set('editor.codeEditorOpened', true)
|
|
|
|
}
|
|
|
|
})
|
2023-12-18 08:52:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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'
|
2023-11-16 06:56:54 -05:00
|
|
|
}
|
2024-08-01 08:19:58 -04:00
|
|
|
|
|
|
|
function codeEditorOpenedFallbackValue() {
|
|
|
|
const signUpDate = getMeta('ol-user').signUpDate
|
|
|
|
if (
|
|
|
|
typeof signUpDate === 'string' &&
|
|
|
|
new Date(signUpDate) < new Date('2024-08-02')
|
|
|
|
) {
|
|
|
|
// if signUpDate is before releasing "codeEditorOpened" value
|
|
|
|
// it is assumed that the user has opened the code editor at some point
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|