Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/commas #20

Open
wants to merge 6 commits into
base: fix/jest-warnings
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions front/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
"sourceType": "module"
},
"rules": {
"arrow-spacing": "error",
"brace-style": "error",
"comma-dangle": ["error", "always-multiline"],
"comma-spacing": ["error", { "before": false, "after": true }],
"indent": ["error", 2],
"keyword-spacing": ["error"],
"line-comment-position": ["error", { "position": "above" }],
"no-unused-vars": ["error", { "argsIgnorePattern": "_" }],
"react/prop-types": "off"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React from 'react'
// mapDispatchToProps :: (Action * -> State) -> Props
const mapDispatchToProps = dispatch => ({
loadAllPlayers: map(
compose(dispatch, loadPlayer)
compose(dispatch, loadPlayer),
),
})

Expand All @@ -20,7 +20,7 @@ const View = () => <span data-is="brightcove-players"/>

// lifecycles :: null -> React.Component
const lifecycles = compose(
componentDidMount(didMount)
componentDidMount(didMount),
)(View)

// BrightcovePlayer :: Props -> React.Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const mapDispatchToProps = (dispatch, props) => ({
closeInsertTweet: () => dispatch(closeInsertTweet(props.editorName)),
initialize: () => dispatch(initialize(props.editorName)),
openMediaPicker: (domain, extra, defaultOpenedComponent) => dispatch(
openMediaPicker(domain, extra, defaultOpenedComponent)
openMediaPicker(domain, extra, defaultOpenedComponent),
),
openInsertTweet: () => dispatch(openInsertTweet(props.editorName)),
openInsertYoutubeVideo: () => dispatch(openInsertYoutubeVideo(props.editorName)),
Expand Down
4 changes: 2 additions & 2 deletions front/src/Component/Container/TextEditor/TextToolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ const lifecycles = compose(

// TextToolbox :: Props -> React.Component
export default connect(
mapStateToProps,
mapDispatchToProps,
mapStateToProps,
mapDispatchToProps,
)(lifecycles)
2 changes: 1 addition & 1 deletion front/src/Component/Container/Tweet/Tweet.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { renderTweet } from '../../../Redux/State/Tweet'
// mapDispatchToProps :: Function -> Props
const mapDispatchToProps = dispatch => ({
renderTweet: (tweetId, uid, originalHtmlMarkup) => dispatch(
renderTweet(tweetId, uid, originalHtmlMarkup)
renderTweet(tweetId, uid, originalHtmlMarkup),
),
})

Expand Down
2 changes: 1 addition & 1 deletion front/src/Component/View/MediaPicker/ImagePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const renderImages = (images, pickImage, domain, extra) => images.map(image =>
src={image.href}
alt={image.legend}
/>
</div>
</div>,
)

export default ImagePicker;
2 changes: 1 addition & 1 deletion front/src/Component/View/MediaPicker/VideoPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const renderVideos = props => map(video =>
src={video.poster}
alt={video.name}
/>
</div>
</div>,
)

export default VideoPicker;
18 changes: 8 additions & 10 deletions front/src/Component/View/TextEditor/Widget.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import uniqid from 'uniqid'
import { cond, T, always, pipe } from 'ramda'
import { cond, T, always } from 'ramda'
import { indexedMap } from '../../../Util'
import TwitterWidget from '../../Container/Tweet/Tweet'
import BrightcoveVideo from '../../Container/BrightcovePlayer/BrightcoveVideo'
Expand All @@ -9,14 +9,12 @@ import BrightcoveVideo from '../../Container/BrightcovePlayer/BrightcoveVideo'
const is = type => ({ component }) => type === component.component

// renderChildren :: (String, [Children]) -> React.Component
const renderChildren = (parentId, children) => pipe(
indexedMap((child, index) =>
<Widget
component={child}
id={`${parentId}-${index}`}
key={`${parentId}-${index}`}
/>
)
const renderChildren = (parentId, children) => indexedMap((child, index) =>
<Widget
component={child}
id={`${parentId}-${index}`}
key={`${parentId}-${index}`}
/>,
)(children)

// Text :: Props -> React.Component
Expand Down Expand Up @@ -112,7 +110,7 @@ const YoutubeVideo = ({ component }) =>
// Heading :: Props -> React.Component
const Heading = ({ component, id }) => React.createElement(
`h${component.size}`,
[], // empty props set
[],
renderChildren(id, component.childComponents),
)

Expand Down
2 changes: 1 addition & 1 deletion front/src/Epic/BrightcovePlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const renderVideoEpic = (action$, state$, { window }) =>
map(([ video ]) => ({
video,
id: pathOr(null, ['dataset', 'videoId'], video),
originalHtmlMarkup: video.outerHTML
originalHtmlMarkup: video.outerHTML,
})),
tap(({ video }) => window['bc'](video)),
map(({ id, originalHtmlMarkup }) => videoRendered(id, originalHtmlMarkup)),
Expand Down
2 changes: 1 addition & 1 deletion front/src/Epic/MediaPicker/ImagePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const searchImagesEpic = (action$, _, { fetchApi }) =>
mergeMap(({ searchString }) => fetchImages(
fetchApi,
1,
searchString
searchString,
)),
map(pipe(
prop('photos'),
Expand Down
10 changes: 5 additions & 5 deletions front/src/Epic/MediaPicker/ImagePicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const imagesMock = [
{
id: 1,
src: {
medium: "href"
medium: "href",
},
photographer_url: "photographer url",
photographer: "photographer",
Expand All @@ -31,7 +31,7 @@ const transformedImages = [
href: "href",
legend: "photographer url",
credit: "photographer",
}
},
];
const dependencies = {
fetchApi: () => Promise.resolve({
Expand Down Expand Up @@ -75,7 +75,7 @@ describe('Epic :: MediaPicker :: ImagePicker :: changePageEpic', () => {
}, 1000);

it('dispatches receivedImages (after scrollRight action)', async () => {
const action = await changePageEpic(scrollRight$, state$, dependencies)
const action = await changePageEpic(scrollRight$, state$, dependencies)
.toPromise(Promise)
;

Expand All @@ -89,8 +89,8 @@ describe('Epic :: MediaPicker :: ImagePicker :: ensurePickedImageHasCreditsEpic'
MediaPicker: {
ImagePicker: {
images: [
{ id: 1, legend: 'This image has credit', credit: 'AFP' },
{ id: 2, legend: 'This one does not', credit: '' },
{ id: 1, legend: 'This image has credit', credit: 'AFP' },
{ id: 2, legend: 'This one does not', credit: '' },
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion front/src/Epic/MediaPicker/MediaPicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Epic :: ArticleEditor :: closeMediaPickerEpic', () => {
g: open(),
h: openInsertTweet(),
i: open(),
j: pickVideo()
j: pickVideo(),
});

expectObservable(
Expand Down
4 changes: 2 additions & 2 deletions front/src/Epic/MediaPicker/VideoPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
SCROLL_LEFT,
SCROLL_RIGHT,
fetchVideos,
videosReceived
videosReceived,
} from '../../Redux/State/MediaPicker/VideoPicker'
import { join, prop, compose, lte, length } from 'ramda'

Expand Down Expand Up @@ -37,7 +37,7 @@ export const searchVideosEpic = action$ => merge(
filter(compose(lte(3), length, prop('searchString'))),
debounceTime(250),
),
action$.pipe(ofType(SCROLL_LEFT, SCROLL_RIGHT))
action$.pipe(ofType(SCROLL_LEFT, SCROLL_RIGHT)),
).pipe(
map(fetchVideos),
)
Expand Down
23 changes: 10 additions & 13 deletions front/src/Epic/TextEditor/InsertTweet.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,16 @@ import { of, from } from 'rxjs'
*/
export const fetchEmbedTweetEpic = (action$, state$, { fetchApi }) => action$.pipe(
ofType(INSERT_TWEET),
mergeMap(action => from(
fetchApi(
`${process.env.REACT_APP_MOCK_SERVER_API_URL}/twitter?url=${action.url}`
)
).pipe(
map(response => embedTweetFetched(
action.editorName,
response.html,
action.url,
)),
catchError(() => of(error(action.editorName))),
)
),
mergeMap(action => from(fetchApi(
`${process.env.REACT_APP_MOCK_SERVER_API_URL}/twitter?url=${action.url}`,
)).pipe(
map(response => embedTweetFetched(
action.editorName,
response.html,
action.url,
)),
catchError(() => of(error(action.editorName))),
)),
)

// insertTweetEpic :: Epic -> Observable Action.TWEET_INSERTED Action.ERROR
Expand Down
28 changes: 11 additions & 17 deletions front/src/Epic/TextEditor/InsertYoutubeVideo.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ofType, combineEpics } from 'redux-observable'
import { logObservableError } from '../../Util'
import { map, withLatestFrom, mergeMap, catchError } from 'rxjs/operators'
import { compose, prop, nth, equals, length, ifElse, path } from 'ramda'
import { compose, prop, pipe, equals, ifElse, path } from 'ramda'
import { insertNewNodeAtIndex } from './TextEditor'
import { from, of } from 'rxjs'
import {
Expand All @@ -27,10 +27,10 @@ export const insertYoutubeVideoEpic = (action$, state$) => action$.pipe(
iframe,
state.TextEditor.ParagraphToolbox[action.editorName].targetNodeIndex,
action.editorName,
))
)),
).pipe(
map(() => youtubeVideoInserted(action.editorName)),
catchError(() => of(error(action.editorName)))
catchError(() => of(error(action.editorName))),
)),
logObservableError(),
)
Expand All @@ -52,20 +52,14 @@ export const closeInsertYoutubeVideoEpic = action$ => action$.pipe(
)

// validateYoutubeUrl :: String -> Promise String String
export const validateYoutubeUrl = url => {
const match = url.match(
/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/
);

// example : https://www.youtube.com/watch?v=jadxTFqyhRM
// nth(1, match) = https://www.youtube.com/watch?v=
// nth(2, match) = jadxTFqyhRM
return new Promise((resolve, reject) =>
match && compose(equals(11), length, nth(2))(match)
? resolve(`https://www.youtube.com/embed/${nth(2, match)}`)
: reject('The provided URL is not a valid youtube video.')
);
}
export const validateYoutubeUrl = pipe(
url => url.match(/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/),
// matches[2] = youtube video identifier
matches => new Promise((resolve, reject) => matches && matches[2].length === 11
? resolve(`https://www.youtube.com/embed/${matches[2]}`)
: reject('The provided URL is not a valid youtube video.'),
),
);

// createYoutubeIframe :: String -> Node.IFRAME
const createYoutubeIframe = url => {
Expand Down
6 changes: 3 additions & 3 deletions front/src/Epic/TextEditor/InsertYoutubeVideo.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
openInsertTweet,
} from '../../Redux/State/TextEditor/ParagraphToolbox'
import {
open as openMediapicker
open as openMediapicker,
} from '../../Redux/State/MediaPicker/MediaPicker'

beforeEach(() => {
Expand All @@ -29,7 +29,7 @@ beforeEach(() => {
`;
});

describe('Epic :: TextEditor :: InsertYoutubeVideo', () => {
describe('Epic :: TextEditor :: InsertYoutubeVideo', () => {
it('validate a youtube url : success', async () => {
const url = await validateYoutubeUrl('https://www.youtube.com/watch?v=jadxTFqyhRM');

Expand Down Expand Up @@ -60,7 +60,7 @@ describe('Epic :: TextEditor :: InsertYoutubeVideo :: insertYoutubeVideoEpic', (
TextEditor: {
ParagraphToolbox: {
'editor-name': {
targetNodeIndex: 1
targetNodeIndex: 1,
},
},
},
Expand Down
6 changes: 3 additions & 3 deletions front/src/Epic/TextEditor/PasteText.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const moveCarretAfterPastedTextEpic = (action$, state$, { window }) =>
selection => window.getSelection().collapse(selection.anchorNode, 1),
selection => window.getSelection().collapse(
selection.anchorNode,
selection.anchorNode.textContent.search(text) + text.length
selection.anchorNode.textContent.search(text) + text.length,
),
)(window.getSelection())),
ignoreElements(),
Expand Down Expand Up @@ -124,8 +124,8 @@ const pasteTextInExistingText = textToBePasted => pipe(
s.anchorNode.data.slice(0, s.anchorOffset),
textToBePasted,
s.anchorNode.data.slice(s.anchorOffset),
])
))
]),
)),
)

export default combineEpics(
Expand Down
Loading