Skip to content

Commit d572cf1

Browse files
ability to add data, added modals, alerts and types
1 parent f867864 commit d572cf1

15 files changed

+499
-14
lines changed

.firebaserc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"projects": {
3+
"default": "ionic-react-fire"
4+
}
5+
}

capacitor.config.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,5 @@
44
"bundledWebRuntime": false,
55
"npmClient": "npm",
66
"webDir": "build",
7-
"cordova": {},
8-
"server": {
9-
"url": "http://192.168.1.151:8100",
10-
"cleartext": true
11-
}
7+
"cordova": {}
128
}

firebase.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"firestore": {
3+
"rules": "firestore.rules",
4+
"indexes": "firestore.indexes.json"
5+
},
6+
"storage": {
7+
"rules": "storage.rules"
8+
},
9+
"emulators": {
10+
"firestore": {
11+
"port": 8080
12+
},
13+
"ui": {
14+
"enabled": true
15+
}
16+
}
17+
}

firestore-debug.log

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
API endpoint: http://localhost:8080
2+
If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:
3+
4+
export FIRESTORE_EMULATOR_HOST=localhost:8080
5+
6+
Dev App Server is now running.
7+
8+
Jul 20, 2020 10:50:59 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
9+
INFO: Detected non-HTTP/2 connection.
10+
Jul 20, 2020 10:50:59 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
11+
INFO: Detected HTTP/2 connection.

firestore.indexes.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"indexes": [],
3+
"fieldOverrides": []
4+
}

firestore.rules

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
rules_version = '2';
2+
service cloud.firestore {
3+
match /databases/{database}/documents {
4+
5+
// This rule allows anyone with your database reference to view, edit,
6+
// and delete all data in your Firestore database. It is useful for getting
7+
// started, but it is configured to expire after 30 days because it
8+
// leaves your app open to attackers. At that time, all client
9+
// requests to your Firestore database will be denied.
10+
//
11+
// Make sure to write security rules for your app before that time, or else
12+
// all client requests to your Firestore database will be denied until you Update
13+
// your rules
14+
match /{document=**} {
15+
allow read, write: if request.time < timestamp.date(2020, 8, 19);
16+
}
17+
}
18+
}

src/App.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import './env';
1+
import "./env";
22

33
import React, { Suspense } from "react";
44
import { FirebaseAppProvider, AuthCheck } from "reactfire";
@@ -27,20 +27,36 @@ import { FIREBASE_CONFIG } from "./env";
2727
import Login from "./pages/Login";
2828
import Home from "./pages/Home";
2929

30-
import { Plugins } from '@capacitor/core';
30+
import { Plugins } from "@capacitor/core";
31+
import { Route, Redirect } from "react-router";
32+
import CreateAccount from "./pages/CreateAccount";
3133
const { SplashScreen } = Plugins;
3234

3335
// Hide the splash (you should do this on app launch)
3436
SplashScreen.hide();
3537

