From e66bd1825da092db669ccb0b2ff440e906d2bc9a Mon Sep 17 00:00:00 2001
From: nkalupahana
Date: Fri, 1 Nov 2024 20:31:36 -0700
Subject: [PATCH] Update media plugin and fix streaks bug
---
android/app/src/main/AndroidManifest.xml | 4 --
ios/App/Podfile.lock | 6 +--
package-lock.json | 8 ++--
package.json | 2 +-
src/components/Streaks/StreakDialog.tsx | 56 ++++++++++++------------
5 files changed, 36 insertions(+), 40 deletions(-)
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index b363a3a2..ae469200 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -54,10 +54,6 @@
-
-
-
-
diff --git a/ios/App/Podfile.lock b/ios/App/Podfile.lock
index b7753893..cbb4b406 100644
--- a/ios/App/Podfile.lock
+++ b/ios/App/Podfile.lock
@@ -13,7 +13,7 @@ PODS:
- Capacitor
- CapacitorCommunityInAppReview (6.0.0):
- Capacitor
- - CapacitorCommunityMedia (6.0.0):
+ - CapacitorCommunityMedia (7.0.0):
- Capacitor
- SDWebImage
- CapacitorCordova (6.1.0)
@@ -280,7 +280,7 @@ SPEC CHECKSUMS:
CapacitorApp: 9d53aec7101f7b030a950c5bdc4df8612576b279
CapacitorCloudkit: a8242b6f83b10564ef6f46b0169a0573436a3d80
CapacitorCommunityInAppReview: c69a9392f39a10f28092d823cfa979637f4fa079
- CapacitorCommunityMedia: 51cc6c8782b92cf622d9644cac37ae024fafb377
+ CapacitorCommunityMedia: 538138898dab7bee12323720c60f27602f358a80
CapacitorCordova: be703980ca797f847c3356f78fa175d21c8330c2
CapacitorDevice: f8fd88f9edd1261c55a109f32015b09bbbfdc4a0
CapacitorFilesystem: 60e59ba274c234a979e7a3be2552feaadcee4263
@@ -317,4 +317,4 @@ SPEC CHECKSUMS:
PODFILE CHECKSUM: cd2022b404aefcad8ecbdb74b45acb77cb0cddcb
-COCOAPODS: 1.14.3
+COCOAPODS: 1.15.2
diff --git a/package-lock.json b/package-lock.json
index e02f7066..1521f480 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -11,7 +11,7 @@
"license": "AGPL-3.0",
"dependencies": {
"@capacitor-community/in-app-review": "^6.0.0",
- "@capacitor-community/media": "^6.0.0",
+ "@capacitor-community/media": "^7.0.0",
"@capacitor-firebase/analytics": "^6.0.0",
"@capacitor-firebase/authentication": "^6.0.0",
"@capacitor-firebase/messaging": "^6.0.0",
@@ -2090,9 +2090,9 @@
}
},
"node_modules/@capacitor-community/media": {
- "version": "6.0.0",
- "resolved": "https://registry.npmjs.org/@capacitor-community/media/-/media-6.0.0.tgz",
- "integrity": "sha512-hROzyGI6pUv9FF86elePw/AqbWybrxgsY+f+83/erMBLhue3HkJaScWCZ7473UpdGKRgxfLEjsUN+Quwvy0NxA==",
+ "version": "7.0.0",
+ "resolved": "https://registry.npmjs.org/@capacitor-community/media/-/media-7.0.0.tgz",
+ "integrity": "sha512-a5c2dZVRvlgowb5ltHXN6hqV1zeib+r19wtBFHyGLEA8T4YuBTpzAuXuNvNlE63y12XrIAvTYGFE4b0se4hzoA==",
"peerDependencies": {
"@capacitor/core": "^6.0.0"
}
diff --git a/package.json b/package.json
index 0d4e58d2..f9be671f 100644
--- a/package.json
+++ b/package.json
@@ -4,7 +4,7 @@
"private": true,
"dependencies": {
"@capacitor-community/in-app-review": "^6.0.0",
- "@capacitor-community/media": "^6.0.0",
+ "@capacitor-community/media": "^7.0.0",
"@capacitor-firebase/analytics": "^6.0.0",
"@capacitor-firebase/authentication": "^6.0.0",
"@capacitor-firebase/messaging": "^6.0.0",
diff --git a/src/components/Streaks/StreakDialog.tsx b/src/components/Streaks/StreakDialog.tsx
index 39f34229..44833e29 100644
--- a/src/components/Streaks/StreakDialog.tsx
+++ b/src/components/Streaks/StreakDialog.tsx
@@ -17,7 +17,6 @@ enum OpenDialog {
const StreakDialog = () => {
const streak = useContext(StreakContext);
- const [shownStreakTime, setShownStreakTime] = useState(undefined);
const [user] = useAuthState(auth);
const [openDialog, setOpenDialog] = useState(OpenDialog.NONE);
@@ -43,43 +42,44 @@ const StreakDialog = () => {
>
useEffect(() => {
+ // Don't show anything if streak isn't loaded yet / is zero
+ if (streak === 0) return;
+
+ // This is used to restore the streak dialog in case
+ // it was shown but not acknowledged (removed from settings when
+ // user clicks the close button)
const settings = parseSettings();
if ([OpenDialog.FIRST_DAY, OpenDialog.CONTINUING].includes(settings.streakDialog)) {
setOpenDialog(settings.streakDialog);
}
- }, []);
+ }, [streak]);
useEffect(() => {
if (!user) return;
get(ref(db, `/${user.uid}/prompts/streak`)).then(snap => {
- const data = snap.val() ?? 0;
- setShownStreakTime(data);
- });
- }, [user]);
-
- useEffect(() => {
- if (shownStreakTime === undefined || !user) return;
- let newShownStreak = false;
+ const shownStreakTime = snap.val() ?? 0;
+ let newShownStreak = false;
- // If we have a streak, and it's been a week since we last showed a streak message
- if (streak > 0 && shownStreakTime < DateTime.now().minus({ days: 7 }).toMillis()) {
- // Only ever show the first journaling message once
- if (streak === 1 && shownStreakTime === 0) {
- newShownStreak = true;
- setOpenDialog(OpenDialog.FIRST_DAY);
- setSettings("streakDialog", OpenDialog.FIRST_DAY);
- } else if (streak % 10 === 0) {
- // Show every ten consecutive days
- newShownStreak = true;
- setOpenDialog(OpenDialog.CONTINUING);
- setSettings("streakDialog", OpenDialog.CONTINUING);
+ // If we have a streak, and it's been a week since we last showed a streak message
+ if (streak > 0 && shownStreakTime < DateTime.now().minus({ days: 7 }).toMillis()) {
+ // Only ever show the first journaling message once
+ if (streak === 1 && shownStreakTime === 0) {
+ newShownStreak = true;
+ setOpenDialog(OpenDialog.FIRST_DAY);
+ setSettings("streakDialog", OpenDialog.FIRST_DAY);
+ } else if (streak % 10 === 0) {
+ // Show every ten consecutive days
+ newShownStreak = true;
+ setOpenDialog(OpenDialog.CONTINUING);
+ setSettings("streakDialog", OpenDialog.CONTINUING);
+ }
}
- }
- if (newShownStreak) {
- set(ref(db, `/${user.uid}/prompts/streak`), serverTimestamp());
- }
- }, [user, streak, shownStreakTime]);
+ if (newShownStreak) {
+ set(ref(db, `/${user.uid}/prompts/streak`), serverTimestamp());
+ }
+ });
+ }, [user, streak]);
return <>
{ openDialog === OpenDialog.FIRST_DAY &&
{ bottomButtons }
}
- { openDialog === OpenDialog.CONTINUING &&