You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -25,11 +25,18 @@ $ ionic cap run android -l --external
25
25
The Live Reload server will start up, and the native IDE of choice will open if not opened already. Within the IDE, click the Play button to launch the app onto your device.
26
26
27
27
## Deleting Photos
28
+
With Live Reload running and the app is open on your device, let’s implement photo deletion functionality. We'll display an [IonActionSheet](https://ionicframework.com/docs/api/action-sheet) with the option to delete a photo.
28
29
29
-
With Live Reload running and the app is open on your device, let’s implement photo deletion functionality. Open `Tab2Page.vue` then import the `actionSheetController`. We'll display an [IonActionSheet](https://ionicframework.com/docs/api/action-sheet) with the option to delete a photo:
30
+
Open `Tab2Page.vue` and add `actionSheetController` to the imports from `@ionic/vue`. We also need to add a reference to the `deletePhoto` method, which we'll create soon in `usePhotoGallery()`:
31
+
```html
32
+
<template>
33
+
<!-- template code -->
34
+
</template>
30
35
31
-
```tsx
36
+
<scriptsetuplang="ts">
37
+
import { camera, trash, close } from'ionicons/icons';
32
38
import {
39
+
// CHANGE: Add the `actionSheetController` import.
Next, within `script setup`, call the `create`function to open a dialog with the option to either delete the selected photo or cancel (close) the dialog:
99
+
Next, within `script setup`, create a new function called `showActionSheet`. `showActionSheet` will call the `create`method on the `actionSheetController` to open a dialog with the option to either delete the selected photo or cancel (close) the dialog:
63
100
64
-
```tsx
101
+
```html
102
+
<template>
103
+
<!-- template code -->
104
+
</template>
105
+
106
+
<scriptsetuplang="ts">
107
+
import { camera, trash, close } from'ionicons/icons';
Next, we need to implement the `deletePhoto` method in the `usePhotoGallery` function. Open the file then add:
155
+
Next, open `usePhotoGallery.ts`. We need to implement the `deletePhoto` method in the `usePhotoGallery` function. We also need to update the return statement to include `deletePhoto`:
92
156
93
157
```tsx
94
-
const deletePhoto =async (photo:UserPhoto) => {
95
-
// Remove this photo from the Photos reference data array
// CHANGE: Add `deletePhoto` to the return statement.
206
+
return {
207
+
photos,
208
+
takePhoto,
209
+
deletePhoto
210
+
};
104
211
};
212
+
213
+
exportinterfaceUserPhoto {
214
+
filepath:string;
215
+
webviewPath?:string;
216
+
}
105
217
```
106
218
107
219
The selected photo is removed from the `photos` array first, then we delete the photo file using the Filesystem API.
@@ -119,16 +231,6 @@ const cachePhotos = () => {
119
231
watch(photos, cachePhotos);
120
232
```
121
233
122
-
Finally, return the `deletePhoto` function:
123
-
124
-
```tsx
125
-
return {
126
-
photos,
127
-
takePhoto,
128
-
deletePhoto,
129
-
};
130
-
```
131
-
132
234
Save this file, then tap on a photo again and choose the "Delete" option. This time, the photo is deleted! Implemented much faster using Live Reload. 💪
133
235
134
236
In the final portion of this tutorial, we’ll walk you through the basics of the Appflow product used to build and deploy your application to users' devices.
0 commit comments