@@ -145,25 +145,40 @@ const NextWorkout = ({ workoutId }) => {
);
};
-const Competitions = () =>
Competitions
;
-
const LoadingSpinner = () => (
);
+const Network = () => (
+
+ Network: {network}
+
+);
+
const App = () => {
return (
- }>
-
-
-
-
-
-
-
-
+
+ }>
+
+
+
+
+
+
+
+
+
+
);
};
diff --git a/08-suspense/lecture/src/components/App.js b/08-suspense/lecture/src/components/App.js
deleted file mode 100644
index 7854e66..0000000
--- a/08-suspense/lecture/src/components/App.js
+++ /dev/null
@@ -1,70 +0,0 @@
-import React, { Placeholder, PureComponent, Fragment } from "react";
-import { unstable_deferredUpdates } from "react-dom";
-import { createResource } from "simple-cache-provider";
-import { cache } from "../cache";
-import Spinner from "./Spinner";
-import ContributorListPage from "./ContributorListPage";
-import { Router, Link, Location } from "@reach/router";
-import ManageScroll from "./ManageScroll";
-
-const UserPageResource = createResource(() => import("./UserPage"));
-
-function UserPageLoader(props) {
- const UserPage = UserPageResource.read(cache).default;
- return ;
-}
-
-class App extends PureComponent {
- state = {
- loadingId: null
- };
-
- handleUserClick = id => {
- this.setState({ loadingId: id });
- };
-
- render() {
- const { loadingId } = this.state;
- return (
- }>
-
-
- );
- }
-}
-
-class Detail extends PureComponent {
- render() {
- const { id } = this.props;
- return (
-
-
- Return to list
-
-
}>
-
-
-
- );
- }
-}
-
-export default () => (
-
-
-
-
-
-
-
-);
diff --git a/08-suspense/lecture/src/components/ContributorListPage.js b/08-suspense/lecture/src/components/ContributorListPage.js
deleted file mode 100644
index 3da8844..0000000
--- a/08-suspense/lecture/src/components/ContributorListPage.js
+++ /dev/null
@@ -1,74 +0,0 @@
-import React, { Fragment } from "react";
-import { createResource } from "simple-cache-provider";
-import { cache } from "../cache";
-import Spinner from "./Spinner";
-import { fetchCoreContributorListJSON } from "../api";
-import { Link } from "@reach/router";
-
-const ContributorListResource = createResource(fetchCoreContributorListJSON);
-
-const ContributorListPage = ({ loadingId, onUserClick }) => (
-
- React Core Team
-
- {ContributorListResource.read(cache).map(user => (
- onUserClick(user.id)}
- isLoading={loadingId && user.id === loadingId}
- user={user}
- />
- ))}
-
-
-);
-
-const ContributorListItem = ({ isLoading, onClick, user }) => (
-
-
-
-
{user.name}
-
{user.id}
-
- {isLoading ? (
-
- ) : (
-
- )}
-
-
-);
-
-export default ContributorListPage;
diff --git a/08-suspense/lecture/src/components/Spinner.css b/08-suspense/lecture/src/components/Spinner.css
deleted file mode 100644
index 552c85b..0000000
--- a/08-suspense/lecture/src/components/Spinner.css
+++ /dev/null
@@ -1,75 +0,0 @@
-.Spinner {
- animation: rotate 1.3s linear infinite;
-}
-
-.SpinnerContainer-large {
- position: fixed;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
-}
-
-@keyframes rotate {
- 0% { transform: rotate(0deg); }
- 100% { transform: rotate(270deg); }
-}
-
-.SmallSpinnerPath {
- stroke-dasharray: 100;
- stroke-dashoffset: 0;
- transform-origin: center;
- animation:
- SmallDash 1.3s ease-in-out infinite;
-}
-
-@keyframes SmallDash {
- 0% { stroke-dashoffset: 100; }
- 50% {
- stroke-dashoffset: 50;
- transform:rotate(135deg);
- }
- 100% {
- stroke-dashoffset: 100;
- transform:rotate(450deg);
- }
-}
-
-.MediumSpinnerPath {
- stroke-dasharray: 150;
- stroke-dashoffset: 0;
- transform-origin: center;
- animation:
- MediumDash 1.3s ease-in-out infinite;
-}
-
-@keyframes MediumDash {
- 0% { stroke-dashoffset: 150; }
- 50% {
- stroke-dashoffset: 50;
- transform:rotate(135deg);
- }
- 100% {
- stroke-dashoffset: 150;
- transform:rotate(450deg);
- }
-}
-
-.LargeSpinnerPath {
- stroke-dasharray: 200;
- stroke-dashoffset: 0;
- transform-origin: center;
- animation:
- LargeDash 1.3s ease-in-out infinite;
-}
-
-@keyframes LargeDash {
- 0% { stroke-dashoffset: 200; }
- 50% {
- stroke-dashoffset: 50;
- transform:rotate(135deg);
- }
- 100% {
- stroke-dashoffset: 200;
- transform:rotate(450deg);
- }
-}
diff --git a/08-suspense/lecture/src/components/Spinner.js b/08-suspense/lecture/src/components/Spinner.js
deleted file mode 100644
index 8ea7251..0000000
--- a/08-suspense/lecture/src/components/Spinner.js
+++ /dev/null
@@ -1,51 +0,0 @@
-import React from 'react';
-import './Spinner.css';
-
-const SPINNER_SIZES = {
- small: 30,
- medium: 50,
- large: 70,
-};
-
-const STROKE_WIDTHS = {
- small: 4,
- medium: 5,
- large: 6,
-};
-
-const PATH_CLASS_NAMES = {
- small: 'SmallSpinnerPath',
- medium: 'MediumSpinnerPath',
- large: 'LargeSpinnerPath',
-};
-
-// Heavily inspired by https://codepen.io/mrrocks/pen/EiplA
-export default function Spinner({size = 'small'}) {
- const baseSize = SPINNER_SIZES[size];
- const pathSize = baseSize / 2;
- const strokeWidth = STROKE_WIDTHS[size];
- const pathRadius = `${baseSize / 2 - strokeWidth}px`;
- const className = PATH_CLASS_NAMES[size];
- const containerClassName = `SpinnerContainer SpinnerContainer-${size}`;
-
- return (
-
-
-
- );
-}
diff --git a/08-suspense/lecture/src/components/UserPage.js b/08-suspense/lecture/src/components/UserPage.js
deleted file mode 100644
index a1b96de..0000000
--- a/08-suspense/lecture/src/components/UserPage.js
+++ /dev/null
@@ -1,169 +0,0 @@
-import React, {Placeholder} from 'react';
-import {createResource} from 'simple-cache-provider';
-import Spinner from './Spinner';
-import {cache} from '../cache';
-import {fetchUserProfileJSON, fetchUserRepositoriesListJSON} from '../api';
-
-export default function UserPage({id}) {
- return (
-
- );
-}
-
-const UserDetailsResource = createResource(fetchUserProfileJSON);
-
-function UserDetails({id}) {
- const user = UserDetailsResource.read(cache, id);
- return (
-
-
-
- {user.name}
-
-
{user.id}
- {user.tagline !== null &&
{user.tagline}
}
-
- {user.location &&
}
- {user.email &&
}
-
- );
-}
-
-const Location = ({location}) => (
-
-);
-
-const Email = ({email}) => (
-
-);
-
-const ImageResource = createResource(
- src =>
- new Promise(resolve => {
- const img = new Image();
- img.onload = () => resolve(src);
- img.src = src;
- })
-);
-
-function Img({src, alt, ...rest}) {
- return
;
-}
-
-function UserPicture({source}) {
- return (
-
}>
-
-
- );
-}
-
-const UserRepositoriesResource = createResource(fetchUserRepositoriesListJSON);
-
-function Repositories({id}) {
- const repos = UserRepositoriesResource.read(cache, id);
- return (
-
- {repos.map(repo => )}
-
- );
-}
-
-function Repository({description, name, url}) {
- return (
-
-
- {name}
-
- {description}
-
- );
-}
diff --git a/08-suspense/lecture/src/favicon.ico b/08-suspense/lecture/src/favicon.ico
deleted file mode 100644
index d392c1d..0000000
Binary files a/08-suspense/lecture/src/favicon.ico and /dev/null differ
diff --git a/08-suspense/lecture/src/index.js b/08-suspense/lecture/src/index.js
index 371346d..2f3ead7 100644
--- a/08-suspense/lecture/src/index.js
+++ b/08-suspense/lecture/src/index.js
@@ -1,8 +1,6 @@
-import "./index.css";
+import "./lib/index.css";
import React from "react";
import { unstable_createRoot } from "react-dom";
-// import App from "./components/App";
-// import App from "./workouts/App";
-import App from "./workouts/Refactor";
+import App from "./App";
unstable_createRoot(document.getElementById("root")).render(
);
diff --git a/08-suspense/lecture/src/workouts/Competitions.js b/08-suspense/lecture/src/lib/Competitions.js
similarity index 100%
rename from 08-suspense/lecture/src/workouts/Competitions.js
rename to 08-suspense/lecture/src/lib/Competitions.js
diff --git a/08-suspense/lecture/src/components/ManageScroll.js b/08-suspense/lecture/src/lib/ManageScroll.js
similarity index 100%
rename from 08-suspense/lecture/src/components/ManageScroll.js
rename to 08-suspense/lecture/src/lib/ManageScroll.js
diff --git a/08-suspense/lecture/src/cache.js b/08-suspense/lecture/src/lib/cache.js
similarity index 100%
rename from 08-suspense/lecture/src/cache.js
rename to 08-suspense/lecture/src/lib/cache.js
diff --git a/08-suspense/lecture/src/index.css b/08-suspense/lecture/src/lib/index.css
similarity index 100%
rename from 08-suspense/lecture/src/index.css
rename to 08-suspense/lecture/src/lib/index.css
diff --git a/08-suspense/lecture/src/workouts/utils.js b/08-suspense/lecture/src/lib/utils.js
similarity index 79%
rename from 08-suspense/lecture/src/workouts/utils.js
rename to 08-suspense/lecture/src/lib/utils.js
index b8bf700..ed40711 100644
--- a/08-suspense/lecture/src/workouts/utils.js
+++ b/08-suspense/lecture/src/lib/utils.js
@@ -1,7 +1,15 @@
import { createResource } from "simple-cache-provider";
////////////////////////////////////////////////////////////
-let qnetworks = ["fast", "slow", "slow", "fast", "slow", "fast", "nextIsSlow"];
+let qnetworks = [
+ "fast",
+ "slow",
+ "slow",
+ "fast",
+ "slow",
+ "fast",
+ "nextIsSlow"
+];
let search = window.location.search.substr(1);
let network = qnetworks[search] || "fast";
@@ -10,7 +18,8 @@ export { network };
////////////////////////////////////////////////////////////
-const sleep = (ms = 1000) => new Promise(res => setTimeout(res, ms));
+const sleep = (ms = 1000) =>
+ new Promise(res => setTimeout(res, ms));
let token = null;
@@ -42,9 +51,17 @@ const fakeWorkouts = [
completed: true
},
{ name: "Cardio", id: "cardio", completed: true },
- { name: "Lower Body", id: "lower", completed: false },
+ {
+ name: "Lower Body",
+ id: "lower",
+ completed: false
+ },
{ name: "Core", id: "core", completed: false },
- { name: "Upper Body", id: "upper-body", completed: false }
+ {
+ name: "Upper Body",
+ id: "upper-body",
+ completed: false
+ }
];
const fakeExercises = {
@@ -63,7 +80,12 @@ const fakeExercises = {
"jab punch sprawl",
"burpees"
],
- lower: ["lunges", "jump squats", "side-kicks", "hip raises"],
+ lower: [
+ "lunges",
+ "jump squats",
+ "side-kicks",
+ "hip raises"
+ ],
core: ["crunches"],
"upper-body": ["curls"]
};
@@ -99,6 +121,8 @@ export const fetchExercises = id =>
console.logTakeoff(`fetchExercises ${id}`);
await sleep(2000);
console.logLanding(`fetchExercises ${id}`);
+ console.log("-------");
+ console.log(fakeExercises[id]);
res(fakeExercises[id]);
});
@@ -107,7 +131,11 @@ export const fetchNextWorkout = id =>
console.logTakeoff(`fetchNext ${id}`);
await sleep(3000);
console.logLanding(`fetchNext ${id}`);
- res(fakeWorkouts.find(workout => workout.id === fakeNextWorkouts[id]));
+ res(
+ fakeWorkouts.find(
+ workout => workout.id === fakeNextWorkouts[id]
+ )
+ );
});
////////////////////////////////////////////////////////////
@@ -148,14 +176,22 @@ export const NextWorkoutResource = createResource(
console.logTakeoff(`readRelated ${id}`);
await sleep(networks[network].next);
console.logLanding(`readRelated ${id}`);
- res(fakeWorkouts.find(workout => workout.id === fakeNextWorkouts[id]));
+ res(
+ fakeWorkouts.find(
+ workout =>
+ workout.id === fakeNextWorkouts[id]
+ )
+ );
})
);
////////////////////////////////////////////////////////
// Contacts
const API = `https://contacts.now.sh`;
-const fetchContacts = async (url, opts = { headers: {} }) => {
+const fetchContacts = async (
+ url,
+ opts = { headers: {} }
+) => {
return fetch(`${API}${url}`, {
...opts,
headers: { authorization: token, ...opts.headers }
@@ -168,7 +204,9 @@ const fetchContacts = async (url, opts = { headers: {} }) => {
});
};
-export const readContacts = createResource(() => fetchContacts("/contacts"));
+export const readContacts = createResource(() =>
+ fetchContacts("/contacts")
+);
export const readContact = createResource(id =>
fetchContacts(`/contacts/${id}`)
@@ -186,9 +224,15 @@ export const createContact = contact =>
////////////////////////////////////////////////////////
// logging stuff
console.logTakeoff = str => {
- console.log(`%c🛫 ${str}`, "font-size: 20px; color: hsl(10, 50%, 50%)");
+ console.log(
+ `%c🛫 ${str}`,
+ "font-size: 20px; color: hsl(10, 50%, 50%)"
+ );
};
console.logLanding = str => {
- console.log(`%c🛬 ${str}`, "font-size: 20px; color: hsl(170, 50%, 50%)");
+ console.log(
+ `%c🛬 ${str}`,
+ "font-size: 20px; color: hsl(170, 50%, 50%)"
+ );
};
diff --git a/08-suspense/lecture/src/workouts/App.js b/08-suspense/lecture/src/workouts/App.js
deleted file mode 100644
index 81a7b54..0000000
--- a/08-suspense/lecture/src/workouts/App.js
+++ /dev/null
@@ -1,283 +0,0 @@
-import { createElement } from "glamor/react"; // eslint-disable-line
-/* @jsx createElement */
-import "./index.css";
-import Spinner from "react-svg-spinner";
-import ManageScroll from "../components/ManageScroll";
-import React, { Placeholder, lazy } from "react";
-import { Router, Link, redirectTo } from "@reach/router";
-import Component from "@reach/component-component";
-import {
- fetchWorkouts,
- fetchWorkout,
- fetchExercises,
- fetchNextWorkout,
- WorkoutsResource,
- WorkoutResource,
- ExercisesResource,
- NextWorkoutResource,
- network
-} from "./utils";
-import { cache } from "../cache";
-
-const Competitions = React.lazy(() =>
- import("./Competitions")
-);
-
-// Chantastic said this is okay to do.
-console.warn = () => {};
-
-let qpatience = [5000, 5000, 1, 1, 2000, 2000, 2000];
-let search = window.location.search.substr(1);
-let patience = qpatience[search] || 10000;
-
-const link = {
- display: "inline-block",
- width: "200px",
- height: "200px",
- lineHeight: "200px",
- background: "#fff",
- textAlign: "center",
- margin: "20px",
- ":hover": {
- background: "#ddd"
- },
- position: "relative"
-};
-
-const LoadingLink = ({ children, ...props }) => (
-
- {({ state, setState }) => (
- {
- setState({ isLoading: true });
- }}
- >
- {children}
-
-
-
-
- )}
-
-);
-
-const Home = () => (
-
-
Workout App!
-
-
- Workouts
-
-
- Competitions
-
-
-
-);
-
-const Workouts = () => {
- const workouts = WorkoutsResource.read(cache, 10);
- return (
-
- Home
-
Workouts
- {workouts.map(workout => (
-
- {workout.name}
-
- ))}
-
- );
-};
-
-const Exercises = ({ workoutId }) => {
- const exercises = ExercisesResource.read(
- cache,
- workoutId
- );
- return (
-
- {exercises.map((exercise, i) => (
- - {exercise}
- ))}
-
- );
-};
-
-class Workout extends React.Component {
- state = {
- workout: null,
- exercises: null,
- nextWorkout: null
- };
-
- componentDidMount() {
- this.fetch();
- }
-
- fetch() {
- const { workoutId } = this.props;
- fetchWorkout(workoutId).then(workout => {
- this.setState({ workout });
- });
- fetchExercises(workoutId).then(exercises => {
- this.setState({ exercises });
- });
- fetchNextWorkout(workoutId).then(nextWorkout => {
- console.log(nextWorkout);
- this.setState({ nextWorkout });
- });
- }
-
- componentDidUpdate(prevProps) {
- if (prevProps.workoutId !== this.props.workoutId) {
- this.setState({
- exercises: null,
- workout: null,
- nextWorkout: null
- });
- this.fetch();
- }
- }
-
- render() {
- const { workoutId } = this.props;
- const { workout, exercises, nextWorkout } = this.state;
-
- WorkoutResource.read(cache, workoutId);
-
- return workout ? (
-
- Home /{" "}
- Workouts
-
{workout.name}
- {exercises ? (
-
- ) : (
-
- )}
- {workout.completed &&
- (nextWorkout ? (
-
- ) : (
-
- Up Next!
-
- ))}
-
- ) : (
-
- );
- }
-}
-
-// class Workout extends React.Component {
-// render() {
-// const { workoutId } = this.props;
-
-// const workout = WorkoutResource.read(cache, workoutId);
-
-// return (
-//
-//
Home /{" "}
-//
Workouts
-//
{workout.name}
-//
}
-// >
-//
-//
-// {workout.completed && (
-//
-// Up Next!
-//
-// }
-// >
-//
-//
-// )}
-//
-// );
-// }
-// }
-
-const NextWorkout = ({ workoutId }) => {
- const nextWorkout = NextWorkoutResource.read(
- cache,
- workoutId
- );
- return (
-
-
- Up Next!{" "}
-
- {nextWorkout.name}
-
-
-
- );
-};
-
-const LoadingSpinner = () => (
-
-
-
-);
-
-const Network = () => (
-
- Network: {network}
-
-);
-
-const App = () => {
- return (
-
- }
- >
-
-
-
-
-
-
-
-
-
-
- );
-};
-
-export default App;
diff --git a/08-suspense/lecture/src/workouts/Img.js b/08-suspense/lecture/src/workouts/Img.js
deleted file mode 100644
index 91e53d6..0000000
--- a/08-suspense/lecture/src/workouts/Img.js
+++ /dev/null
@@ -1,20 +0,0 @@
-/* eslint-disable jsx-a11y/alt-text */
-import React from "react";
-import { createResource } from "simple-cache-provider";
-import withCache from "./withCache";
-
-const ImageResource = createResource(src => {
- const image = new Image();
- return new Promise(resolve => {
- image.onload = () => resolve(src);
- image.src = src;
- });
-});
-
-function Img({ cache, src, ...props }) {
- return
;
-}
-
-export const preload = ImageResource.preload;
-
-export default withCache(Img);
diff --git a/08-suspense/lecture/src/workouts/withCache.js b/08-suspense/lecture/src/workouts/withCache.js
deleted file mode 100644
index 8edb126..0000000
--- a/08-suspense/lecture/src/workouts/withCache.js
+++ /dev/null
@@ -1,8 +0,0 @@
-import React from "react";
-import { SimpleCache } from "simple-cache-provider";
-
-export default Comp => props => (
-
- {cache => }
-
-);