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

feat: add setting to turn off intelligent spacebar #1960

Closed
wants to merge 1 commit into from
Closed
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
feat: configurable intelligent spacebar
Intelligent spacebar can now be turned on/off in settings.
  • Loading branch information
singh-sp committed Jun 2, 2024
commit 8a45f2156ac6a9b70396ec4fc4dc14604d9dc89d
6 changes: 5 additions & 1 deletion www/configs/user-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"other-options": {
"title": "OTHER_OPTIONS",
"type": "switch",
"settings": ["limit-change-log", "statistics"]
"settings": ["limit-change-log", "statistics", "intelligent-spacebar"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small change, Instead of other options, can you please move this setting to App Settings.

}
},
"settings": {
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
49 changes: 29 additions & 20 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 @@ -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;
Expand Down Expand Up @@ -298,9 +309,7 @@ const ShabadContent = () => {
setPreviousIndex(nextVerseIndex);
}
}
const nextVerseId = mappedShabadArray[nextVerseIndex].verseId;
scrollToVerse(nextVerseId);
updateTraversedVerse(nextVerseId, nextVerseIndex);
return nextVerseIndex;
}
};

Expand Down