Skip to content

Commit

Permalink
Merge pull request #1989 from yadvirkaur/intelliSpacebar
Browse files Browse the repository at this point in the history
Add setting to turn off intelligent spacebar in Multi-Pane
  • Loading branch information
Gauravjeetsingh authored Jul 31, 2024
2 parents 5131a7c + 5a00505 commit c606079
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 31 deletions.
6 changes: 5 additions & 1 deletion www/configs/user-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"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",
Expand Down Expand Up @@ -268,6 +268,10 @@
"title": "AUTO_PLAY",
"initialValue": false
},
"intelligent-spacebar":{
"title": "INTELLIGENT_SPACEBAR",
"initialValue": true
},
"autoplay-delay": {
"title": "DELAY",
"type": "range",
Expand Down
1 change: 1 addition & 0 deletions www/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,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",
Expand Down
59 changes: 34 additions & 25 deletions www/main/navigator/shabad/ShabadContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,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,
);

Expand Down Expand Up @@ -102,21 +102,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 {};
})
: [];
}
};
Expand Down Expand Up @@ -259,15 +259,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;

const handleIntelligentSpacebar = (nextVerseIndex, mappedShabadArray, currentVerseIndex) => {
if (atHome) {
if (previousVerseIndex !== null) {
nextVerseIndex = previousVerseIndex + 1;
Expand Down Expand Up @@ -299,6 +291,23 @@ const ShabadContent = () => {
setPreviousIndex(nextVerseIndex);
}
}
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);
Expand Down
3 changes: 2 additions & 1 deletion www/main/navigator/shabad/ShabadText.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const ShabadText = ({
lineNumber,
} = useStoreState((state) => state.navigator);

const { baniLength, liveFeed, autoplayDelay, autoplayToggle } = useStoreState(
const { baniLength, liveFeed, autoplayDelay, autoplayToggle, intelligentSpacebar } = useStoreState(
(state) => state.userSettings,
);

Expand Down Expand Up @@ -273,6 +273,7 @@ export const ShabadText = ({
atHome,
setHome,
homeVerse: paneAttributes.homeVerse,
intelligentSpacebar,
});
if (verse) {
updateTraversedVerse(verse.verseId, verse.verseIndex);
Expand Down
26 changes: 22 additions & 4 deletions www/main/navigator/shabad/utils/change-verse.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,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;
const handleIntelligentSpacebar = (nextIndex, currentVerseIndex) => {
let nextVerseIndex = nextIndex;

if (atHome) {
if (previousVerseIndex !== null) {
Expand Down Expand Up @@ -202,6 +209,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 };
}
Expand Down

0 comments on commit c606079

Please sign in to comment.