Compare commits
2 Commits
d22dbd7629
...
ba9713e3eb
Author | SHA1 | Date | |
---|---|---|---|
ba9713e3eb | |||
c25a2c5fe2 |
BIN
.nova/Artwork
BIN
.nova/Artwork
Binary file not shown.
Before Width: | Height: | Size: 11 KiB |
@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"workspace.art_style" : 1,
|
|
||||||
"workspace.color" : 10,
|
|
||||||
"workspace.name" : "Treadl"
|
|
||||||
}
|
|
@ -10,6 +10,8 @@ export default {
|
|||||||
UPDATE_EDITOR: 'UPDATE_EDITOR',
|
UPDATE_EDITOR: 'UPDATE_EDITOR',
|
||||||
RECEIVE_SNIPPET: 'RECEIVE_SNIPPET',
|
RECEIVE_SNIPPET: 'RECEIVE_SNIPPET',
|
||||||
DELETE_SNIPPET: 'DELETE_SNIPPET',
|
DELETE_SNIPPET: 'DELETE_SNIPPET',
|
||||||
|
RECEIVE_SNAPSHOT: 'RECEIVE_SNAPSHOT',
|
||||||
|
TRAVERSE_SNAPSHOTS: 'TRAVERSE_SNAPSHOTS',
|
||||||
RECEIVE_COMMENT: 'RECEIVE_COMMENT',
|
RECEIVE_COMMENT: 'RECEIVE_COMMENT',
|
||||||
DELETE_COMMENT: 'DELETE_COMMENT',
|
DELETE_COMMENT: 'DELETE_COMMENT',
|
||||||
|
|
||||||
@ -55,6 +57,14 @@ export default {
|
|||||||
return { type: this.DELETE_SNIPPET, snippetId };
|
return { type: this.DELETE_SNIPPET, snippetId };
|
||||||
},
|
},
|
||||||
|
|
||||||
|
receiveSnapshot(snapshot) {
|
||||||
|
return { type: this.RECEIVE_SNAPSHOT, snapshot };
|
||||||
|
},
|
||||||
|
|
||||||
|
traverseSnapshots(direction) {
|
||||||
|
return { type: this.TRAVERSE_SNAPSHOTS, direction };
|
||||||
|
},
|
||||||
|
|
||||||
receiveComment(comment) {
|
receiveComment(comment) {
|
||||||
return { type: this.RECEIVE_COMMENT, comment };
|
return { type: this.RECEIVE_COMMENT, comment };
|
||||||
},
|
},
|
||||||
|
@ -5,6 +5,7 @@ import { useSelector, useDispatch } from 'react-redux';
|
|||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
import { useBlocker } from 'react-router';
|
import { useBlocker } from 'react-router';
|
||||||
import { toast } from 'react-toastify';
|
import { toast } from 'react-toastify';
|
||||||
|
import { useDebouncedCallback } from 'use-debounce';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import Tour from '../../../includes/Tour';
|
import Tour from '../../../includes/Tour';
|
||||||
import ElementPan from '../../../includes/ElementPan';
|
import ElementPan from '../../../includes/ElementPan';
|
||||||
@ -43,6 +44,8 @@ function Draft() {
|
|||||||
dispatch(actions.objects.receive(o));
|
dispatch(actions.objects.receive(o));
|
||||||
setObject(o);
|
setObject(o);
|
||||||
setPattern(o.pattern);
|
setPattern(o.pattern);
|
||||||
|
console.log('GETTING OBJECT', createSnapshot);
|
||||||
|
setTimeout(() => createSnapshot(o.pattern), 1000);
|
||||||
});
|
});
|
||||||
}, [objectId]);
|
}, [objectId]);
|
||||||
|
|
||||||
@ -51,15 +54,28 @@ function Draft() {
|
|||||||
currentLocation.pathname !== nextLocation.pathname
|
currentLocation.pathname !== nextLocation.pathname
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const createSnapshot = (snapshotPattern) => {
|
||||||
|
const snapshot = Object.assign({}, snapshotPattern);
|
||||||
|
snapshot.objectId = objectId;
|
||||||
|
snapshot.warp = Object.assign({}, snapshotPattern.warp);
|
||||||
|
snapshot.weft = Object.assign({}, snapshotPattern.weft);
|
||||||
|
snapshot.tieups = Object.assign({}, snapshotPattern.tieups);
|
||||||
|
dispatch(actions.objects.receiveSnapshot(snapshot));
|
||||||
|
console.log('CREATING SNAPSHOT');
|
||||||
|
};
|
||||||
|
const debouncedSnapshot = useDebouncedCallback(createSnapshot, 2000);
|
||||||
|
|
||||||
const updateObject = (update) => {
|
const updateObject = (update) => {
|
||||||
setObject(Object.assign({}, object, update));
|
setObject(Object.assign({}, object, update));
|
||||||
setUnsaved(true);
|
setUnsaved(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const updatePattern = (update) => {
|
const updatePattern = (update, withoutSnapshot = false) => {
|
||||||
const newPattern = Object.assign({}, pattern, update);
|
const newPattern = Object.assign({}, pattern, update);
|
||||||
setPattern(Object.assign({}, pattern, newPattern));
|
//setPattern(Object.assign({}, pattern, newPattern));
|
||||||
|
setPattern(newPattern);
|
||||||
setUnsaved(true);
|
setUnsaved(true);
|
||||||
|
if (!withoutSnapshot) debouncedSnapshot(newPattern);
|
||||||
};
|
};
|
||||||
|
|
||||||
const saveObject = () => {
|
const saveObject = () => {
|
||||||
|
@ -63,13 +63,15 @@ function Tools({ object, pattern, warp, weft, unsaved, saving, baseSize, updateP
|
|||||||
const { objectId, username, projectPath } = useParams();
|
const { objectId, username, projectPath } = useParams();
|
||||||
const { colours } = pattern;
|
const { colours } = pattern;
|
||||||
|
|
||||||
const { user, project, editor } = useSelector(state => {
|
const { user, project, editor, snapshots, currentSnapshotIndex } = useSelector(state => {
|
||||||
const user = state.users.users.filter(u => state.auth.currentUserId === u._id)[0];
|
const user = state.users.users.filter(u => state.auth.currentUserId === u._id)[0];
|
||||||
let project = {};
|
let project = {};
|
||||||
state.projects.projects.forEach((p) => {
|
state.projects.projects.forEach((p) => {
|
||||||
if (p.path === projectPath && p.owner && p.owner.username === username) project = p;
|
if (p.path === projectPath && p.owner && p.owner.username === username) project = p;
|
||||||
});
|
});
|
||||||
return { user, project, editor: state.objects.editor };
|
const snapshots = state.objects.snapshots.filter(s => s.objectId === objectId);
|
||||||
|
const currentSnapshotIndex = state.objects.currentSnapshotIndex;
|
||||||
|
return { user, project, editor: state.objects.editor, snapshots, currentSnapshotIndex };
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -85,6 +87,22 @@ function Tools({ object, pattern, warp, weft, unsaved, saving, baseSize, updateP
|
|||||||
if (colours?.length && !editor.colour) setColour(colours[colours.length - 1]);
|
if (colours?.length && !editor.colour) setColour(colours[colours.length - 1]);
|
||||||
}, [colours]);
|
}, [colours]);
|
||||||
|
|
||||||
|
const undo = () => {
|
||||||
|
const snapshot = snapshots[currentSnapshotIndex + 1];
|
||||||
|
console.log(snapshot);
|
||||||
|
console.log(currentSnapshotIndex);
|
||||||
|
if (!snapshot) return;
|
||||||
|
const newWarp = Object.assign({}, snapshot.warp);
|
||||||
|
const newWeft = Object.assign({}, snapshot.weft);
|
||||||
|
//if (snapshot.warp.threading) newWarp.threading = snapshot.warp.threading;
|
||||||
|
//if (snapshot.weft.treadling) newWeft.treadling = snapshot.weft.treadling;
|
||||||
|
updatePattern({ warp: newWarp, weft: newWeft }, true);
|
||||||
|
dispatch(actions.objects.traverseSnapshots(-1));
|
||||||
|
};
|
||||||
|
const redo = () => {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
const enableTool = (tool) => {
|
const enableTool = (tool) => {
|
||||||
dispatch(actions.objects.updateEditor({ tool, colour: editor.colour }));
|
dispatch(actions.objects.updateEditor({ tool, colour: editor.colour }));
|
||||||
};
|
};
|
||||||
@ -247,6 +265,12 @@ function Tools({ object, pattern, warp, weft, unsaved, saving, baseSize, updateP
|
|||||||
</div>
|
</div>
|
||||||
:
|
:
|
||||||
<div style={{display: 'flex', alignItems: 'end'}}>
|
<div style={{display: 'flex', alignItems: 'end'}}>
|
||||||
|
<div style={{marginRight: 10}}>
|
||||||
|
<Button.Group size="tiny">
|
||||||
|
<Button disabled={snapshots?.length < 2} data-tooltip="Undo" size="tiny" icon onClick={undo}><Icon name="undo" /></Button>
|
||||||
|
<Button disabled={!currentSnapshotIndex} data-tooltip="Redo" size="tiny" icon onClick={redo}><Icon name="redo" /></Button>
|
||||||
|
</Button.Group>
|
||||||
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<ToolLabel>View</ToolLabel>
|
<ToolLabel>View</ToolLabel>
|
||||||
<Popup hoverable on='click'
|
<Popup hoverable on='click'
|
||||||
|
@ -9,6 +9,8 @@ const initialState = {
|
|||||||
selected: null,
|
selected: null,
|
||||||
editor: { tool: 'straight', colour: null, view: 'interlacement', autoExtend: true },
|
editor: { tool: 'straight', colour: null, view: 'interlacement', autoExtend: true },
|
||||||
snippets: [],
|
snippets: [],
|
||||||
|
snapshots: [],
|
||||||
|
currentSnapshotIndex: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
function objects(state = initialState, action) {
|
function objects(state = initialState, action) {
|
||||||
@ -94,6 +96,16 @@ function objects(state = initialState, action) {
|
|||||||
return Object.assign({}, state, { snippets: state.snippets.filter(e => e._id !== action.snippetId) });
|
return Object.assign({}, state, { snippets: state.snippets.filter(e => e._id !== action.snippetId) });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case actions.objects.RECEIVE_SNAPSHOT: {
|
||||||
|
const snapshots = Object.assign([], state.snapshots);
|
||||||
|
snapshots.splice(0, 0, action.snapshot);
|
||||||
|
return Object.assign({}, state, { snapshots, currentSnapshotIndex: 0});
|
||||||
|
}
|
||||||
|
case actions.objects.TRAVERSE_SNAPSHOTS: {
|
||||||
|
const currentSnapshotIndex = state.currentSnapshotIndex + action.direction;
|
||||||
|
return Object.assign({}, state, { currentSnapshotIndex });
|
||||||
|
}
|
||||||
|
|
||||||
case actions.objects.RECEIVE_COMMENT: {
|
case actions.objects.RECEIVE_COMMENT: {
|
||||||
let found = false;
|
let found = false;
|
||||||
const comments = state.comments.map(e => {
|
const comments = state.comments.map(e => {
|
||||||
|
Loading…
Reference in New Issue
Block a user