Skip to content

Commit 257a51d

Browse files
authored
Merge pull request #2302 from Sefaria/bug/sc-31548/can-t-bookmark-a-text
chore: start fixing bookmarks Force merging due to failing playwright tests
2 parents 513271c + e6d2321 commit 257a51d

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

static/js/sefaria/sefaria.js

+18-8
Original file line numberDiff line numberDiff line change
@@ -2579,14 +2579,24 @@ _media: {},
25792579
return this._ApiPromise(Sefaria.apiHost + "/api/passages/" + refs.join("|"));
25802580
},
25812581
areVersionsEqual(savedVersion, currVersion) {
2582-
const checkEquality = (key) => {
2583-
//This is temporary for RTL - we check savedVersion?.[key] for old data and savedVersion?.[key]?.versionTitle for new data
2584-
//also we currently don't check the languageFamilyName to fit old data
2585-
const savedVersionTitle = savedVersion?.[key]?.versionTitle ?? savedVersion?.[key] ?? '';
2586-
const currVersionTitle = currVersion?.[key]?.versionTitle ?? currVersion?.[key] ?? '';
2587-
return savedVersionTitle === currVersionTitle;
2588-
}
2589-
return checkEquality("en") && checkEquality("he");
2582+
// Determines if two versions are equal, but we don't know what format the data is in so consider both old and new format.
2583+
// New format is an object with two props: 'versionTitle' and 'languageFamilyName', while old format is a string.
2584+
const checkEquality = (lang, prop) => {
2585+
const propValues = [savedVersion, currVersion].map(version => {
2586+
version = version?.[lang];
2587+
const propValue = typeof version === 'string' ? version : version?.[prop];
2588+
return propValue ?? "";
2589+
});
2590+
return propValues[0] === propValues[1];
2591+
}
2592+
for (const prop of ["versionTitle", "languageFamilyName"]) {
2593+
for (const lang of ["he", "en"]) {
2594+
if (!checkEquality(lang, prop)) {
2595+
return false;
2596+
}
2597+
}
2598+
}
2599+
return true;
25902600
},
25912601
getSavedItem: ({ ref, versions }) => {
25922602
return Sefaria.saved.items.find(s => s.ref === ref && Sefaria.areVersionsEqual(s.versions, versions));

0 commit comments

Comments
 (0)