2017-10-26 10:12:34 -04:00
|
|
|
export const dataStructure = () => ({
|
2017-10-26 06:14:31 -04:00
|
|
|
id: '',
|
2017-11-06 03:53:33 -05:00
|
|
|
key: '',
|
2017-10-26 06:14:31 -04:00
|
|
|
type: '',
|
|
|
|
name: '',
|
|
|
|
url: '',
|
|
|
|
path: '',
|
|
|
|
level: 0,
|
|
|
|
tempFile: false,
|
|
|
|
icon: '',
|
|
|
|
tree: [],
|
|
|
|
loading: false,
|
|
|
|
opened: false,
|
|
|
|
active: false,
|
|
|
|
changed: false,
|
2017-11-01 12:08:06 -04:00
|
|
|
lastCommitPath: '',
|
|
|
|
lastCommit: {
|
|
|
|
url: '',
|
|
|
|
message: '',
|
|
|
|
updatedAt: '',
|
|
|
|
},
|
2017-10-26 06:14:31 -04:00
|
|
|
tree_url: '',
|
|
|
|
blamePath: '',
|
|
|
|
commitsPath: '',
|
|
|
|
permalink: '',
|
|
|
|
rawPath: '',
|
|
|
|
binary: false,
|
|
|
|
html: '',
|
|
|
|
raw: '',
|
|
|
|
content: '',
|
|
|
|
parentTreeUrl: '',
|
2017-10-26 11:54:44 -04:00
|
|
|
renderError: false,
|
2017-10-31 08:13:29 -04:00
|
|
|
base64: false,
|
2017-10-26 06:14:31 -04:00
|
|
|
});
|
|
|
|
|
2017-11-01 12:08:06 -04:00
|
|
|
export const decorateData = (entity) => {
|
2017-10-26 06:14:31 -04:00
|
|
|
const {
|
|
|
|
id,
|
2017-10-26 10:12:34 -04:00
|
|
|
type,
|
2017-10-26 06:14:31 -04:00
|
|
|
url,
|
|
|
|
name,
|
|
|
|
icon,
|
|
|
|
tree_url,
|
|
|
|
path,
|
2017-10-26 11:54:44 -04:00
|
|
|
renderError,
|
2017-10-31 08:13:29 -04:00
|
|
|
content = '',
|
2017-10-27 13:16:28 -04:00
|
|
|
tempFile = false,
|
2017-10-26 06:14:31 -04:00
|
|
|
active = false,
|
|
|
|
opened = false,
|
2017-10-26 10:12:34 -04:00
|
|
|
changed = false,
|
|
|
|
parentTreeUrl = '',
|
|
|
|
level = 0,
|
2017-10-31 08:13:29 -04:00
|
|
|
base64 = false,
|
2017-10-26 06:14:31 -04:00
|
|
|
} = entity;
|
|
|
|
|
|
|
|
return {
|
2017-10-26 10:12:34 -04:00
|
|
|
...dataStructure(),
|
2017-10-26 06:14:31 -04:00
|
|
|
id,
|
2017-11-06 03:53:33 -05:00
|
|
|
key: `${name}-${type}-${id}`,
|
2017-10-26 06:14:31 -04:00
|
|
|
type,
|
|
|
|
name,
|
|
|
|
url,
|
|
|
|
tree_url,
|
|
|
|
path,
|
|
|
|
level,
|
|
|
|
tempFile,
|
|
|
|
icon: `fa-${icon}`,
|
|
|
|
opened,
|
|
|
|
active,
|
|
|
|
parentTreeUrl,
|
2017-10-26 10:12:34 -04:00
|
|
|
changed,
|
2017-10-26 11:54:44 -04:00
|
|
|
renderError,
|
2017-10-31 08:13:29 -04:00
|
|
|
content,
|
|
|
|
base64,
|
2017-10-26 06:14:31 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-10-26 10:12:34 -04:00
|
|
|
export const findEntry = (state, type, name) => state.tree.find(
|
|
|
|
f => f.type === type && f.name === name,
|
|
|
|
);
|
2017-10-26 06:14:31 -04:00
|
|
|
export const findIndexOfFile = (state, file) => state.findIndex(f => f.path === file.path);
|
|
|
|
|
|
|
|
export const setPageTitle = (title) => {
|
|
|
|
document.title = title;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const pushState = (url) => {
|
|
|
|
history.pushState({ url }, '', url);
|
|
|
|
};
|
2017-10-26 10:12:34 -04:00
|
|
|
|
2017-10-31 08:13:29 -04:00
|
|
|
export const createTemp = ({ name, path, type, level, changed, content, base64 }) => {
|
2017-10-26 10:12:34 -04:00
|
|
|
const treePath = path ? `${path}/${name}` : name;
|
|
|
|
|
|
|
|
return decorateData({
|
|
|
|
id: new Date().getTime().toString(),
|
|
|
|
name,
|
|
|
|
type,
|
|
|
|
tempFile: true,
|
|
|
|
path: treePath,
|
|
|
|
icon: type === 'tree' ? 'folder' : 'file-text-o',
|
|
|
|
changed,
|
|
|
|
content,
|
|
|
|
parentTreeUrl: '',
|
|
|
|
level,
|
2017-10-31 08:13:29 -04:00
|
|
|
base64,
|
|
|
|
renderError: base64,
|
2017-10-26 10:12:34 -04:00
|
|
|
});
|
|
|
|
};
|
2017-11-02 12:07:01 -04:00
|
|
|
|
|
|
|
export const createOrMergeEntry = ({ tree, entry, type, parentTreeUrl, level }) => {
|
|
|
|
const found = findEntry(tree, type, entry.name);
|
|
|
|
|
|
|
|
if (found) {
|
|
|
|
return Object.assign({}, found, {
|
|
|
|
id: entry.id,
|
|
|
|
url: entry.url,
|
|
|
|
tempFile: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return decorateData({
|
|
|
|
...entry,
|
|
|
|
type,
|
|
|
|
parentTreeUrl,
|
|
|
|
level,
|
|
|
|
});
|
|
|
|
};
|