From 8a45f2156ac6a9b70396ec4fc4dc14604d9dc89d Mon Sep 17 00:00:00 2001 From: Sant Parkash Singh Date: Sun, 2 Jun 2024 13:03:25 -0700 Subject: [PATCH 1/3] feat: configurable intelligent spacebar Intelligent spacebar can now be turned on/off in settings. --- www/configs/user-settings.json | 6 ++- www/locales/en.json | 1 + www/main/navigator/shabad/ShabadContent.jsx | 49 ++++++++++++--------- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/www/configs/user-settings.json b/www/configs/user-settings.json index 203954ff..740c8a3c 100644 --- a/www/configs/user-settings.json +++ b/www/configs/user-settings.json @@ -73,7 +73,7 @@ "other-options": { "title": "OTHER_OPTIONS", "type": "switch", - "settings": ["limit-change-log", "statistics"] + "settings": ["limit-change-log", "statistics", "intelligent-spacebar"] } }, "settings": { @@ -268,6 +268,10 @@ "title": "AUTO_PLAY", "initialValue": false }, + "intelligent-spacebar":{ + "title": "INTELLIGENT_SPACEBAR", + "initialValue": true + }, "autoplay-delay": { "title": "DELAY", "type": "range", diff --git a/www/locales/en.json b/www/locales/en.json index 8d443945..a716c8ee 100644 --- a/www/locales/en.json +++ b/www/locales/en.json @@ -323,6 +323,7 @@ "LEFT_ALIGN": "Left-Align", "NEXT_LINE": "Next Line", "AUTOPLAY_OPTIONS": "Autoplay Options", + "INTELLIGENT_SPACEBAR": "Intelligent Spacebar", "AUTO_PLAY": "Auto Play", "DELAY": "Delay (Seconds)", "BANI_SETTINGS": "Bani Settings", diff --git a/www/main/navigator/shabad/ShabadContent.jsx b/www/main/navigator/shabad/ShabadContent.jsx index ef7f130c..618daffb 100644 --- a/www/main/navigator/shabad/ShabadContent.jsx +++ b/www/main/navigator/shabad/ShabadContent.jsx @@ -49,7 +49,7 @@ const ShabadContent = () => { } = useStoreActions((state) => state.navigator); // mangalPosition was removed from below settings - const { autoplayToggle, autoplayDelay, baniLength, liveFeed } = useStoreState( + const { autoplayToggle, autoplayDelay, baniLength, liveFeed, intelligentSpacebar } = useStoreState( (state) => state.userSettings, ); @@ -101,21 +101,21 @@ const ShabadContent = () => { const regex = checkPauri.length > 1 ? /]\d*]/ : /]/; return versesNew ? versesNew.map((verse, index) => { - if (verse) { - const verseObj = { - ID: index, - verseId: verse.ID, - verse: verse.Gurmukhi, - english: verse.English ? verse.English : '', - lineNo: currentLine, - crossPlatformId: verse.crossPlatformID ? verse.crossPlatformID : '', - }; - // eslint-disable-next-line no-unused-expressions - regex.test(verse.Gurmukhi) && currentLine++; - return verseObj; - } - return {}; - }) + if (verse) { + const verseObj = { + ID: index, + verseId: verse.ID, + verse: verse.Gurmukhi, + english: verse.English ? verse.English : '', + lineNo: currentLine, + crossPlatformId: verse.crossPlatformID ? verse.crossPlatformID : '', + }; + // eslint-disable-next-line no-unused-expressions + regex.test(verse.Gurmukhi) && currentLine++; + return verseObj; + } + return {}; + }) : []; } }; @@ -265,8 +265,19 @@ const ShabadContent = () => { const currentVerseIndex = mappedShabadArray.findIndex( ({ verseId }) => verseId === activeVerseId, ); - let nextVerseIndex; + let nextVerseIndex = homeVerse; + + if (intelligentSpacebar) { + nextVerseIndex = handleIntelligentSpacebar(nextVerseIndex, mappedShabadArray, currentVerseIndex); + } + + const nextVerseId = mappedShabadArray[nextVerseIndex].verseId; + scrollToVerse(nextVerseId); + updateTraversedVerse(nextVerseId, nextVerseIndex); + } + + function handleIntelligentSpacebar(nextVerseIndex, mappedShabadArray, currentVerseIndex) { if (atHome) { if (previousVerseIndex !== null) { nextVerseIndex = previousVerseIndex + 1; @@ -298,9 +309,7 @@ const ShabadContent = () => { setPreviousIndex(nextVerseIndex); } } - const nextVerseId = mappedShabadArray[nextVerseIndex].verseId; - scrollToVerse(nextVerseId); - updateTraversedVerse(nextVerseId, nextVerseIndex); + return nextVerseIndex; } }; From aa4431e07441f02d53b15b8484a76d3f28eeddbe Mon Sep 17 00:00:00 2001 From: Yadvir Kaur Date: Tue, 2 Jul 2024 19:49:46 +0530 Subject: [PATCH 2/3] add setting to turn off intelligent spacebar in multi-pane --- www/configs/user-settings.json | 4 +-- www/main/navigator/shabad/ShabadText.jsx | 3 ++- .../navigator/shabad/utils/change-verse.js | 26 ++++++++++++++++--- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/www/configs/user-settings.json b/www/configs/user-settings.json index 740c8a3c..bf24e198 100644 --- a/www/configs/user-settings.json +++ b/www/configs/user-settings.json @@ -68,12 +68,12 @@ "app-layout": { "title": "APP_SETTINGS", "type": "switch", - "settings": ["quick-tools", "shortcut-tray", "live-feed"] + "settings": ["quick-tools", "shortcut-tray", "live-feed", "intelligent-spacebar"] }, "other-options": { "title": "OTHER_OPTIONS", "type": "switch", - "settings": ["limit-change-log", "statistics", "intelligent-spacebar"] + "settings": ["limit-change-log", "statistics"] } }, "settings": { diff --git a/www/main/navigator/shabad/ShabadText.jsx b/www/main/navigator/shabad/ShabadText.jsx index 7b5bf91b..26bb9258 100644 --- a/www/main/navigator/shabad/ShabadText.jsx +++ b/www/main/navigator/shabad/ShabadText.jsx @@ -52,7 +52,7 @@ export const ShabadText = ({ shortcuts, } = useStoreState((state) => state.navigator); - const { baniLength, liveFeed, autoplayDelay, autoplayToggle } = useStoreState( + const { baniLength, liveFeed, autoplayDelay, autoplayToggle, intelligentSpacebar } = useStoreState( (state) => state.userSettings, ); @@ -235,6 +235,7 @@ export const ShabadText = ({ atHome, setHome, homeVerse: paneAttributes.homeVerse, + intelligentSpacebar, }); if (verse) { updateTraversedVerse(verse.verseId, verse.verseIndex); diff --git a/www/main/navigator/shabad/utils/change-verse.js b/www/main/navigator/shabad/utils/change-verse.js index c4557882..ddc9d293 100644 --- a/www/main/navigator/shabad/utils/change-verse.js +++ b/www/main/navigator/shabad/utils/change-verse.js @@ -119,11 +119,18 @@ const skipMangla = (shabadVerses, index) => { export const intelligentNextVerse = ( filteredItems, - { activeVerseId, previousVerseIndex, setPreviousIndex, atHome, setHome, homeVerse }, + { + activeVerseId, + previousVerseIndex, + setPreviousIndex, + atHome, + setHome, + homeVerse, + intelligentSpacebar, + }, ) => { - if (homeVerse) { - const currentVerseIndex = filteredItems.findIndex(({ verseId }) => verseId === activeVerseId); - let nextVerseIndex; + function handleIntelligentSpacebar(nextIndex, currentVerseIndex) { + let nextVerseIndex = nextIndex; if (atHome) { if (previousVerseIndex !== null) { @@ -156,6 +163,17 @@ export const intelligentNextVerse = ( setPreviousIndex(nextVerseIndex); } } + return nextVerseIndex; + } + + if (homeVerse) { + const currentVerseIndex = filteredItems.findIndex(({ verseId }) => verseId === activeVerseId); + let nextVerseIndex = homeVerse; + + if (intelligentSpacebar) { + nextVerseIndex = handleIntelligentSpacebar(nextVerseIndex, currentVerseIndex); + } + const nextVerseId = filteredItems[nextVerseIndex].verseId; return { verseId: nextVerseId, verseIndex: nextVerseIndex }; } From 5a005058e9983738540fae5f8685c69863f8b792 Mon Sep 17 00:00:00 2001 From: Yadvir Kaur Date: Mon, 8 Jul 2024 11:46:14 +0530 Subject: [PATCH 3/3] minor changes in intelligent spacebar --- www/main/navigator/shabad/ShabadContent.jsx | 40 +++++++++---------- .../navigator/shabad/utils/change-verse.js | 2 +- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/www/main/navigator/shabad/ShabadContent.jsx b/www/main/navigator/shabad/ShabadContent.jsx index 618daffb..62fd3fcc 100644 --- a/www/main/navigator/shabad/ShabadContent.jsx +++ b/www/main/navigator/shabad/ShabadContent.jsx @@ -258,26 +258,7 @@ const ShabadContent = () => { }; const toggleHomeVerse = () => { - if (isSundarGutkaBani || isCeremonyBani) { - openNextVerse(); - } else if (homeVerse) { - const mappedShabadArray = filterRequiredVerseItems(activeShabad); - const currentVerseIndex = mappedShabadArray.findIndex( - ({ verseId }) => verseId === activeVerseId, - ); - - let nextVerseIndex = homeVerse; - - if (intelligentSpacebar) { - nextVerseIndex = handleIntelligentSpacebar(nextVerseIndex, mappedShabadArray, currentVerseIndex); - } - - const nextVerseId = mappedShabadArray[nextVerseIndex].verseId; - scrollToVerse(nextVerseId); - updateTraversedVerse(nextVerseId, nextVerseIndex); - } - - function handleIntelligentSpacebar(nextVerseIndex, mappedShabadArray, currentVerseIndex) { + const handleIntelligentSpacebar = (nextVerseIndex, mappedShabadArray, currentVerseIndex) => { if (atHome) { if (previousVerseIndex !== null) { nextVerseIndex = previousVerseIndex + 1; @@ -311,6 +292,25 @@ const ShabadContent = () => { } return nextVerseIndex; } + + if (isSundarGutkaBani || isCeremonyBani) { + openNextVerse(); + } else if (homeVerse) { + const mappedShabadArray = filterRequiredVerseItems(activeShabad); + const currentVerseIndex = mappedShabadArray.findIndex( + ({ verseId }) => verseId === activeVerseId, + ); + + let nextVerseIndex = homeVerse; + + if (intelligentSpacebar) { + nextVerseIndex = handleIntelligentSpacebar(nextVerseIndex, mappedShabadArray, currentVerseIndex); + } + + const nextVerseId = mappedShabadArray[nextVerseIndex].verseId; + scrollToVerse(nextVerseId); + updateTraversedVerse(nextVerseId, nextVerseIndex); + } }; const changeHomeVerse = (verseIndex) => { diff --git a/www/main/navigator/shabad/utils/change-verse.js b/www/main/navigator/shabad/utils/change-verse.js index ddc9d293..4fc969ac 100644 --- a/www/main/navigator/shabad/utils/change-verse.js +++ b/www/main/navigator/shabad/utils/change-verse.js @@ -129,7 +129,7 @@ export const intelligentNextVerse = ( intelligentSpacebar, }, ) => { - function handleIntelligentSpacebar(nextIndex, currentVerseIndex) { + const handleIntelligentSpacebar = (nextIndex, currentVerseIndex) => { let nextVerseIndex = nextIndex; if (atHome) {