2020-07-11 23:57:30 +00:00
|
|
|
import React from 'react';
|
|
|
|
import tw from 'twin.macro';
|
|
|
|
import { ServerContext } from '@/state/server';
|
|
|
|
import styled from 'styled-components/macro';
|
|
|
|
import Input from '@/components/elements/Input';
|
|
|
|
|
2020-07-12 00:09:54 +00:00
|
|
|
export const FileActionCheckbox = styled(Input)`
|
2020-07-11 23:57:30 +00:00
|
|
|
&& {
|
2020-12-27 18:44:56 +00:00
|
|
|
${tw`border-neutral-500 bg-transparent`};
|
2022-06-26 19:13:52 +00:00
|
|
|
|
2020-07-11 23:57:30 +00:00
|
|
|
&:not(:checked) {
|
|
|
|
${tw`hover:border-neutral-300`};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
export default ({ name }: { name: string }) => {
|
2022-06-26 19:13:52 +00:00
|
|
|
const isChecked = ServerContext.useStoreState((state) => state.files.selectedFiles.indexOf(name) >= 0);
|
|
|
|
const appendSelectedFile = ServerContext.useStoreActions((actions) => actions.files.appendSelectedFile);
|
|
|
|
const removeSelectedFile = ServerContext.useStoreActions((actions) => actions.files.removeSelectedFile);
|
2020-07-11 23:57:30 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<label css={tw`flex-none p-4 absolute self-center z-30 cursor-pointer`}>
|
2020-07-12 00:09:54 +00:00
|
|
|
<FileActionCheckbox
|
2020-07-11 23:57:30 +00:00
|
|
|
name={'selectedFiles'}
|
|
|
|
value={name}
|
|
|
|
checked={isChecked}
|
|
|
|
type={'checkbox'}
|
|
|
|
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
|
if (e.currentTarget.checked) {
|
|
|
|
appendSelectedFile(name);
|
|
|
|
} else {
|
|
|
|
removeSelectedFile(name);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</label>
|
|
|
|
);
|
|
|
|
};
|