Skip to content

Commit 4ff6c31

Browse files
committed
docs(react): ran npm run lint and fixed spelling in docs
1 parent aeead46 commit 4ff6c31

File tree

6 files changed

+610
-632
lines changed

6 files changed

+610
-632
lines changed

docs/react/your-first-app.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ import App from './App';
108108
// CHANGE: Add the following import.
109109
import { defineCustomElements } from '@ionic/pwa-elements/loader';
110110

111-
// Call the element loader before the render call
111+
// CHANGE: Call the element loader before the render call
112112
defineCustomElements(window);
113113

114114
const container = document.getElementById('root');
@@ -159,7 +159,7 @@ Open `/src/pages/Tab2.tsx`. We see:
159159
<IonTitle>Photo Gallery</IonTitle>
160160
```
161161

162-
We put the visual aspects of our app into <ion-content>. In this case, it’s where we’ll add a button that opens the device’s camera as well as displays the image captured by the camera. Start by adding a [floating action button](https://ionicframework.com/docs/api/fab) (FAB) to the bottom of the page and set the camera image as the icon.
162+
We put the visual aspects of our app into `<ion-content>`. In this case, it’s where we’ll add a button that opens the device’s camera as well as displays the image captured by the camera. Start by adding a [floating action button](https://ionicframework.com/docs/api/fab) (FAB) to the bottom of the page and set the camera image as the icon.
163163

164164
```tsx
165165
// CHANGE: Add the following import.
@@ -216,7 +216,7 @@ import { images, square, triangle } from 'ionicons/icons';
216216
Within the tab bar (`<IonTabBar>`), change the label to “Photos” and the `ellipse` icon to `images` for the middle tab button:
217217

218218
```tsx
219-
// Keep other imports
219+
// Keep other imports
220220
// CHANGE: Add the following import.
221221
import { images, square, triangle } from 'ionicons/icons';
222222

docs/react/your-first-app/2-taking-photos.md

Lines changed: 86 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@ import { useState, useEffect } from 'react';
2929
import { isPlatform } from '@ionic/react';
3030

3131
// CHANGE: Add the following imports
32-
import {
33-
Camera,
34-
CameraResultType,
35-
CameraSource,
36-
Photo,
37-
} from '@capacitor/camera';
32+
import { Camera, CameraResultType, CameraSource, Photo } from '@capacitor/camera';
3833
import { Filesystem, Directory } from '@capacitor/filesystem';
3934
import { Preferences } from '@capacitor/preferences';
4035
import { Capacitor } from '@capacitor/core';
@@ -48,30 +43,25 @@ Next, create a function named usePhotoGallery:
4843
import { useState, useEffect } from 'react';
4944
import { isPlatform } from '@ionic/react';
5045

51-
import {
52-
Camera,
53-
CameraResultType,
54-
CameraSource,
55-
Photo,
56-
} from '@capacitor/camera';
46+
import { Camera, CameraResultType, CameraSource, Photo } from '@capacitor/camera';
5747
import { Filesystem, Directory } from '@capacitor/filesystem';
5848
import { Preferences } from '@capacitor/preferences';
5949
import { Capacitor } from '@capacitor/core';
6050

6151
export function usePhotoGallery() {
62-
// CHANGE: ADd the usePhotoGallery function.
63-
const takePhoto = async () => {
64-
// Take a photo
65-
const photo = await Camera.getPhoto({
66-
resultType: CameraResultType.Uri,
67-
source: CameraSource.Camera,
68-
quality: 100,
69-
});
70-
};
71-
72-
return {
73-
takePhoto,
74-
};
52+
// CHANGE: Add the usePhotoGallery function.
53+
const takePhoto = async () => {
54+
// Take a photo
55+
const photo = await Camera.getPhoto({
56+
resultType: CameraResultType.Uri,
57+
source: CameraSource.Camera,
58+
quality: 100,
59+
});
60+
};
61+
62+
return {
63+
takePhoto,
64+
};
7565
}
7666
```
7767

@@ -88,25 +78,25 @@ The last step we need to take is to use the new hook from the Tab2 page. Go back
8878
import { usePhotoGallery } from '../hooks/usePhotoGallery';
8979

9080
const Tab2: React.FC = () => {
91-
// CHANGE: Get access to `takePhoto` method by using the hook
92-
const { takePhoto } = usePhotoGallery();
93-
94-
return (
95-
<IonPage>
96-
<IonHeader>
97-
<IonToolbar>
98-
<IonTitle>Tab 2</IonTitle>
99-
</IonToolbar>
100-
</IonHeader>
101-
<IonContent>
102-
<IonFab vertical='bottom' horizontal='center' slot='fixed'>
103-
<IonFabButton onClick={() => takePhoto()}>
104-
<IonIcon icon={camera}></IonIcon>
105-
</IonFabButton>
106-
</IonFab>
107-
</IonContent>
108-
</IonPage>
109-
);
81+
// CHANGE: Get access to `takePhoto` method by using the hook
82+
const { takePhoto } = usePhotoGallery();
83+
84+
return (
85+
<IonPage>
86+
<IonHeader>
87+
<IonToolbar>
88+
<IonTitle>Tab 2</IonTitle>
89+
</IonToolbar>
90+
</IonHeader>
91+
<IonContent>
92+
<IonFab vertical="bottom" horizontal="center" slot="fixed">
93+
<IonFabButton onClick={() => takePhoto()}>
94+
<IonIcon icon={camera}></IonIcon>
95+
</IonFabButton>
96+
</IonFab>
97+
</IonContent>
98+
</IonPage>
99+
);
110100
};
111101

