Commit a515b459 authored by Phil Hughes's avatar Phil Hughes

remove extra state property

pending tabs now get added into openfiles & just filtered correctly
parent 89bb7b85
...@@ -32,7 +32,7 @@ export default { ...@@ -32,7 +32,7 @@ export default {
}, },
computed: { computed: {
...mapState(['changedFiles', 'openFiles', 'viewer']), ...mapState(['changedFiles', 'openFiles', 'viewer']),
...mapGetters(['activeFile', 'hasChanges', 'tabs']), ...mapGetters(['activeFile', 'hasChanges']),
}, },
mounted() { mounted() {
const returnValue = 'Are you sure you want to lose unsaved changes?'; const returnValue = 'Are you sure you want to lose unsaved changes?';
...@@ -61,7 +61,7 @@ export default { ...@@ -61,7 +61,7 @@ export default {
> >
<repo-tabs <repo-tabs
:active-file="activeFile" :active-file="activeFile"
:files="tabs" :files="openFiles"
:viewer="viewer" :viewer="viewer"
:has-changes="hasChanges" :has-changes="hasChanges"
/> />
......
...@@ -76,11 +76,17 @@ router.beforeEach((to, from, next) => { ...@@ -76,11 +76,17 @@ router.beforeEach((to, from, next) => {
.then(() => { .then(() => {
if (to.params[0]) { if (to.params[0]) {
const path = const path =
to.params[0].slice(-1) === '/' to.params[0].slice(-1) === '/' ? to.params[0].slice(0, -1) : to.params[0];
? to.params[0].slice(0, -1) const treeEntry = Object.keys(store.state.entries).reduce((acc, key) => {
: to.params[0]; const file = store.state.entries[key];
const treeEntry = store.state.entries[path]; if (key === path && !file.pending) {
if (treeEntry) { return file;
}
return acc;
}, {});
if (Object.keys(treeEntry).length) {
store.dispatch('handleTreeEntryAction', treeEntry); store.dispatch('handleTreeEntryAction', treeEntry);
} }
} }
......
...@@ -6,9 +6,9 @@ import * as types from '../mutation_types'; ...@@ -6,9 +6,9 @@ import * as types from '../mutation_types';
import router from '../../ide_router'; import router from '../../ide_router';
import { setPageTitle } from '../utils'; import { setPageTitle } from '../utils';
export const closeFile = ({ commit, state, getters, dispatch }, file) => { export const closeFile = ({ commit, state, dispatch }, file) => {
const path = file.path; const path = file.path;
const indexOfClosedFile = getters.tabs.findIndex(f => f.key === file.key); const indexOfClosedFile = state.openFiles.findIndex(f => f.key === file.key);
const fileWasActive = file.active; const fileWasActive = file.active;
if (file.pending) { if (file.pending) {
...@@ -18,9 +18,9 @@ export const closeFile = ({ commit, state, getters, dispatch }, file) => { ...@@ -18,9 +18,9 @@ export const closeFile = ({ commit, state, getters, dispatch }, file) => {
commit(types.SET_FILE_ACTIVE, { path, active: false }); commit(types.SET_FILE_ACTIVE, { path, active: false });
} }
if (getters.tabs.length > 0 && fileWasActive) { if (state.openFiles.length > 0 && fileWasActive) {
const nextIndexToOpen = indexOfClosedFile === 0 ? 0 : indexOfClosedFile - 1; const nextIndexToOpen = indexOfClosedFile === 0 ? 0 : indexOfClosedFile - 1;
const nextFileToOpen = getters.tabs[nextIndexToOpen]; const nextFileToOpen = state.openFiles[nextIndexToOpen];
if (nextFileToOpen.pending) { if (nextFileToOpen.pending) {
dispatch('updateViewer', 'diff'); dispatch('updateViewer', 'diff');
...@@ -29,7 +29,7 @@ export const closeFile = ({ commit, state, getters, dispatch }, file) => { ...@@ -29,7 +29,7 @@ export const closeFile = ({ commit, state, getters, dispatch }, file) => {
dispatch('updateDelayViewerUpdated', true); dispatch('updateDelayViewerUpdated', true);
router.push(`/project${nextFileToOpen.url}`); router.push(`/project${nextFileToOpen.url}`);
} }
} else if (!getters.tabs.length) { } else if (!state.openFiles.length) {
router.push(`/project/${file.projectId}/tree/${file.branchId}/`); router.push(`/project/${file.projectId}/tree/${file.branchId}/`);
} }
...@@ -76,14 +76,7 @@ export const getFileData = ({ state, commit, dispatch }, file) => { ...@@ -76,14 +76,7 @@ export const getFileData = ({ state, commit, dispatch }, file) => {
}) })
.catch(() => { .catch(() => {
commit(types.TOGGLE_LOADING, { entry: file }); commit(types.TOGGLE_LOADING, { entry: file });
flash( flash('Error loading file data. Please try again.', 'alert', document, null, false, true);
'Error loading file data. Please try again.',
'alert',
document,
null,
false,
true,
);
}); });
}; };
...@@ -94,14 +87,7 @@ export const getRawFileData = ({ commit, dispatch }, file) => ...@@ -94,14 +87,7 @@ export const getRawFileData = ({ commit, dispatch }, file) =>
commit(types.SET_FILE_RAW_DATA, { file, raw }); commit(types.SET_FILE_RAW_DATA, { file, raw });
}) })
.catch(() => .catch(() =>
flash( flash('Error loading file content. Please try again.', 'alert', document, null, false, true),
'Error loading file content. Please try again.',
'alert',
document,
null,
false,
true,
),
); );
export const changeFileContent = ({ state, commit }, { path, content }) => { export const changeFileContent = ({ state, commit }, { path, content }) => {
...@@ -129,10 +115,7 @@ export const setFileEOL = ({ getters, commit }, { eol }) => { ...@@ -129,10 +115,7 @@ export const setFileEOL = ({ getters, commit }, { eol }) => {
} }
}; };
export const setEditorPosition = ( export const setEditorPosition = ({ getters, commit }, { editorRow, editorColumn }) => {
{ getters, commit },
{ editorRow, editorColumn },
) => {
if (getters.activeFile) { if (getters.activeFile) {
commit(types.SET_FILE_POSITION, { commit(types.SET_FILE_POSITION, {
file: getters.activeFile, file: getters.activeFile,
......
export const tabs = state => state.openFiles.concat(state.pendingTabs); export const activeFile = state => state.openFiles.find(file => file.active) || null;
export const activeFile = state => tabs(state).find(file => file.active) || null;
export const addedFiles = state => state.changedFiles.filter(f => f.tempFile); export const addedFiles = state => state.changedFiles.filter(f => f.tempFile);
......
...@@ -6,12 +6,15 @@ export default { ...@@ -6,12 +6,15 @@ export default {
active, active,
}); });
if (active) { if (active && !state.entries[path].pending) {
Object.assign(state, { Object.assign(state, {
pendingTabs: state.pendingTabs.map(f => ({ openFiles: state.openFiles.map(f => {
...f, if (f.pending) {
active: false, return Object.assign(f, { active: false });
})), }
return f;
}),
}); });
} }
}, },
...@@ -23,8 +26,10 @@ export default { ...@@ -23,8 +26,10 @@ export default {
if (state.entries[path].opened) { if (state.entries[path].opened) {
state.openFiles.push(state.entries[path]); state.openFiles.push(state.entries[path]);
} else { } else {
const file = state.entries[path];
Object.assign(state, { Object.assign(state, {
openFiles: state.openFiles.filter(f => f.path !== path), openFiles: state.openFiles.filter(f => f.key !== file.key),
}); });
} }
}, },
...@@ -90,26 +95,31 @@ export default { ...@@ -90,26 +95,31 @@ export default {
}); });
}, },
[types.ADD_PENDING_TAB](state, file) { [types.ADD_PENDING_TAB](state, file) {
const pendingTab = state.pendingTabs.find(f => f.path === file.path); const pendingTab = state.openFiles.find(f => f.path === file.path && f.pending);
Object.assign(state, { Object.assign(state, {
openFiles: state.openFiles.map(f => openFiles: state.openFiles.map(f => {
Object.assign(f, { if (!f.pending) {
active: false, return Object.assign(f, { active: false });
}
return f;
}), }),
),
}); });
if (pendingTab) { if (pendingTab) {
Object.assign(state, { Object.assign(state, {
pendingTabs: state.pendingTabs.map(tab => ({ openFiles: state.openFiles.map(f => {
...tab, if (f.pending && f.path === file.path) {
active: !!pendingTab, return Object.assign(f, { active: true });
})), }
return f;
}),
}); });
} else { } else {
Object.assign(state, { Object.assign(state, {
pendingTabs: state.pendingTabs.concat({ openFiles: state.openFiles.concat({
...file, ...file,
active: true, active: true,
pending: true, pending: true,
...@@ -120,7 +130,7 @@ export default { ...@@ -120,7 +130,7 @@ export default {
}, },
[types.REMOVE_PENDING_TAB](state, file) { [types.REMOVE_PENDING_TAB](state, file) {
Object.assign(state, { Object.assign(state, {
pendingTabs: state.pendingTabs.filter(f => f.path !== file.path), openFiles: state.openFiles.filter(f => f.key !== file.key),
}); });
}, },
}; };
...@@ -16,5 +16,4 @@ export default () => ({ ...@@ -16,5 +16,4 @@ export default () => ({
entries: {}, entries: {},
viewer: 'editor', viewer: 'editor',
delayViewerUpdated: false, delayViewerUpdated: false,
pendingTabs: [],
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment