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 match file enumeration & sorting #181

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
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ function FilterPaneHeader(props) {

useEffect(() => {
if (autoFocus) {
console.log("Focusing", buttonRef.current);
buttonRef.current.focus();
// setTimeout(() => );
buttonRef.current?.focus();
}
}, [autoFocus, buttonRef]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ const useStyles = makeStyles((theme) => ({
},
}));

/**
* Compare two matches.
*/
function matchComparator(first, second) {
if (first.distance < second.distance) {
return -1;
} else if (first.distance > second.distance) {
return 1;
} else {
return String(first.file.filename).localeCompare(second.file.filename);
}
}

/**
* Get i18n text.
*/
Expand All @@ -64,13 +77,15 @@ function MatchFiles(props) {
const messages = useMessages();

const {
matches,
matches: loadedMatches,
error: matchError,
loadMatches,
hasMore,
progress,
} = useDirectMatches(motherFileId);

const matches = loadedMatches.sort(matchComparator);

// Move to the first element when matches are loaded
useEffect(() => {
if (!hasMore && matches.length > 0 && matchFileId == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ const useStyles = makeStyles((theme) => ({
},
formControl: {
width: 300,
marginLeft: theme.spacing(2),
},
button: {
marginLeft: theme.spacing(1),
},
index: {
...theme.mixins.text,
},
}));

/**
Expand Down Expand Up @@ -60,8 +64,15 @@ function MatchSelector(props) {
selected,
]);

const showSelected = matches.length > 0 && selected >= 0;

return (
<div className={clsx(classes.root, className)}>
{showSelected && (
<div className={classes.index}>
{selected + 1} of {matches.length}
</div>
)}
<FormControl
variant="outlined"
className={classes.formControl}
Expand All @@ -70,7 +81,7 @@ function MatchSelector(props) {
<InputLabel id={labelId}>{messages.label}</InputLabel>
<Select
labelId={labelId}
value={matches.length > 0 && selected >= 0 ? selected : ""}
value={showSelected ? selected : ""}
onChange={handleSelect}
label={messages.label}
disabled={matches.length === 0}
Expand Down