-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(story): fetch story * feat(story): display story data in sidepanel * feat(story): add slides to sidepanel * refactor(story): remove unused import * style(app): remove trailing whitespace * fix(story): fix PR issues
- Loading branch information
1 parent
6093e98
commit 6cc8f3a
Showing
33 changed files
with
216 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import {Dispatch} from 'redux'; | ||
|
||
import fetchStoryApi from '../api/fetch-story'; | ||
import {languageSelector} from '../reducers/language'; | ||
import {State} from '../reducers/index'; | ||
|
||
import {Story} from '../types/story'; | ||
|
||
export const FETCH_STORY_SUCCESS = 'FETCH_STORY_SUCCESS'; | ||
export const FETCH_STORY_ERROR = 'FETCH_STORY_ERROR'; | ||
|
||
interface FetchStorySuccessAction { | ||
type: typeof FETCH_STORY_SUCCESS; | ||
story: Story; | ||
} | ||
|
||
interface FetchStoryErrorAction { | ||
type: typeof FETCH_STORY_ERROR; | ||
message: string; | ||
} | ||
|
||
export type FetchStoryActions = FetchStorySuccessAction | FetchStoryErrorAction; | ||
|
||
function fetchStorySuccessAction(story: Story) { | ||
return { | ||
type: FETCH_STORY_SUCCESS, | ||
story | ||
}; | ||
} | ||
|
||
function fetchStoryErrorAction(message: string) { | ||
return { | ||
type: FETCH_STORY_ERROR, | ||
message | ||
}; | ||
} | ||
|
||
const fetchStory = (id: string) => ( | ||
dispatch: Dispatch, | ||
getState: () => State | ||
) => { | ||
const language = languageSelector(getState()); | ||
|
||
return fetchStoryApi(id, language) | ||
.then(story => dispatch(fetchStorySuccessAction(story))) | ||
.catch(error => dispatch(fetchStoryErrorAction(error.message))); | ||
}; | ||
|
||
export default fetchStory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import config from '../config/main'; | ||
|
||
import {replaceUrlPlaceholders} from '../libs/replace-url-placeholders'; | ||
|
||
import {Language} from '../types/language'; | ||
|
||
export default function fetchStories(language: Language) { | ||
const url = `${config.api.stories}-${language.toLowerCase()}.json`; | ||
export default function fetchStories(lang: Language) { | ||
const url = replaceUrlPlaceholders(config.api.stories, {lang}); | ||
return fetch(url).then(res => res.json()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import config from '../config/main'; | ||
|
||
import {replaceUrlPlaceholders} from '../libs/replace-url-placeholders'; | ||
|
||
import {Language} from '../types/language'; | ||
|
||
export default function fetchStory(id: string, lang: Language) { | ||
const url = replaceUrlPlaceholders(config.api.story, {id, lang}); | ||
return fetch(url).then(res => res.json()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,45 @@ | ||
import React, {FunctionComponent} from 'react'; | ||
import React, {FunctionComponent, useEffect} from 'react'; | ||
import {useDispatch, useSelector} from 'react-redux'; | ||
import {useParams, Redirect} from 'react-router-dom'; | ||
|
||
import fetchStory from '../../actions/fetch-story'; | ||
import {storySelector} from '../../reducers/story'; | ||
|
||
import styles from './story.styl'; | ||
|
||
const Story: FunctionComponent = () => ( | ||
<div className={styles.story}> | ||
<div className={styles.sidepanel}> | ||
<div className={styles.previewImage}></div> | ||
<div className={styles.content}> | ||
<h1>Test</h1> | ||
<p> | ||
Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolor optio | ||
nisi nobis quas ut. Exercitationem, sapiente. Praesentium quidem | ||
mollitia explicabo voluptatem aperiam deleniti ut sunt atque eaque, | ||
voluptate commodi in. | ||
</p> | ||
</div> | ||
const Story: FunctionComponent = () => { | ||
const story = useSelector(storySelector); | ||
const dispatch = useDispatch(); | ||
const {storyId, page} = useParams(); | ||
const pageNumber = parseInt(page || '0', 10); | ||
const slide = story && story.slides[pageNumber]; | ||
const activeStoryId = story && story.id; | ||
|
||
useEffect(() => { | ||
storyId && dispatch(fetchStory(storyId)); | ||
}, [storyId, dispatch]); | ||
|
||
if (!slide) { | ||
return <Redirect to={`/stories/${storyId}/0`} />; | ||
} | ||
|
||
if (activeStoryId !== storyId) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className={styles.story}> | ||
{story && ( | ||
<div className={styles.sidepanel} key={slide.title}> | ||
<img src={slide.image} className={styles.previewImage} /> | ||
<div className={styles.content}> | ||
<h1>{slide.title}</h1> | ||
<p>{slide.bodytext}</p> | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
); | ||
}; | ||
|
||
export default Story; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {FETCH_STORY_SUCCESS, FetchStoryActions} from '../actions/fetch-story'; | ||
|
||
import {Story} from '../types/story'; | ||
import {State} from './index'; | ||
|
||
function storyReducer( | ||
storyState: Story | null = null, | ||
action: FetchStoryActions | ||
): Story | null { | ||
switch (action.type) { | ||
case FETCH_STORY_SUCCESS: | ||
return action.story; | ||
default: | ||
return storyState; | ||
} | ||
} | ||
|
||
export function storySelector(state: State): Story | null { | ||
return state.story; | ||
} | ||
|
||
export default storyReducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export interface StoryListItem { | ||
id: string; | ||
title: string; | ||
description: string; | ||
link: string; | ||
image: string; | ||
} | ||
|
||
export type StoryList = StoryListItem[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
export interface Story { | ||
id: string; | ||
slides: Slide[]; | ||
} | ||
|
||
interface Slide { | ||
title: string; | ||
description: string; | ||
link: string; | ||
subtitle: string; | ||
bodytext: string; | ||
image: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.