Gisle Aune
6 years ago
8 changed files with 134 additions and 2 deletions
-
BINrpdata-graphiql
-
2rpdata-ui/src/App.js
-
4rpdata-ui/src/common/Menu.js
-
6rpdata-ui/src/common/css/Menu.css
-
51rpdata-ui/src/routes/story-content/StoryContentMenu.js
-
44rpdata-ui/src/routes/story-content/StoryContentRoot.js
-
28rpdata-ui/src/routes/story-content/gql/StoryContentRoot.js
-
1rpdata-ui/src/routes/story/StoryRoot.js
@ -0,0 +1,51 @@ |
|||
import React, { Component } from "react" |
|||
import moment from "moment" |
|||
|
|||
import Menu, { MenuHeader, MenuLink, MenuGap } from '../../common/Menu' |
|||
|
|||
export default class StoryContentMenu extends Component { |
|||
render() { |
|||
const { story } = this.props |
|||
|
|||
console.log(story.tags) |
|||
|
|||
return ( |
|||
<Menu> |
|||
<MenuHeader>Chapters</MenuHeader> |
|||
<ChapterMenu storyId={story.id} chapters={story.chapters} /> |
|||
<MenuGap /> |
|||
<MenuHeader>Tags</MenuHeader> |
|||
<TagMenu tags={story.tags} /> |
|||
<MenuGap /> |
|||
<MenuHeader>Story</MenuHeader> |
|||
<MonthMenuItem date={story.fictionalDate} /> |
|||
<MenuLink to={`/story/author/${story.author}`} icon="A">{story.author}</MenuLink> |
|||
<MenuGap /> |
|||
</Menu> |
|||
) |
|||
} |
|||
} |
|||
|
|||
function ChapterMenu({chapters, storyId}) { |
|||
return chapters.map((chapter, index) => ( |
|||
<MenuLink to={`/story/${storyId}/${chapter.id}`} icon={index + 1}>{chapter.title}</MenuLink> |
|||
)) |
|||
} |
|||
|
|||
function TagMenu({tags}) { |
|||
return tags.map(tag => ( |
|||
<MenuLink tagKind={tag.kind} to={`/story/tag/${tag.kind}/${tag.name}`} icon={tag.kind.charAt(0)}>{tag.name}</MenuLink> |
|||
)) |
|||
} |
|||
|
|||
function MonthMenuItem({date}) { |
|||
const fictionalDate = moment.utc(date) |
|||
if (fictionalDate.year() < 100) { |
|||
return null |
|||
} |
|||
|
|||
const monthKey = fictionalDate.format("YYYY-MM") |
|||
const monthText = fictionalDate.format("MMM D, YYYY") |
|||
|
|||
return <MenuLink to={`/story/month/${monthKey}`} icon="D">{monthText}</MenuLink> |
|||
} |
@ -0,0 +1,44 @@ |
|||
import React, { Component } from "react" |
|||
import { Route, Switch, Redirect } from "react-router-dom"; |
|||
import { Query } from "react-apollo" |
|||
|
|||
import Background from "../../common/Background" |
|||
import { LoadingScreen } from "../../common/LoadingScreen" |
|||
import StoryContentMenu from "./StoryContentMenu" |
|||
|
|||
import storyContentRoot from "./gql/StoryContentRoot"; |
|||
|
|||
class StoryContentRoot extends Component { |
|||
render() { |
|||
const story = this.props.story |
|||
|
|||
const chapterRedirect = story.chapters.length > 0 ? ( |
|||
<Redirect exact from={`/story/${story.id}/`} to={`/story/${story.id}/${story.chapters[0].id}`} /> |
|||
) : null |
|||
|
|||
return ( |
|||
<div className="StoryContentRoot theme-story"> |
|||
<Background /> |
|||
<StoryContentMenu story={this.props.story} /> |
|||
<Switch> |
|||
{chapterRedirect} |
|||
</Switch> |
|||
</div> |
|||
) |
|||
} |
|||
} |
|||
|
|||
export default ({id, match}) => ( |
|||
<Query query={storyContentRoot} variables={{id: id || match.params.id}}> |
|||
{({ loading, error, data }) => { |
|||
if (loading) { |
|||
return <LoadingScreen className="theme-story" /> |
|||
} |
|||
if (error) { |
|||
return `Error! ${error.message}` |
|||
} |
|||
|
|||
return <StoryContentRoot {...data} /> |
|||
}} |
|||
</Query> |
|||
) |
@ -0,0 +1,28 @@ |
|||
import gql from "graphql-tag" |
|||
|
|||
export default gql`
|
|||
query StoryContentRoot($id: String!) { |
|||
story(id: $id) { |
|||
id |
|||
name |
|||
author |
|||
category |
|||
createdDate |
|||
fictionalDate |
|||
updatedDate |
|||
tags { |
|||
kind |
|||
name |
|||
} |
|||
chapters { |
|||
id |
|||
title |
|||
author |
|||
source |
|||
createdDate |
|||
fictionalDate |
|||
editedDate |
|||
} |
|||
} |
|||
} |
|||
`
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue