Skip to content

Commit

Permalink
Always open root directory in TreeView
Browse files Browse the repository at this point in the history
  • Loading branch information
N. Justus committed Sep 27, 2019
1 parent 6b57236 commit 7e6e787
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ui/src/models/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export function setId(root:FileNode): FileNode {
...root
}
}
export function toggleRoot(root:FileNode): FileNode {
return { ...root, toggled: true }
}

export function renameFile(root: FileNode, oldFile: FilePath, newFile: FilePath): FileNode {
if(root.file && root.file === oldFile)
Expand Down
8 changes: 5 additions & 3 deletions ui/src/redux/reducers.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import { initialState, AppState, Session, SimulationOption, SimulationData, ProjectPreviewState, Notification, BackgroundJobInfo } from '../models/state'
import { Project } from '../models/project'
import { File, FileNode, setId } from '../models/file'
import { File, FileNode, setId, toggleRoot } from '../models/file'
import { Action, ActionTypes } from './actions'
import * as utils from '../utils'
import * as R from 'ramda'
import { CompilerError, AuthServiceToken, WebmodelicaToken } from '../models/index';
import { oc } from 'ts-optchain';

const setupNodes = R.compose(toggleRoot, setId)

const reducerMap = {
[ActionTypes.SetProjects.toString()]: (state: AppState, data: Project[]) => { return { ...state, projects: data } },
[ActionTypes.SetProject.toString()]: (state: AppState, project: Project) => ({
...state,
projects: R.reduce((acc: Project[], p) => R.append((p.id === project.id) ? project : p, acc), [], state.projects)
}),
[ActionTypes.SetSessionFiles.toString()]: (state: AppState, files: FileNode) => ({ ...state, session: { ...state.session!, files: setId(files) } }),
[ActionTypes.SetSessionFiles.toString()]: (state: AppState, files: FileNode) => ({ ...state, session: { ...state.session!, files: setupNodes(files) } }),
[ActionTypes.AddProject.toString()]: (state: AppState, data: Project) => ({ ...state, projects: R.prepend(data, state.projects) }),
[ActionTypes.SetProjectPreview.toString()]: (state: AppState, data: ProjectPreviewState) => ({ ...state, projectPreview: { ...data, files: setId(data.files) } }),
[ActionTypes.SetProjectPreview.toString()]: (state: AppState, data: ProjectPreviewState) => ({ ...state, projectPreview: { ...data, files: setupNodes(data.files) } }),
[ActionTypes.SetOpenFile.toString()]: (state: AppState, file: File) => R.assocPath(['session', 'openedFile'], file, state),
[ActionTypes.SetSession.toString()]: (state: AppState, session: Session) => ({ ...state, session: session }),
[ActionTypes.UpdateWsToken.toString()]: (state: AppState, token: string) => {
Expand Down

0 comments on commit 7e6e787

Please sign in to comment.