33
44import { createElement } from "glamor/react" ; // eslint-disable-line
55/* @jsx createElement */
6- import Spinner from "react-svg-spinner" ;
7- import ManageScroll from "../components/ManageScroll" ;
86import React , { Placeholder } from "react" ;
97import { Router , Link } from "@reach/router" ;
10- import Component from "@reach/component-component" ;
8+ import Spinner from "react-svg-spinner" ;
9+ import Competitions from "./lib/Competitions" ;
10+ import ManageScroll from "./lib/ManageScroll" ;
11+ import { cache } from "./lib/cache" ;
12+
1113import {
12- fetchWorkouts ,
1314 fetchWorkout ,
1415 fetchExercises ,
1516 fetchNextWorkout ,
16- WorkoutsResource ,
17- WorkoutResource ,
18- ExercisesResource ,
19- NextWorkoutResource ,
20- network
21- } from "./utils" ;
22- import { cache } from "../cache" ;
23- let patience = 1 ;
24-
25- const link = {
26- display : "inline-block" ,
27- width : "200px" ,
28- height : "200px" ,
29- lineHeight : "200px" ,
30- background : "#f0f0f0" ,
31- textAlign : "center" ,
32- margin : "20px" ,
33- ":hover" : {
34- background : "#ddd"
35- } ,
36- position : "relative"
37- } ;
17+ WorkoutsResource
18+ } from "./lib/utils" ;
3819
39- const Home = ( ) => (
40- < div >
41- < h1 css = { { textAlign : "center" } } > Workout App!</ h1 >
42- < div
43- css = { {
44- display : "flex" ,
45- alignItems : "center" ,
46- justifyContent : "center"
47- } }
48- >
49- < Link to = "/workouts" css = { link } >
50- Workouts
51- </ Link >
52- < Link to = "/competitions" css = { link } >
53- Competitions
54- </ Link >
55- </ div >
56- </ div >
57- ) ;
58-
59- const Workouts = ( ) => {
60- const workouts = WorkoutsResource . read ( cache , 10 ) ;
61- return (
62- < div >
63- < Link to = ".." > Home</ Link >
64- < h1 > Workouts</ h1 >
65- { workouts . map ( workout => (
66- < Link key = { workout . id } to = { workout . id } css = { link } >
67- { workout . name }
68- </ Link >
69- ) ) }
70- </ div >
71- ) ;
72- } ;
73-
74- const Competitions = ( ) => < div > Competitions</ div > ;
75-
76- const LoadingSpinner = ( ) => (
77- < div css = { { textAlign : "center" , padding : 20 } } >
78- < Spinner size = "100" />
79- </ div >
80- ) ;
20+ let patience = 1 ;
8121
8222///////////////////////////////////////////////////
83-
8423class Workout extends React . Component {
8524 state = {
8625 workout : null ,
@@ -118,19 +57,13 @@ class Workout extends React.Component {
11857 }
11958
12059 render ( ) {
121- const { workoutId } = this . props ;
12260 const { workout, exercises, nextWorkout } = this . state ;
12361
12462 return workout ? (
12563 < div >
126- < Link to = "../.." > Home</ Link > /{ " " }
127- < Link to = ".." > Workouts</ Link >
64+ < Link to = "../.." > Home</ Link > / < Link to = ".." > Workouts</ Link >
12865 < h1 > { workout . name } </ h1 >
129- { exercises ? (
130- < Exercises exercises = { exercises } />
131- ) : (
132- < Spinner />
133- ) }
66+ { exercises ? < Exercises exercises = { exercises } /> : < Spinner /> }
13467 { workout . completed &&
13568 ( nextWorkout ? (
13669 < NextWorkout nextWorkout = { nextWorkout } />
@@ -146,35 +79,73 @@ class Workout extends React.Component {
14679 }
14780}
14881
149- const Exercises = ( { exercises } ) => {
82+ ////////////////////////////////////////////////////////////
83+ const link = {
84+ display : "inline-block" ,
85+ width : "200px" ,
86+ height : "200px" ,
87+ lineHeight : "200px" ,
88+ background : "#f0f0f0" ,
89+ textAlign : "center" ,
90+ margin : "20px" ,
91+ ":hover" : {
92+ background : "#ddd"
93+ } ,
94+ position : "relative"
95+ } ;
96+
97+ const Home = ( ) => (
98+ < div >
99+ < h1 css = { { textAlign : "center" } } > Workout App!</ h1 >
100+ < div
101+ css = { {
102+ display : "flex" ,
103+ alignItems : "center" ,
104+ justifyContent : "center"
105+ } }
106+ >
107+ < Link to = "/workouts" css = { link } >
108+ Workouts
109+ </ Link >
110+ < Link to = "/competitions" css = { link } >
111+ Competitions
112+ </ Link >
113+ </ div >
114+ </ div >
115+ ) ;
116+
117+ const Workouts = ( ) => {
118+ const workouts = WorkoutsResource . read ( cache , 10 ) ;
150119 return (
151- < ul >
152- { exercises . map ( ( exercise , i ) => (
153- < li key = { i } > { exercise } </ li >
120+ < div >
121+ < Link to = ".." > Home</ Link >
122+ < h1 > Workouts</ h1 >
123+ { workouts . map ( workout => (
124+ < Link key = { workout . id } to = { workout . id } css = { link } >
125+ { workout . name }
126+ </ Link >
154127 ) ) }
155- </ ul >
128+ </ div >
156129 ) ;
157130} ;
158131
132+ const Exercises = ( { exercises } ) => {
133+ return < ul > { exercises . map ( ( exercise , i ) => < li key = { i } > { exercise } </ li > ) } </ ul > ;
134+ } ;
135+
159136const NextWorkout = ( { nextWorkout } ) => {
160137 return (
161138 < div >
162139 < h2 >
163- Up Next!{ " " }
164- < Link to = { `../${ nextWorkout . id } ` } >
165- { nextWorkout . name }
166- </ Link >
140+ Up Next! < Link to = { `../${ nextWorkout . id } ` } > { nextWorkout . name } </ Link >
167141 </ h2 >
168142 </ div >
169143 ) ;
170144} ;
171145
172146const App = ( ) => {
173147 return (
174- < Placeholder
175- delayMs = { patience }
176- fallback = { < Spinner size = "100" /> }
177- >
148+ < Placeholder delayMs = { patience } fallback = { < Spinner size = "100" /> } >
178149 < ManageScroll />
179150 < Router style = { { padding : 20 } } >
180151 < Home path = "/" />
0 commit comments