Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
hummingly committed Apr 4, 2019
1 parent 4a90092 commit 0ce87ff
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 44 deletions.
25 changes: 8 additions & 17 deletions src/renderer/frontend/components/FileTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,13 @@ interface IFileTagProps {
const Single = observer(({ file }: { file: ClientFile }) => {
const { tagStore } = useContext(StoreContext);

const handleClear = useCallback(
() => file.tags.clear(),
[file],
);
const handleClear = useCallback(() => file.tags.clear(), [file]);

const handleDeselect = useCallback(
(index) => file.tags.splice(index, 1),
[file],
);
const handleDeselect = useCallback((index) => file.tags.splice(index, 1), [
file,
]);

const handleSelect = useCallback(
(tag) => file.tags.push(tag.id),
[file],
);
const handleSelect = useCallback((tag) => file.tags.push(tag.id), [file]);

const handleCreate = useCallback(
(name: string) => {
Expand Down Expand Up @@ -57,13 +50,11 @@ const Multi = observer(({ files }: IFileTagProps) => {
combinedTags.forEach((t) => countMap.set(t, (countMap.get(t) || 0) + 1));

// Sort based on count
// tslint:disable-next-line: newline-per-chained-call
const sortedTags = Array.from(countMap.entries()).sort((a, b) => b[1] - a[1]);

const handleClear = useCallback(
() => files.forEach((f) => f.tags.clear()),
[files],
);
const handleClear = useCallback(() => files.forEach((f) => f.tags.clear()), [
files,
]);

const handleSelect = useCallback(
(tag: ClientTag) => files.forEach((f) => f.tags.push(tag.id)),
Expand Down
36 changes: 20 additions & 16 deletions src/renderer/frontend/components/Gallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ const Gallery = ({
}: IGalleryProps) => {
// Todo: Maybe move these to UiStore so that it can be reset when the fileList changes?
/** The first item that is selected in a multi-selection */
const [initialSelectionIndex, setInitialSelectionIndex] = useState<number | undefined>(undefined);
const [initialSelectionIndex, setInitialSelectionIndex] = useState<
number | undefined
>(undefined);
/** The last item that is selected in a multi-selection */
const [lastSelectionIndex, setLastSelectionIndex] = useState<number | undefined>(undefined);
const [lastSelectionIndex, setLastSelectionIndex] = useState<
number | undefined
>(undefined);

const selectionModeOn = uiStore.fileSelection.length > 0;

Expand Down Expand Up @@ -61,7 +65,9 @@ const Gallery = ({
uiStore.selectFile(fileList[Math.max(0, lastSelectionIndex - 1)]);
} else if (e.key === 'ArrowRight' || e.key === 'ArrowDown') {
uiStore.fileSelection.clear();
uiStore.selectFile(fileList[Math.min(fileList.length - 1, lastSelectionIndex + 1)]);
uiStore.selectFile(
fileList[Math.min(fileList.length - 1, lastSelectionIndex + 1)],
);
}
};

Expand All @@ -74,19 +80,17 @@ const Gallery = ({

return (
<div className={`${selectionModeOn ? 'gallerySelectionMode' : ''}`}>
{
fileList.map((file, fileIndex) => (
<GalleryItem
key={`file-${file.id}`}
file={file}
isSelected={uiStore.fileSelection.includes(file.id)}
onRemoveTag={(tag) => file.removeTag(tag.id)}
onSelect={(f, e) => onSelect(fileIndex, e)}
onDeselect={(f) => uiStore.deselectFile(f)}
onDrop={(tag) => file.addTag(tag.id)}
/>
))
}
{fileList.map((file, fileIndex) => (
<GalleryItem
key={`file-${file.id}`}
file={file}
isSelected={uiStore.fileSelection.includes(file.id)}
onRemoveTag={(tag) => file.removeTag(tag.id)}
onSelect={(f, e) => onSelect(fileIndex, e)}
onDeselect={(f) => uiStore.deselectFile(f)}
onDrop={(tag) => file.addTag(tag.id)}
/>
))}
</div>
);
};
Expand Down
23 changes: 13 additions & 10 deletions src/renderer/frontend/components/MultiTagSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ const filterTag: ItemPredicate<ClientTag> = (query, tag, index, exactMatch) => {
const normalizedQuery = query.toLowerCase();

if (exactMatch) {
return normalizedName === normalizedQuery;
return normalizedName === normalizedQuery;
} else {
return normalizedName.indexOf(normalizedQuery) >= 0;
return normalizedName.indexOf(normalizedQuery) >= 0;
}
};

Expand Down Expand Up @@ -77,12 +77,13 @@ const MultiTagSelector = ({
);

// Todo: Might need a confirmation pop over
const ClearButton = useMemo(() =>
selectedTags.length > 0 ? (
<Button icon="cross" minimal={true} onClick={onClearSelection} />
) : (
undefined
),
const ClearButton = useMemo(
() =>
selectedTags.length > 0 ? (
<Button icon="cross" minimal={true} onClick={onClearSelection} />
) : (
undefined
),
[selectedTags],
);

Expand All @@ -106,7 +107,7 @@ const MultiTagSelector = ({
[selectedTags],
);

const TagLabel = (tag: ClientTag) => tagLabel ? tagLabel(tag) : tag.name;
const TagLabel = (tag: ClientTag) => (tagLabel ? tagLabel(tag) : tag.name);

// Only used for visualization in the selector, an actual ClientTag is created onSelect
const createNewTag = useCallback(
Expand All @@ -115,7 +116,9 @@ const MultiTagSelector = ({
);

const maybeCreateNewItemFromQuery = onTagCreation ? createNewTag : undefined;
const maybeCreateNewItemRenderer = onTagCreation ? renderCreateTagOption : undefined;
const maybeCreateNewItemRenderer = onTagCreation
? renderCreateTagOption
: undefined;

return (
<>
Expand Down
1 change: 0 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"indent": [true, "spaces", 2],
"member-access": [false, "warning"],
"ordered-imports": [false, "warning"],
"newline-per-chained-call": true
},
"jsRules": {
"max-line-length": {
Expand Down

0 comments on commit 0ce87ff

Please sign in to comment.