Skip to content

Commit

Permalink
routing is working
Browse files Browse the repository at this point in the history
  • Loading branch information
excitement-engineer committed May 20, 2017
1 parent 19e1ff4 commit 512e15a
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 70 deletions.
74 changes: 55 additions & 19 deletions components/router.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@

//@flow


import React from "react";

//$FlowFixMe
import { AppRegistry, asset, Pano, Text, View, VrButton, Image } from "react-vr";
import {
AppRegistry,
asset,
Pano,
Text,
View,
VrButton,
Image
// $FlowFixMe
} from "react-vr";

import Home from "./menu";
import Detail from "./detail"

import Detail from "./detail";
import SpeakerList from "./speakerList";
import { type Speaker } from "../query";

type Route = "HOME" | "DETAIL";

type State = {
route: Route
state:
| {
route: "HOME"
}
| {
route: "DETAIL",
speaker: Speaker
}
};

export default class Router extends React.Component {
Expand All @@ -24,26 +38,48 @@ export default class Router extends React.Component {
constructor() {
super();
this.state = {
route: "HOME"
state: {
route: "HOME"
}
};
}

render() {
let content;
switch(this.state.route) {
const { state } = this.state;

switch (state.route) {
case "HOME":
content = <Home setRoute={(route: Route) => {
this.setState({route});
}}/>
break;
content = (
<SpeakerList
onSpeakerSelection={speaker => {
this.setState({
state: {
route: "DETAIL",
speaker
}
});
}}
/>
);
break;
case "DETAIL":
content = <Detail description="This is a monkey in a box. Hello There!" backPressed={() => {
this.setState({route: "HOME"});
}}/>
break;
content = (
<Detail
description={state.speaker.talks[0].description}
backPressed={() => {
this.setState({
state: {
route: "HOME"
}
});
}}
/>
);
break;
default:
throw new Error("No Route");
}
throw new Error("No Route");
}

return content;
}
Expand Down
37 changes: 37 additions & 0 deletions components/speaker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// @flow

import React from "react";
//$FlowFixMe
import { Image, Text, View, VrButton } from "react-vr";

type Props = {
profileUrl?: string,
text: string,
onLook: () => void,
onClick: () => void
};

const defaultURL = "https://facebook.github.io/react/img/logo_og.png";

export default (props: Props) => {
const url = props.profileUrl ? props.profileUrl : defaultURL;
return (
<View onEnter={props.onLook}>
<VrButton
onClick={props.onClick}
>
<Image source={{ uri: url }} style={{ width: 1, height: 1 }}>
<Text
style={{
margin: "5",
textAlign: "center",
fontWeight: "600"
}}
>
{props.text}
</Text>
</Image>
</VrButton>
</View>
);
};
33 changes: 16 additions & 17 deletions speakerList.js → components/speakerList.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
// @flow

import React from "react";
//$FlowFixMe
import { AppRegistry, asset, Pano, Text, View } from "react-vr";
import Speaker from "./speaker";

import API, { type APIResult } from "./query";
import API, { type Speaker as SpeakerType } from "../query";

export default class VRTextReader extends React.Component {

state: {
offset: number,
data: ?APIResult
}
data: ?Array<SpeakerType>
};

async componentDidMount(): any {
const data = await API();

this.setState({
data
})
});
}

constructor() {
Expand All @@ -27,31 +27,27 @@ export default class VRTextReader extends React.Component {
this.state = {
offset: 0,
data: null
}
};
}

render() {

let contentAmount = thursdaySections.length;

let selectedSpeakerIndex = (contentAmount/2) - this.state.offset;

if (!this.state.data) {
return null;
}

let contentAmount = this.state.data.length;
let selectedSpeakerIndex = contentAmount / 2 - this.state.offset;

const content = this.state.data.map((el, index) => {
let profileUrl = el.avatarUrl;
let text = el.talks[0].title;

let delta;
if (index < selectedSpeakerIndex) {
if (index < selectedSpeakerIndex - 2) {
delta = -1;
}
else if (index > selectedSpeakerIndex) {
} else if (index > selectedSpeakerIndex + 2) {
delta = 1;
}
else {
} else {
delta = 0;
}

Expand All @@ -61,7 +57,10 @@ export default class VRTextReader extends React.Component {
onLook: () => {
this.setState({
offset: this.state.offset - delta
})
});
},
onClick: () => {
this.props.onSpeakerSelection(el)
}
};
});
Expand Down
10 changes: 7 additions & 3 deletions query.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const query = `
}
}`;

export type APIResult = Array<{
export type Speaker = {
avatarUrl: string,
bio: string,
name: string,
Expand All @@ -29,9 +29,13 @@ export type APIResult = Array<{
startDate: string,
title: string
}>
}>
};

export default (): Promise<APIResult> => {

//export type APIResult = Array<Speaker>


export default (): Promise<Array<Speaker>> => {
return fetch("https://www.react-europe.org/gql", {
method: "POST",
body: JSON.stringify({
Expand Down
31 changes: 0 additions & 31 deletions speaker.js

This file was deleted.

0 comments on commit 512e15a

Please sign in to comment.