Skip to content

Commit c2ea59f

Browse files
Sort order
1 parent fd077d1 commit c2ea59f

File tree

3 files changed

+75
-9
lines changed

3 files changed

+75
-9
lines changed

src/components/file/helpers.js

+65-6
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,73 @@ export const saveFile = async ({
7575
return response;
7676
};
7777

78-
export const manifestFileComparer = async({
78+
const REGEX_TSV_BOOK_ABBREVIATION = /^\w*_(\w*)\.tsv$/i;
79+
80+
export const manifestFileComparer = ({
7981
repository, item1, item2,
8082
}) => {
81-
alert(JSON.stringify(repository));
83+
let compare = 0;
84+
85+
if (item1 && item2 && repository && repository.books)
86+
{
87+
const book1Matches = item1.match(REGEX_TSV_BOOK_ABBREVIATION);
88+
const book2Matches = item2.match(REGEX_TSV_BOOK_ABBREVIATION);
8289

83-
return 0;
90+
const isTsvFiles = (book1Matches && book2Matches)?true:false;
91+
if (isTsvFiles)
92+
{
93+
const book1 = book1Matches[1];
94+
const book2 = book2Matches[1];
95+
96+
let iiBook1 = 0;
97+
let iiBook2 = 0;
98+
for (let ii=0; ii < repository.books.length; ii++)
99+
{
100+
if (repository.books[ii].toLowerCase() == book1.toLowerCase())
101+
{
102+
iiBook1 = ii;
103+
}
104+
if (repository.books[ii].toLowerCase() == book2.toLowerCase())
105+
{
106+
iiBook2 = ii;
107+
}
108+
}
109+
110+
if (iiBook1 < iiBook2)
111+
{
112+
compare = -1;
113+
}
114+
else if (iiBook2 < iiBook1)
115+
{
116+
compare = 1;
117+
}
118+
else
119+
{
120+
compare = 0;
121+
}
122+
}
123+
else // BOTH are NOT TSV file: (could be manifest file).
124+
{
125+
if (book1Matches)
126+
{
127+
// Book1 is a TSV, but book2 is a non-TSV file.
128+
return 1;
129+
}
130+
else if (book2Matches)
131+
{
132+
// Book2 is the TSV file; but book1 is NOT.
133+
return -1;
134+
}
135+
else
136+
{
137+
compare = item1.localeCompare(item2);
138+
}
139+
}
140+
}
141+
else // item1/item2 don't exist:
142+
{
143+
compare = 0;
144+
}
84145

85-
// contentObject = await readContent({
86-
// owner, repo, ref: branch, filepath, config,
87-
// });
146+
return compare;
88147
};

src/components/file/useFile.js

-2
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,6 @@ function useFile({
174174
if (create) {
175175
component = components.create;
176176
} else {
177-
alert("!! browse\n\n" + JSON.stringify(repository));
178-
console.log(repository);
179177
component = components.browse;
180178
}
181179
}

src/components/tree-blob/useBlob.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React, { useState, useCallback, useMemo } from 'react';
22
import PropTypes from 'prop-types';
33
import deepFreeze from 'deep-freeze';
44

5+
import {manifestFileComparer} from '../file/helpers';
6+
57
import { Tree } from '.';
68

79
function useBlob({
@@ -27,6 +29,12 @@ function useBlob({
2729
update();
2830
}, [update]);
2931

32+
const tsvManifestFileComparer = useCallback((item1,item2) => {
33+
const item1Path = item1?.path;
34+
const item2Path = item2?.path;
35+
return manifestFileComparer({repository, item1: item1Path, item2: item2Path});
36+
}, [manifestFileComparer]);
37+
3038
const browse = useMemo(() => {
3139
return (tree || url) ? (
3240
<Tree
@@ -35,9 +43,10 @@ function useBlob({
3543
config={config}
3644
selected={true}
3745
onBlob={update}
46+
comparer={tsvManifestFileComparer}
3847
/>
3948
) : (<></>);
40-
}, [tree, url, config, update]);
49+
}, [tree, url, config, update, repository?.name]);
4150

4251
return {
4352
state: blob,

0 commit comments

Comments
 (0)