Skip to content

Commit

Permalink
Merge pull request #5 from lopezh18/auto-download-rithm
Browse files Browse the repository at this point in the history
created auto-download feature #20
  • Loading branch information
misscoded authored Jun 21, 2019
2 parents 8e52f10 + 452b65e commit 8f075dd
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 79 deletions.
73 changes: 34 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"react-redux": "^6.0.0",
"react-scripts": "2.1.2",
"redux": "^4.0.1",
"redux-devtools-extension": "^2.13.8",
"redux-thunk": "^2.3.0"
},
"scripts": {
Expand Down
5 changes: 4 additions & 1 deletion src/actions/action-creators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,10 @@ describe('Action creators', () => {
return cb({ image: 'test' });
}
};
store.dispatch(actions.generateGIF([], opts, gifshot));
// download mock
const download = () => null;

store.dispatch(actions.generateGIF([], opts, gifshot, download));
expect(store.getActions()).toEqual(expectedActions);
});
});
Expand Down
15 changes: 10 additions & 5 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ import {
badSettingsInput,
badNameInput
} from '../lib/error-messages';
import download from 'downloadjs';
import {
getBurstErrors,
getSettingsErrors,
getSaveGraphErrors
} from '../lib/input-helpers';
import {} from '../lib/input-helpers';

const ERROR_DELAY = 3000;
let nextFrameID = 0;
Expand Down Expand Up @@ -231,12 +231,15 @@ export const startAnimation = () => (dispatch, getState) => {

// The gifshot library is loaded in index.html
const gifshot = window.gifshot;
export const generateGIF = (images, opts, gifMaker = gifshot) => (
dispatch,
getState
) => {
export const generateGIF = (
images,
opts,
gifMaker = gifshot,
downloadFn = download
) => (dispatch, getState) => {
// Have to check state interval and not opts because opts is in seconds
const { interval } = getState().settings.image;
const { gifFileName } = getState().images;
const settingsErrors = getSettingsErrors({ interval });
if (Object.keys(settingsErrors).length) {
dispatch(flashError(badSettingsInput(settingsErrors)));
Expand All @@ -248,11 +251,13 @@ export const generateGIF = (images, opts, gifMaker = gifshot) => (
...opts,
progressCallback: progress => dispatch(updateGIFProgress(progress))
};

gifMaker.createGIF(gifshotArgs, data => {
if (data.error) {
dispatch(flashError(gifCreationProblem()));
} else {
dispatch(addGIF(data.image));
downloadFn(data.image, gifFileName || 'gifsmos.gif', 'image/gif');
}
});
};
Expand Down
Loading

0 comments on commit 8f075dd

Please sign in to comment.