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 {
},
computed: {
...mapState(['changedFiles', 'openFiles', 'viewer']),
...mapGetters(['activeFile', 'hasChanges', 'tabs']),
...mapGetters(['activeFile', 'hasChanges']),
},
mounted() {
const returnValue = 'Are you sure you want to lose unsaved changes?';
......@@ -61,7 +61,7 @@ export default {
>
<repo-tabs
:active-file="activeFile"
:files="tabs"
:files="openFiles"
:viewer="viewer"
:has-changes="hasChanges"
/>
......
......@@ -76,11 +76,17 @@ router.beforeEach((to, from, next) => {
.then(() => {
if (to.params[0]) {
const path =
to.params[0].slice(-1) === '/'
? to.params[0].slice(0, -1)
: to.params[0];
const treeEntry = store.state.entries[path];
if (treeEntry) {
to.params[0].slice(-1) === '/' ? to.params[0].slice(0, -1) : to.params[0];
const treeEntry = Object.keys(store.state.entries).reduce((acc, key) => {
const file = store.state.entries[key];
if (key === path && !file.pending) {
return file;
}
return acc;
}, {});
if (Object.keys(treeEntry).length) {
store.dispatch('handleTreeEntryAction', treeEntry);
}
}
......
......@@ -6,9 +6,9 @@ import * as types from '../mutation_types';
import router from '../../ide_router';
import { setPageTitle } from '../utils';
export const closeFile = ({ commit, state, getters, dispatch }, file) => {
export const closeFile = ({ commit, state, dispatch }, file) => {
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;
if (file.pending) {
......@@ -18,9 +18,9 @@ export const closeFile = ({ commit, state, getters, dispatch }, file) => {
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 nextFileToOpen = getters.tabs[nextIndexToOpen];
const nextFileToOpen = state.openFiles[nextIndexToOpen];
if (nextFileToOpen.pending) {
dispatch('updateViewer', 'diff');
......@@ -29,7 +29,7 @@ export const closeFile = ({ commit, state, getters, dispatch }, file) => {
dispatch('updateDelayViewerUpdated', true);
router.push(`/project${nextFileToOpen.url}`);
}
} else if (!getters.tabs.length) {
} else if (!state.openFiles.length) {
router.push(`/project/${file.projectId}/tree/${file.branchId}/`);
}
......@@ -76,14 +76,7 @@ export const getFileData = ({ state, commit, dispatch }, file) => {
})
.catch(() => {
commit(types.TOGGLE_LOADING, { entry: file });
flash(
'Error loading file data. Please try again.',
'alert',
document,
null,
false,
true,
);
flash('Error loading file data. Please try again.', 'alert', document, null, false, true);
});
};
......@@ -94,14 +87,7 @@ export const getRawFileData = ({ commit, dispatch }, file) =>
commit(types.SET_FILE_RAW_DATA, { file, raw });
})
.catch(() =>
flash(
'Error loading file content. Please try again.',
'alert',
document,
null,
false,
true,
),
flash('Error loading file content. Please try again.', 'alert', document, null, false, true),
);
export const changeFileContent = ({ state, commit }, { path, content }) => {
......@@ -129,10 +115,7 @@ export const setFileEOL = ({ getters, commit }, { eol }) => {
}
};
export const setEditorPosition = (
{ getters, commit },
{ editorRow, editorColumn },
) => {
export const setEditorPosition = ({ getters, commit }, { editorRow, editorColumn }) => {
if (getters.activeFile) {
commit(types.SET_FILE_POSITION, {
file: getters.activeFile,
......
export const tabs = state => state.openFiles.concat(state.pendingTabs);
export const activeFile = state => tabs(state).find(file => file.active) || null;
export const activeFile = state => state.openFiles.find(file => file.active) || null;
export const addedFiles = state => state.changedFiles.filter(f => f.tempFile);
......
......@@ -6,12 +6,15 @@ export default {
active,
});
if (active) {
if (active && !state.entries[path].pending) {
Object.assign(state, {
pendingTabs: state.pendingTabs.map(f => ({
...f,
active: false,
})),
openFiles: state.openFiles.map(f => {
if (f.pending) {
return Object.assign(f, { active: false });
}
return f;
}),
});
}
},
......@@ -23,8 +26,10 @@ export default {
if (state.entries[path].opened) {
state.openFiles.push(state.entries[path]);
} else {
const file = state.entries[path];
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 {
});
},
[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, {
openFiles: state.openFiles.map(f =>
Object.assign(f, {
active: false,
openFiles: state.openFiles.map(f => {
if (!f.pending) {
return Object.assign(f, { active: false });
}
return f;
}),
),
});
if (pendingTab) {
Object.assign(state, {
pendingTabs: state.pendingTabs.map(tab => ({
...tab,
active: !!pendingTab,
})),
openFiles: state.openFiles.map(f => {
if (f.pending && f.path === file.path) {
return Object.assign(f, { active: true });
}
return f;
}),
});
} else {
Object.assign(state, {
pendingTabs: state.pendingTabs.concat({
openFiles: state.openFiles.concat({
...file,
active: true,
pending: true,
......@@ -120,7 +130,7 @@ export default {
},
[types.REMOVE_PENDING_TAB](state, file) {
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 () => ({
entries: {},
viewer: 'editor',
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