38+
const PublicRoutes: React.FunctionComponent = () => {
39+
return (
40+
<IonRouterOutlet>
41+
<Route exact path="/login">
42+
<Login />
43+
</Route>
44+
<Route exact path="/create-account">
45+
<CreateAccount />
46+
</Route>
47+
<Redirect path="/" to="/login" />
48+
</IonRouterOutlet>
49+
);
50+
};
51+
3652
const App: React.FunctionComponent = () => {
3753
return (
3854
<FirebaseAppProvider firebaseConfig={FIREBASE_CONFIG}>
3955
<IonApp>
4056
<IonReactRouter>
4157
<IonRouterOutlet>
4258
<Suspense fallback={<IonLoading isOpen={true} />}>
43-
<AuthCheck fallback={<Login />}>
59+
<AuthCheck fallback={<PublicRoutes />}>
4460
<Home />
4561
</AuthCheck>
4662
</Suspense>

src/components/MyErrorDisplay.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from "react";
2+
import { ErrorMessage } from "@hookform/error-message";
3+
/**
4+
* custom component to render the error messahe with the
5+
* desired style, we are wrapping a react-form-hook utility
6+
*
7+
* @param errors
8+
* @param elementName
9+
*/
10+
export const MyErrorDisplay: React.FunctionComponent<{
11+
errors: any;
12+
elementName: string;
13+
}> = ({ errors, elementName }) => {
14+
return (
15+
<ErrorMessage
16+
errors={errors}
17+
name={elementName}
18+
as={<div
19+
style={{
20+
color: "red",
21+
paddingTop: 6,
22+
paddingLeft: 16,
23+
fontStyle: "italic",
24+
}} />} />
25+
);
26+
};

src/components/MyIonTextItem.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from "react";
2+
import {
3+
IonItem,
4+
IonLabel,
5+
IonInput
6+
} from "@ionic/react";
7+
import { Controller } from "react-hook-form";
8+
import { MyErrorDisplay } from "./MyErrorDisplay";
9+
/**
10+
* custom component to render the text fields
11+
* @param param0
12+
*/
13+
export const MyIonTextItem: React.FunctionComponent<{
14+
name: string;
15+
errors: any;
16+
render?: any;
17+
control: any;
18+
labelName: string;
19+
}> = ({ name, errors, render, control, labelName }) => {
20+
return (
21+
<>
22+
<IonItem>
23+
<IonLabel>{labelName}</IonLabel>
24+
<Controller
25+
render={({ onChange }) => (
26+
<IonInput type="text" onIonChange={onChange} defaultValue="" />
27+
)}
28+
control={control}
29+
name={name}
30+
rules={{
31+
required: labelName + " is a required field",
32+
}} />
33+
</IonItem>
34+
<MyErrorDisplay errors={errors} elementName={name} />
35+
</>
36+
);
37+
};

src/pages/AddSomethingModal.tsx

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import React from "react";
2+
import {
3+
IonButtons,
4+
IonButton,
5+
IonHeader,
6+
IonToolbar,
7+
IonTitle,
8+
IonContent,
9+
IonPage,
10+
} from "@ionic/react";
11+
12+
import { useForm } from "react-hook-form";
13+
import { MyIonTextItem } from "../components/MyIonTextItem";
14+
15+
const AddSomethingModal: React.FunctionComponent<{
16+
onCloseModal: (data: IModalResponse) => Promise<void>;
17+
}> = ({ onCloseModal }) => {
18+
// from react-hook-form
19+
// SEE - https://react-hook-form.com/
20+
const { handleSubmit, control, errors } = useForm();
21+
/**
22+
* get data from form and pass it back to the parent
23+
* component
24+
*/
25+
const addTheThing = async (data: IModalData) => {
26+
console.log(data);
27+
onCloseModal({ hasData: true, data });
28+
};
29+
30+
return (
31+
<IonPage>
32+
<IonHeader>
33+
<IonToolbar color="light">
34+
<IonButtons slot="start" />
35+
<IonTitle>Enter Thing Information</IonTitle>
36+
</IonToolbar>
37+
</IonHeader>
38+
<IonContent className="ion-padding">
39+
<form onSubmit={handleSubmit(addTheThing)}>
40+
<MyIonTextItem
41+
labelName="Podcast Name"
42+
name="podcastName"
43+
errors={errors}
44+
control={control}
45+
/>
46+
47+
<MyIonTextItem
48+
labelName="Host"
49+
name="podcastHost"
50+
errors={errors}
51+
control={control}
52+
/>
53+
54+
<MyIonTextItem
55+
labelName="URL"
56+
name="podcastURL"
57+
errors={errors}
58+
control={control}
59+
/>
60+
61+
<div className="ion-padding">
62+
<IonButton expand="block" type="submit">
63+
Save Podcast Information
64+
</IonButton>
65+
<IonButton
66+
expand="block"
67+
type="button"
68+
onClick={() => onCloseModal({ hasData: false })}
69+
>
70+
Cancel
71+
</IonButton>
72+
</div>
73+
</form>
74+
</IonContent>
75+
</IonPage>
76+
);
77+
};
78+
79+
export default AddSomethingModal;
80+
81+
type IModalData = {
82+
podcastName: string;
83+
podcastHost: string;
84+
podcastURL: string;
85+
};
86+
87+
export type IModalResponse = {
88+
hasData: boolean;
89+
data?: IModalData;
90+
};

0 commit comments

Comments
 (0)