Skip to content

Commit 4a6eb99

Browse files
1ilitewqazxc
authored andcommitted
Fix getting the correct version to compare to (drawdb-io#851)
1 parent f15835a commit 4a6eb99

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/components/EditorHeader/SideSheet/Versions.jsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,19 +229,24 @@ export default function Versions({ open, title, setTitle }) {
229229

230230
const getVersionToCompareTo = useCallback(async () => {
231231
if (!selectedVersion) return null;
232+
232233
const currentIndex = versions.findIndex(
233234
(v) => v.version === selectedVersion,
234235
);
235236

236237
if (currentIndex === -1) return null;
237238

238-
if (currentIndex === versions.length - 1) {
239+
if (currentIndex === versions.length - 1 && hasMore) {
239240
const res = await getCommitsWithFile(gistId, VERSION_FILENAME, 1, cursor);
241+
const version = res.data.length ? res.data[0].version : "null";
242+
243+
if (version === selectedVersion) return null;
240244

241-
return res.data.length ? res.data[0].version : null;
245+
return version;
246+
} else {
247+
return versions[currentIndex + 1]?.version || "null";
242248
}
243-
return versions[currentIndex + 1].version;
244-
}, [selectedVersion, versions, gistId, cursor]);
249+
}, [selectedVersion, versions, gistId, cursor, hasMore]);
245250

246251
useEffect(() => {
247252
const getVersionToCompare = async () => {

0 commit comments

Comments
 (0)