Skip to content

Commit 3df4d43

Browse files
committed
Support checking all
1 parent cb32885 commit 3df4d43

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

resources/scripts/components/server/files/FileManagerBreadcrumbs.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { ServerContext } from '@/state/server';
33
import { NavLink } from 'react-router-dom';
44
import { cleanDirectoryPath } from '@/helpers';
55
import tw from 'twin.macro';
6+
import { FileActionCheckbox } from '@/components/server/files/SelectFileCheckbox';
7+
import useFileManagerSwr from '@/plugins/useFileManagerSwr';
68

79
interface Props {
810
withinFileEditor?: boolean;
@@ -14,6 +16,10 @@ export default ({ withinFileEditor, isNewFile }: Props) => {
1416
const id = ServerContext.useStoreState(state => state.server.data!.id);
1517
const directory = ServerContext.useStoreState(state => state.files.directory);
1618

19+
const { data: files } = useFileManagerSwr();
20+
const setSelectedFiles = ServerContext.useStoreActions(actions => actions.files.setSelectedFiles);
21+
const selectedFilesLength = ServerContext.useStoreState(state => state.files.selectedFiles.length);
22+
1723
useEffect(() => {
1824
const parts = cleanDirectoryPath(window.location.hash).split('/');
1925

@@ -32,8 +38,20 @@ export default ({ withinFileEditor, isNewFile }: Props) => {
3238
return { name: decodeURIComponent(directory), path: `/${dirs.slice(0, index + 1).join('/')}` };
3339
});
3440

41+
const onSelectAllClick = (e: React.ChangeEvent<HTMLInputElement>) => {
42+
setSelectedFiles(e.currentTarget.checked ? (files?.map(file => file.name) || []) : []);
43+
};
44+
3545
return (
3646
<div css={tw`flex items-center text-sm mb-4 text-neutral-500`}>
47+
{!!(files && files.length) &&
48+
<FileActionCheckbox
49+
type={'checkbox'}
50+
css={tw`mx-4`}
51+
checked={selectedFilesLength === (files ? files.length : -1)}
52+
onChange={onSelectAllClick}
53+
/>
54+
}
3755
/<span css={tw`px-1 text-neutral-300`}>home</span>/
3856
<NavLink
3957
to={`/server/${id}/files`}

resources/scripts/components/server/files/SelectFileCheckbox.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ServerContext } from '@/state/server';
44
import styled from 'styled-components/macro';
55
import Input from '@/components/elements/Input';
66

7-
const Checkbox = styled(Input)`
7+
export const FileActionCheckbox = styled(Input)`
88
&& {
99
${tw`border-neutral-500`};
1010
@@ -21,7 +21,7 @@ export default ({ name }: { name: string }) => {
2121

2222
return (
2323
<label css={tw`flex-none p-4 absolute self-center z-30 cursor-pointer`}>
24-
<Checkbox
24+
<FileActionCheckbox
2525
name={'selectedFiles'}
2626
value={name}
2727
checked={isChecked}

0 commit comments

Comments
 (0)