Skip to content

Commit

Permalink
Update media plugin and fix streaks bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nkalupahana committed Nov 2, 2024
1 parent cf467d8 commit e66bd18
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 40 deletions.
4 changes: 0 additions & 4 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
</manifest>
6 changes: 3 additions & 3 deletions ios/App/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -280,7 +280,7 @@ SPEC CHECKSUMS:
CapacitorApp: 9d53aec7101f7b030a950c5bdc4df8612576b279
CapacitorCloudkit: a8242b6f83b10564ef6f46b0169a0573436a3d80
CapacitorCommunityInAppReview: c69a9392f39a10f28092d823cfa979637f4fa079
CapacitorCommunityMedia: 51cc6c8782b92cf622d9644cac37ae024fafb377
CapacitorCommunityMedia: 538138898dab7bee12323720c60f27602f358a80
CapacitorCordova: be703980ca797f847c3356f78fa175d21c8330c2
CapacitorDevice: f8fd88f9edd1261c55a109f32015b09bbbfdc4a0
CapacitorFilesystem: 60e59ba274c234a979e7a3be2552feaadcee4263
Expand Down Expand Up @@ -317,4 +317,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: cd2022b404aefcad8ecbdb74b45acb77cb0cddcb

COCOAPODS: 1.14.3
COCOAPODS: 1.15.2
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
56 changes: 28 additions & 28 deletions src/components/Streaks/StreakDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ enum OpenDialog {

const StreakDialog = () => {
const streak = useContext(StreakContext);
const [shownStreakTime, setShownStreakTime] = useState<number | undefined>(undefined);
const [user] = useAuthState(auth);
const [openDialog, setOpenDialog] = useState(OpenDialog.NONE);

Expand All @@ -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 && <Dialog title="Great work getting started.">
Expand All @@ -95,7 +95,7 @@ const StreakDialog = () => {
</p>
{ bottomButtons }
</Dialog> }
{ openDialog === OpenDialog.CONTINUING && <Dialog title="Streak milestone!">
{ openDialog === OpenDialog.CONTINUING && streak > 1 && <Dialog title="Streak milestone!">
<div className="br" />
<StreakBadge />
<p className="text-center">
Expand Down

0 comments on commit e66bd18

Please sign in to comment.