mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-02 00:31:15 -05:00
0766c91079
* open visual code if user havent used latex before * test tooltip on code editor switch * firstTimeLoadedEditor * track editor.codeEditorOpened value * lastEditorLoadedDate * odc data loaded from mongo * fix a typo * use tutorial to check if it was dissmised * use getInactiveTutorials fn * fix test * check if code editor was opened * added translations * pass classname to tooltip * use signUpDate instead of lastEditorLoadedDate * refactor visual fallback value * use tutorial completed data only for tooltip * set lastUsedMode in odc form * safer usedLatex check * getOnboardingDataValue helper function * move tooltip to a separate component * move classname to tooltipProps * usedLatex in meta tag * codeEdtiorOpened fallback value * fix release date year * fix 24 hours criteria for showing the tooltip * fix tests * hide tooltip when code editor is opened * remove setting lastUsedMode in ODC form * remove empty comment * change date for checking signUpDate * fix linting error GitOrigin-RevId: 0a57ba3f4717492d4546633571117f667d3a05f8
73 lines
2 KiB
TypeScript
73 lines
2 KiB
TypeScript
import { ReactScopeValueStore } from '@/features/ide-react/scope-value-store/react-scope-value-store'
|
|
import customLocalStorage from '@/infrastructure/local-storage'
|
|
import getMeta from '@/utils/meta'
|
|
|
|
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,
|
|
})
|
|
store.persisted(
|
|
'editor.showVisual',
|
|
getMeta('ol-usedLatex') === 'never' || showVisualFallbackValue(projectId),
|
|
`editor.lastUsedMode`,
|
|
{
|
|
toPersisted: showVisual => (showVisual ? 'visual' : 'code'),
|
|
fromPersisted: mode => mode === 'visual',
|
|
}
|
|
)
|
|
|
|
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)
|
|
}
|
|
})
|
|
}
|
|
|
|
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'
|
|
}
|
|
|
|
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
|
|
}
|