Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factor out useDynamicFlow hook #151

Merged
merged 2 commits into from Mar 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions client/ionic/src/hooks/useDynamicFlow.ts
@@ -0,0 +1,17 @@
import { useEffect, useState } from 'react';
import { FlowLoader, LoadedFlow } from '../content/flow';
import { getUserContext } from '../content/userContext';

export default function useDynamicFlow(id: string) {
const [flow, setFlow] = useState({} as LoadedFlow);

useEffect(() => {
async function fetchFlow() {
const f = await FlowLoader.loadFlow(id, getUserContext());
setFlow(f);
}
fetchFlow();
}, [id]);

return flow;
}
19 changes: 1 addition & 18 deletions client/ionic/src/pages/About.tsx
@@ -1,5 +1,4 @@
import React from 'react';
import { FlowLoader, Flow, LoadedFlow } from '../content/flow';
import {
IonContent,
IonPage,
Expand All @@ -14,23 +13,7 @@ import {
IonImg,
} from '@ionic/react';
import 'tachyons';
import { getUserContext } from '../content/userContext';

// TODO: Abstract this, DRY.

function useDynamicFlow(id: string) {
const [flow, setFlow] = React.useState({} as LoadedFlow);

React.useEffect(() => {
async function fetchFlow() {
const f = await FlowLoader.loadFlow(id, getUserContext());
setFlow(f);
}
fetchFlow();
}, [id]);

return flow;
}
import useDynamicFlow from '../hooks/useDynamicFlow';

// TODO: Rename to Splash, after other PRs to avoid conflicts.
const About: React.FC = () => {
Expand Down
19 changes: 1 addition & 18 deletions client/ionic/src/pages/ProtectYourself.tsx
@@ -1,5 +1,4 @@
import React from 'react';
import { FlowLoader, Flow, LoadedFlow } from '../content/flow';
import {
IonContent,
IonPage,
Expand All @@ -11,23 +10,7 @@ import {
} from '@ionic/react';
import TopNav from '../components/TopNav';
import 'tachyons';
import { getUserContext } from '../content/userContext';

// TODO: Abstract this, DRY.

function useDynamicFlow(id: string) {
const [flow, setFlow] = React.useState({} as LoadedFlow);

React.useEffect(() => {
async function fetchFlow() {
const f = await FlowLoader.loadFlow(id, getUserContext());
setFlow(f);
}
fetchFlow();
}, [id]);

return flow;
}
import useDynamicFlow from '../hooks/useDynamicFlow';

const ProtectYourself: React.FC = () => {
// TODO: Refactor this out to separate Flow components. Use a dictionary
Expand Down
1 change: 1 addition & 0 deletions content/credits.yaml
Expand Up @@ -19,6 +19,7 @@ team:
- Mark Graves, Jr
- Hunter Spinks
- Bob Lee
- Simon Sturmer

# Add yourself here when you first submit a contribution.

Expand Down