Merge pull request #15029 from overleaf/mf-remove-angular-settings-dependency-rename-project

[web] Remove angular settings dependency when renaming a project in editor top bar

GitOrigin-RevId: 45a8b71fc84135f5291217f613cc95aea7192c35
This commit is contained in:
M Fahru 2023-09-28 09:36:08 -07:00 committed by Copybot
parent 9daa8f5d98
commit 3324a14202
5 changed files with 15 additions and 10 deletions

View file

@ -30,6 +30,7 @@ export type ProjectSettings = {
imageName: string
rootDocId: string
spellCheckLanguage: string
name: string
}
type SaveUserSettings = Partial<

View file

@ -14,6 +14,7 @@ import { useProjectContext } from './project-context'
import { useDetachContext } from './detach-context'
import getMeta from '../../utils/meta'
import { useUserContext } from './user-context'
import { saveProjectSettings } from '@/features/editor-left-menu/utils/api'
export const EditorContext = createContext()
@ -42,18 +43,23 @@ EditorContext.Provider.propTypes = {
}),
}
export function EditorProvider({ children, settings }) {
export function EditorProvider({ children }) {
const ide = useIdeContext()
const { id: userId } = useUserContext()
const { role } = useDetachContext()
const { owner, features } = useProjectContext({
const {
owner,
features,
_id: projectId,
} = useProjectContext({
owner: PropTypes.shape({
_id: PropTypes.string.isRequired,
}),
features: PropTypes.shape({
compileGroup: PropTypes.string,
}),
_id: PropTypes.string.isRequired,
})
const cobranding = useMemo(() => {
@ -106,7 +112,7 @@ export function EditorProvider({ children, settings }) {
newName => {
setProjectName(oldName => {
if (oldName !== newName) {
settings.saveProjectSettings({ name: newName }).catch(response => {
saveProjectSettings(projectId, { name: newName }).catch(response => {
setProjectName(oldName)
const { data, status } = response
if (status === 400) {
@ -122,7 +128,7 @@ export function EditorProvider({ children, settings }) {
return newName
})
},
[settings, ide, setProjectName]
[ide, setProjectName, projectId]
)
const { setTitle } = useBrowserWindow()
@ -192,7 +198,6 @@ export function EditorProvider({ children, settings }) {
EditorProvider.propTypes = {
children: PropTypes.any,
settings: PropTypes.object,
}
export function useEditorContext(propTypes) {

View file

@ -14,7 +14,7 @@ import { SplitTestProvider } from './split-test-context'
import { FileTreeDataProvider } from './file-tree-data-context'
import { ProjectSettingsProvider } from '../../features/editor-left-menu/context/project-settings-context'
export function ContextRoot({ children, ide, settings }) {
export function ContextRoot({ children, ide }) {
return (
<SplitTestProvider>
<IdeProvider ide={ide}>
@ -22,7 +22,7 @@ export function ContextRoot({ children, ide, settings }) {
<ProjectProvider>
<FileTreeDataProvider>
<DetachProvider>
<EditorProvider settings={settings}>
<EditorProvider>
<ProjectSettingsProvider>
<LayoutProvider>
<LocalCompileProvider>
@ -45,7 +45,6 @@ export function ContextRoot({ children, ide, settings }) {
ContextRoot.propTypes = {
children: PropTypes.any,
ide: PropTypes.object,
settings: PropTypes.object,
}
export const rootContext = createSharedContext(ContextRoot)

View file

@ -229,7 +229,7 @@ export const ScopeDecorator = (
}, [])
return (
<ContextRoot ide={ide} settings={{}}>
<ContextRoot ide={ide}>
<Story />
</ContextRoot>
)

View file

@ -117,7 +117,7 @@ export function EditorProviders({
<ProjectProvider>
<FileTreeDataProvider>
<DetachProvider>
<EditorProvider settings={{}}>
<EditorProvider>
<ProjectSettingsProvider>
<LayoutProvider>
<LocalCompileProvider>