From b855d25ae8383f0710da3cdddbfa2bb8248de417 Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 18 Mar 2024 21:37:20 +0200 Subject: [PATCH 1/5] `genMarkLesson` takes `finished` param --- js/audio-service.ts | 6 +++--- js/persistence.ts | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/js/audio-service.ts b/js/audio-service.ts index 44dc4a8..7e6cc0c 100644 --- a/js/audio-service.ts +++ b/js/audio-service.ts @@ -4,7 +4,7 @@ import BackgroundTimer, {IntervalId} from 'react-native-background-timer'; import { genAutopause, genUpdateProgressForLesson, - genMarkLessonFinished, + genMarkLesson, genPreferenceStreamQuality, } from './persistence'; import CourseData from './course-data'; @@ -272,7 +272,7 @@ export default async () => { course: wasPlaying?.course, lesson: wasPlaying?.lesson, }); - await genMarkLessonFinished(wasPlaying.course, wasPlaying.lesson); + await genMarkLesson(wasPlaying.course, wasPlaying.lesson, true); await genUpdateProgressForLesson( wasPlaying.course, wasPlaying.lesson, @@ -327,7 +327,7 @@ export default async () => { // guess who worked out the hard way that if you do the next two concurrently you get a race condition - await genMarkLessonFinished(wasPlaying.course, wasPlaying.lesson); + await genMarkLesson(wasPlaying.course, wasPlaying.lesson, true); // otherwise it's very tricky to play it again! await genUpdateProgressForLesson( diff --git a/js/persistence.ts b/js/persistence.ts index 252670e..bca8ead 100644 --- a/js/persistence.ts +++ b/js/persistence.ts @@ -92,9 +92,10 @@ export const genUpdateProgressForLesson = async ( ]); }; -export const genMarkLessonFinished = async ( +export const genMarkLesson = async ( course: Course, lesson: number, + finished: boolean, ): Promise => { const progressObject = await genProgressForLesson(course, lesson); @@ -103,7 +104,7 @@ export const genMarkLessonFinished = async ( `@activity/${course}/${lesson}`, JSON.stringify({ ...progressObject, - finished: true, + finished, }), ), AsyncStorage.setItem( @@ -114,6 +115,7 @@ export const genMarkLessonFinished = async ( ]); if ( + finished && (await genPreferenceAutoDeleteFinished()) && (await DownloadManager.genIsDownloaded(course, lesson)) ) { From 5633255eedc49716640259f02c08eda492feaf87 Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 18 Mar 2024 21:38:26 +0200 Subject: [PATCH 2/5] Formatting --- js/components/Listen/ListenBottomSheet.react.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js/components/Listen/ListenBottomSheet.react.tsx b/js/components/Listen/ListenBottomSheet.react.tsx index 58396a6..0c5cb59 100644 --- a/js/components/Listen/ListenBottomSheet.react.tsx +++ b/js/components/Listen/ListenBottomSheet.react.tsx @@ -15,11 +15,11 @@ import {useNavigation} from '@react-navigation/native'; import {useProgress} from 'react-native-track-player'; import {log} from '../../metrics'; import formatDuration from 'format-duration'; -import { MainNavigationProp } from '../App.react'; +import {MainNavigationProp} from '../App.react'; interface Props { - course: Course, - lesson: number, + course: Course; + lesson: number; downloaded: boolean | null; } From 1dc4ce6ef22bdfcef960472f0d9c3434bb4e525c Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 18 Mar 2024 21:38:42 +0200 Subject: [PATCH 3/5] Bottom sheet allow toggle finish --- .../Listen/ListenBottomSheet.react.tsx | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/js/components/Listen/ListenBottomSheet.react.tsx b/js/components/Listen/ListenBottomSheet.react.tsx index 0c5cb59..8bc2cbd 100644 --- a/js/components/Listen/ListenBottomSheet.react.tsx +++ b/js/components/Listen/ListenBottomSheet.react.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, {useEffect, useState} from 'react'; import { StyleSheet, View, @@ -9,7 +9,7 @@ import { import {Icon} from 'react-native-elements'; import CourseData from '../../course-data'; import DownloadManager from '../../download-manager'; -import {genMarkLessonFinished} from '../../persistence'; +import {genMarkLesson, genProgressForLesson, Progress} from '../../persistence'; import {genStopPlaying} from '../../audio-service'; import {useNavigation} from '@react-navigation/native'; import {useProgress} from 'react-native-track-player'; @@ -26,24 +26,35 @@ interface Props { const ListenBottomSheet = ({course, lesson, downloaded}: Props) => { const {position} = useProgress(); const {pop} = useNavigation>(); + const [progress, setProgress] = useState(null); + + useEffect(() => { + (async () => { + const progressResp = await genProgressForLesson(course, lesson); + setProgress(progressResp); + })(); + }, [course, lesson]); + + const finished = progress?.finished; return ( <> { log({ - action: 'mark_finished', + action: `mark_${finished ? 'unfinished' : 'finished'}`, surface: 'listen_bottom_sheet', course, lesson, position, }); - - await genMarkLessonFinished(course, lesson); + await genMarkLesson(course, lesson, !finished); pop(); }}> - Mark as finished + {`Mark as ${ + finished ? 'unfinished' : 'finished' + }`} Date: Mon, 18 Mar 2024 21:40:13 +0200 Subject: [PATCH 4/5] Toggle finished/unfinished from all lessons rows --- js/components/AllLessons/LessonRow.react.tsx | 51 +++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/js/components/AllLessons/LessonRow.react.tsx b/js/components/AllLessons/LessonRow.react.tsx index 6d58edb..84cebbc 100644 --- a/js/components/AllLessons/LessonRow.react.tsx +++ b/js/components/AllLessons/LessonRow.react.tsx @@ -5,7 +5,7 @@ import ProgressCircle from 'react-native-progress-circle'; import {Icon} from 'react-native-elements'; import formatDuration from 'format-duration'; import prettyBytes from 'pretty-bytes'; -import {genProgressForLesson, Progress} from '../../persistence'; +import {genMarkLesson, genProgressForLesson, Progress} from '../../persistence'; import DownloadManager, {useDownloadStatus} from '../../download-manager'; import CourseData from '../../course-data'; import {usePreference} from '../../persistence'; @@ -166,10 +166,33 @@ const LessonRow = ({ const finished = progress?.finished; const downloading = downloadState && !downloadState.error && !downloadState.finished; - - const bundled = !!(lesson === 0 && CourseData.getBundledFirstLesson(course)) + + const bundled = !!(lesson === 0 && CourseData.getBundledFirstLesson(course)); + + const handleFinishedPress = async () => { + log({ + action: `mark_${finished ? 'unfinished' : 'finished'}`, + surface: 'all_lessons', + course, + lesson, + }); + await genMarkLesson(course, lesson, !finished); + setProgress({...progress!, finished: !finished}); + }; + return ( + + + + + { navigate('Listen', {course, lesson}); @@ -177,16 +200,6 @@ const LessonRow = ({ {ready ? ( - {CourseData.getLessonTitle(course, lesson)} @@ -234,12 +247,11 @@ const LessonRow = ({ const styles = StyleSheet.create({ row: { flexDirection: 'row', - }, - lessonBox: { - paddingHorizontal: 20, backgroundColor: 'white', borderBottomColor: '#ccc', borderBottomWidth: 1, + }, + lessonBox: { flex: 1, flexDirection: 'row', justifyContent: 'space-between', @@ -247,9 +259,6 @@ const styles = StyleSheet.create({ downloadBox: { width: LESSON_ROW_HEIGHT, height: LESSON_ROW_HEIGHT, - backgroundColor: 'white', - borderColor: '#ccc', - borderBottomWidth: 1, alignItems: 'center', justifyContent: 'center', }, @@ -269,10 +278,6 @@ const styles = StyleSheet.create({ fontSize: 12, color: 'gray', }, - - finishedIcon: { - marginRight: 24, - }, progressCircleText: { fontSize: 16, }, From 5b7e409deb539f0a790bed44f1a7d8ecb3728a30 Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 18 Mar 2024 21:59:39 +0200 Subject: [PATCH 5/5] Remove unneeded brackets --- js/components/AllLessons/LessonRow.react.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/components/AllLessons/LessonRow.react.tsx b/js/components/AllLessons/LessonRow.react.tsx index 84cebbc..2fa3964 100644 --- a/js/components/AllLessons/LessonRow.react.tsx +++ b/js/components/AllLessons/LessonRow.react.tsx @@ -183,7 +183,7 @@ const LessonRow = ({ return ( - +