112102
export default Tab2;
@@ -126,7 +116,7 @@ First we will create a new type to define our Photo, which will hold specific me
126116

127117
```tsx
128118
export functino usePhotoGallery {
129-
// Old code from before.
119+
// Same old code from before.
130120
}
131121

132122
// CHANGE: Add the interface.
@@ -143,42 +133,42 @@ export function usePhotoGallery {
143133
// CHANGE: Add the photos array.
144134
const [photos, setPhotos] = useState<UserPhoto[]>([]);
145135

146-
// Old code from before.
136+
// Same old code from before.
147137
}
148138
```
149139

150140
When the camera is done taking a picture, the resulting Photo returned from Capacitor will be stored in the `photo` variable. We want to create a new photo object and add it to the photos state array. We make sure we don't accidentally mutate the current photos array by making a new array, and then call `setPhotos` to store the array into state. Update the `takePhoto` method and add this code after the getPhoto call:
151141

152142
```tsx
153-
// Old code from before.
143+
// Same old code from before.
154144

155145
export function usePhotoGallery() {
156-
const [photos, setPhotos] = useState<UserPhoto[]>([]);
157-
// CHANGE: Create new fileName variable with date and .jpeg
158-
const fileName = Date.now() + '.jpeg';
159-
160-
const takePhoto = async () => {
161-
// Photo Code
162-
163-
// CHANGE: Add in newPhotos after getPhoto call
164-
const newPhotos = [
165-
{
166-
filepath: fileName,
167-
webviewPath: photo.webPath,
168-
},
169-
...photos,
170-
];
171-
setPhotos(newPhotos);
172-
};
173-
174-
// CHANGE: Update return statement to include photos.
175-
return {
176-
photos,
177-
takePhoto,
178-
};
146+
const [photos, setPhotos] = useState<UserPhoto[]>([]);
147+
// CHANGE: Create new fileName variable with date and .jpeg
148+
const fileName = Date.now() + '.jpeg';
149+
150+
const takePhoto = async () => {
151+
// Same old code from before.
152+
153+
// CHANGE: Add in newPhotos after getPhoto call
154+
const newPhotos = [
155+
{
156+
filepath: fileName,
157+
webviewPath: photo.webPath,
158+
},
159+
...photos,
160+
];
161+
setPhotos(newPhotos);
162+
};
163+
164+
// CHANGE: Update return statement to include photos.
165+
return {
166+
photos,
167+
takePhoto,
168+
};
179169
}
180170

181-
// Old code from before.
171+
// Same old code from before.
182172
```
183173

184174
`usePhotoGallery.ts` should now look like this:
@@ -192,30 +182,30 @@ import { Preferences } from '@capacitor/preferences';
192182
import { Capacitor } from '@capacitor/core';
193183

194184
export function usePhotoGallery() {
195-
const [photos, setPhotos] = useState<UserPhoto[]>([]);
196-
const fileName = Date.now() + '.jpeg';
197-
198-
const takePhoto = async () => {
199-
const photo = await Camera.getPhoto({
200-
resultType: CameraResultType.Uri,
201-
source: CameraSource.Camera,
202-
quality: 100,
203-
});
204-
205-
const newPhotos = [
206-
{
207-
filepath: fileName,
208-
webviewPath: photo.webPath,
209-
},
210-
...photos,
211-
];
212-
setPhotos(newPhotos);
213-
};
214-
215-
return {
216-
photos,
217-
takePhoto,
218-
};
185+
const [photos, setPhotos] = useState<UserPhoto[]>([]);
186+
const fileName = Date.now() + '.jpeg';
187+
188+
const takePhoto = async () => {
189+
const photo = await Camera.getPhoto({
190+
resultType: CameraResultType.Uri,
191+
source: CameraSource.Camera,
192+
quality: 100,
193+
});
194+
195+
const newPhotos = [
196+
{
197+
filepath: fileName,
198+
webviewPath: photo.webPath,
199+
},
200+
...photos,
201+
];
202+
setPhotos(newPhotos);
203+
};
204+
205+
return {
206+
photos,
207+
takePhoto,
208+
};
219209
}
220210

221211
export interface UserPhoto {
@@ -227,7 +217,7 @@ export interface UserPhoto {
227217
Next, move over to `Tab2.tsx` so we can display the image on the screen. With the photo(s) stored into the main array we can display the images on the screen. Add a [Grid component](https://ionicframework.com/docs/api/grid) so that each photo will display nicely as photos are added to the gallery, and loop through each photo in the Photos array, adding an Image component (`<IonImg>`) for each. Point the `src` (source) to the photo’s path:
228218

229219
```tsx
230-
// Old code
220+
// Same old code from before.
231221

232222
// CHANGE: Import usePhotoGallery Hook
233223
import { usePhotoGallery } from '../hooks/usePhotoGallery';

0 commit comments

Comments
 (0)