Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting to turn off intelligent spacebar in Multi-Pane #1989

Merged
merged 3 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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",
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 @@ -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,
);

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

const handleIntelligentSpacebar = (nextVerseIndex, mappedShabadArray, currentVerseIndex) => {
if (atHome) {
if (previousVerseIndex !== null) {
nextVerseIndex = previousVerseIndex + 1;
Expand Down Expand Up @@ -298,6 +290,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 @@ -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,
);

Expand Down Expand Up @@ -235,6 +235,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 @@ -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;
const handleIntelligentSpacebar = (nextIndex, currentVerseIndex) => {
let nextVerseIndex = nextIndex;

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