Skip to content

Commit

Permalink
Remove use of x-interaction, dispatch x-article-save-button custom ev…
Browse files Browse the repository at this point in the history
…ent directly on submit.
  • Loading branch information
dan-searle committed Nov 27, 2018
1 parent 9efd815 commit c9137ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 34 deletions.
1 change: 0 additions & 1 deletion components/x-article-save-button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
},
"dependencies": {
"@financial-times/x-engine": "file:../../packages/x-engine",
"@financial-times/x-interaction": "file:../x-interaction",
"classnames": "^2.2.6"
}
}
45 changes: 12 additions & 33 deletions components/x-article-save-button/src/ArticleSaveButton.jsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,8 @@
import { h } from '@financial-times/x-engine';
import { withActions } from '@financial-times/x-interaction';
import articleSaveStyles from './ArticleSaveButton.scss';
import classNames from 'classnames';

const articleSaveActions = withActions(initialProps => ({
triggerSave(rootElement) {
return currentProps => {
const detail = {
action: currentProps.saved ? 'remove' : 'add',
actorType: 'user',
actorId: null, // myft client sets to user id from session
relationshipName: 'saved',
subjectType: 'content',
subjectId: initialProps.contentId,
token: initialProps.csrfToken
};

rootElement.dispatchEvent(new CustomEvent('x-article-save-button', { bubbles: true, detail }));
};
},
saved() {
return { saved: true };
},
unsaved() {
return { saved: false };
}
}));

const BaseArticleSaveButton = props => {
export const ArticleSaveButton = props => {
const getLabel = props => {
if (props.saved) {
return 'Saved to myFT';
Expand All @@ -44,7 +19,17 @@ const BaseArticleSaveButton = props => {
data-content-id={props.contentId}
onSubmit={event => {
event.preventDefault();
props.actions.triggerSave(event.target);
const detail = {
action: props.saved ? 'remove' : 'add',
actorType: 'user',
actorId: null, // myft client sets to user id from session
relationshipName: 'saved',
subjectType: 'content',
subjectId: props.contentId,
token: props.csrfToken
};

event.target.dispatchEvent(new CustomEvent('x-article-save-button', { bubbles: true, detail }));
}}
>
{props.csrfToken && <input
Expand All @@ -65,9 +50,3 @@ const BaseArticleSaveButton = props => {
</form>
);
};

BaseArticleSaveButton.displayName = 'BaseArticleSaveButton';

const ArticleSaveButton = articleSaveActions(BaseArticleSaveButton);

export { ArticleSaveButton, articleSaveActions, BaseArticleSaveButton };

0 comments on commit c9137ae

Please sign in to comment.