musora-content-services 2.8.0 → 2.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/package.json +1 -1
- package/src/services/dateUtils.js +7 -1
- package/src/services/userActivity.js +19 -14
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [2.8.1](https://github.com/railroadmedia/musora-content-services/compare/v2.8.0...v2.8.1) (2025-05-29)
|
|
6
|
+
|
|
5
7
|
## [2.8.0](https://github.com/railroadmedia/musora-content-services/compare/v2.7.3...v2.8.0) (2025-05-28)
|
|
6
8
|
|
|
7
9
|
|
package/package.json
CHANGED
|
@@ -53,7 +53,7 @@ export function isNextDay(prev, current) {
|
|
|
53
53
|
);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
export function getTimeRemainingUntilLocal(targetUtcIsoString) {
|
|
56
|
+
export function getTimeRemainingUntilLocal(targetUtcIsoString, {withTotalSeconds} = {}) {
|
|
57
57
|
const targetUTC = new Date(targetUtcIsoString);
|
|
58
58
|
if (isNaN(targetUTC.getTime())) {
|
|
59
59
|
return "00:00:00";
|
|
@@ -70,6 +70,12 @@ export function getTimeRemainingUntilLocal(targetUtcIsoString) {
|
|
|
70
70
|
const hours = String(Math.floor(totalSeconds / 3600)).padStart(2, '0');
|
|
71
71
|
const minutes = String(Math.floor((totalSeconds % 3600) / 60)).padStart(2, '0');
|
|
72
72
|
const seconds = String(totalSeconds % 60).padStart(2, '0');
|
|
73
|
+
if(withTotalSeconds) {
|
|
74
|
+
return {
|
|
75
|
+
totalSeconds,
|
|
76
|
+
formatted: `${hours}:${minutes}:${seconds}`
|
|
77
|
+
}
|
|
78
|
+
}
|
|
73
79
|
|
|
74
80
|
return `${hours}:${minutes}:${seconds}`;
|
|
75
81
|
}
|
|
@@ -1032,8 +1032,8 @@ async function processContentItem(item) {
|
|
|
1032
1032
|
|
|
1033
1033
|
if (item.childIndex) {
|
|
1034
1034
|
let nextId = item.childIndex
|
|
1035
|
-
const nextByProgress = findIncompleteLesson(progressOnItems, item.childIndex, item.raw.type)
|
|
1036
|
-
nextId = nextByProgress ? nextByProgress : nextId
|
|
1035
|
+
const nextByProgress = findIncompleteLesson(progressOnItems, item.childIndex, item.raw.type)
|
|
1036
|
+
nextId = nextByProgress ? nextByProgress : nextId
|
|
1037
1037
|
|
|
1038
1038
|
const nestedLessons = data.lessons
|
|
1039
1039
|
.filter(item => Array.isArray(item.lessons))
|
|
@@ -1049,15 +1049,17 @@ async function processContentItem(item) {
|
|
|
1049
1049
|
}))
|
|
1050
1050
|
);
|
|
1051
1051
|
|
|
1052
|
-
const lessons = (nestedLessons.length === 0) ? data.lessons : nestedLessons
|
|
1053
|
-
const nextLesson = lessons.find(lesson => lesson.id === nextId)
|
|
1054
|
-
data.first_incomplete_child = nextLesson?.parent ?? nextLesson
|
|
1055
|
-
data.second_incomplete_child = (nextLesson?.parent) ? nextLesson : null
|
|
1052
|
+
const lessons = (nestedLessons.length === 0) ? data.lessons : nestedLessons
|
|
1053
|
+
const nextLesson = lessons.find(lesson => lesson.id === nextId)
|
|
1054
|
+
data.first_incomplete_child = nextLesson?.parent ?? nextLesson
|
|
1055
|
+
data.second_incomplete_child = (nextLesson?.parent) ? nextLesson : null
|
|
1056
1056
|
if(data.type === 'challenge' && nextByProgress !== undefined ){
|
|
1057
1057
|
const challenge = await fetchChallengeLessonData(nextByProgress)
|
|
1058
1058
|
if(challenge.lesson.is_locked) {
|
|
1059
|
-
|
|
1060
|
-
|
|
1059
|
+
const timeRemaining = getTimeRemainingUntilLocal(challenge.lesson.unlock_date, {withTotalSeconds:true})
|
|
1060
|
+
data.is_locked = true
|
|
1061
|
+
data.time_remaining_seconds = timeRemaining.totalSeconds
|
|
1062
|
+
ctaText = 'Next lesson in ' + timeRemaining.formatted
|
|
1061
1063
|
}
|
|
1062
1064
|
}
|
|
1063
1065
|
}
|
|
@@ -1097,6 +1099,7 @@ async function processContentItem(item) {
|
|
|
1097
1099
|
},
|
|
1098
1100
|
cta: {
|
|
1099
1101
|
text: ctaText,
|
|
1102
|
+
timeRemainingToUnlockSeconds: data.time_remaining_seconds ?? null,
|
|
1100
1103
|
action: {
|
|
1101
1104
|
type: data.type,
|
|
1102
1105
|
brand: data.brand,
|
|
@@ -1272,7 +1275,7 @@ export async function pinProgressRow(brand, id, progressType) {
|
|
|
1272
1275
|
const url = `/api/user-management-system/v1/progress/pin?brand=${brand}&id=${id}&progressType=${progressType}`;
|
|
1273
1276
|
const response = await fetchHandler(url, 'PUT', null)
|
|
1274
1277
|
if (response && !response.error) {
|
|
1275
|
-
updatePinnedProgressRow(brand, {
|
|
1278
|
+
await updatePinnedProgressRow(brand, {
|
|
1276
1279
|
id,
|
|
1277
1280
|
progressType,
|
|
1278
1281
|
pinnedAt: new Date().toISOString(),
|
|
@@ -1295,20 +1298,22 @@ export async function unpinProgressRow(brand) {
|
|
|
1295
1298
|
const url = `/api/user-management-system/v1/progress/unpin?brand=${brand}`
|
|
1296
1299
|
const response = await fetchHandler(url, 'PUT', null)
|
|
1297
1300
|
if (response && !response.error) {
|
|
1298
|
-
updatePinnedProgressRow(brand, null)
|
|
1301
|
+
await updatePinnedProgressRow(brand, null)
|
|
1299
1302
|
}
|
|
1300
1303
|
return response
|
|
1301
1304
|
}
|
|
1302
1305
|
|
|
1303
|
-
function updatePinnedProgressRow(brand, pinnedData) {
|
|
1304
|
-
const
|
|
1306
|
+
async function updatePinnedProgressRow(brand, pinnedData) {
|
|
1307
|
+
const userRaw = await globalConfig.localStorage.getItem('user');
|
|
1308
|
+
const user = userRaw ? JSON.parse(userRaw) : {};
|
|
1305
1309
|
user.brand_pinned_progress = user.brand_pinned_progress || {}
|
|
1306
1310
|
user.brand_pinned_progress[brand] = pinnedData
|
|
1307
|
-
globalConfig.localStorage.setItem('user', JSON.stringify(user))
|
|
1311
|
+
await globalConfig.localStorage.setItem('user', JSON.stringify(user))
|
|
1308
1312
|
}
|
|
1309
1313
|
|
|
1310
1314
|
async function extractPinnedItem({brand, progressMap, playlistItems}) {
|
|
1311
|
-
const
|
|
1315
|
+
const userRaw = await globalConfig.localStorage.getItem('user');
|
|
1316
|
+
const user = userRaw ? JSON.parse(userRaw) : {};
|
|
1312
1317
|
user.brand_pinned_progress = user.brand_pinned_progress || {}
|
|
1313
1318
|
|
|
1314
1319
|
const pinned = user.brand_pinned_progress[brand]
|