|
@@ -1,8 +1,7 @@
|
|
import { FlexWrapper } from "@ente/shared/components/Container";
|
|
import { FlexWrapper } from "@ente/shared/components/Container";
|
|
import { ENTE_WEBSITE_LINK } from "@ente/shared/constants/urls";
|
|
import { ENTE_WEBSITE_LINK } from "@ente/shared/constants/urls";
|
|
-import { formatDate } from "@ente/shared/time/format";
|
|
|
|
import { convertBytesToHumanReadable } from "@ente/shared/utils/size";
|
|
import { convertBytesToHumanReadable } from "@ente/shared/utils/size";
|
|
-import { Box, Link, Typography, styled } from "@mui/material";
|
|
|
|
|
|
+import { Box, Link, Typography, Checkbox, styled } from "@mui/material";
|
|
import {
|
|
import {
|
|
DATE_CONTAINER_HEIGHT,
|
|
DATE_CONTAINER_HEIGHT,
|
|
GAP_BTW_TILES,
|
|
GAP_BTW_TILES,
|
|
@@ -23,8 +22,10 @@ import {
|
|
ListChildComponentProps,
|
|
ListChildComponentProps,
|
|
areEqual,
|
|
areEqual,
|
|
} from "react-window";
|
|
} from "react-window";
|
|
-import { EnteFile } from "types/file";
|
|
|
|
import { PublicCollectionGalleryContext } from "utils/publicCollectionGallery";
|
|
import { PublicCollectionGalleryContext } from "utils/publicCollectionGallery";
|
|
|
|
+import { formatDate, getDate, isSameDay } from "@ente/shared/time/format";
|
|
|
|
+import { handleSelectCreator } from "utils/photoFrame";
|
|
|
|
+import { EnteFile } from "types/file";
|
|
|
|
|
|
const A_DAY = 24 * 60 * 60 * 1000;
|
|
const A_DAY = 24 * 60 * 60 * 1000;
|
|
const FOOTER_HEIGHT = 90;
|
|
const FOOTER_HEIGHT = 90;
|
|
@@ -185,6 +186,10 @@ const NothingContainer = styled(ListItemContainer)`
|
|
justify-content: center;
|
|
justify-content: center;
|
|
`;
|
|
`;
|
|
|
|
|
|
|
|
+const SelectAllCheckBoxContainer = styled(Checkbox)<{ margin: number }>`
|
|
|
|
+ margin-left: ${(props) => props.margin}px;
|
|
|
|
+`;
|
|
|
|
+
|
|
interface Props {
|
|
interface Props {
|
|
height: number;
|
|
height: number;
|
|
width: number;
|
|
width: number;
|
|
@@ -265,6 +270,8 @@ export function PhotoList({
|
|
const shouldRefresh = useRef(false);
|
|
const shouldRefresh = useRef(false);
|
|
const listRef = useRef(null);
|
|
const listRef = useRef(null);
|
|
|
|
|
|
|
|
+ const [checkedDates, setCheckedDates] = useState({});
|
|
|
|
+
|
|
const fittableColumns = getFractionFittableColumns(width);
|
|
const fittableColumns = getFractionFittableColumns(width);
|
|
let columns = Math.floor(fittableColumns);
|
|
let columns = Math.floor(fittableColumns);
|
|
|
|
|
|
@@ -473,14 +480,6 @@ export function PhotoList({
|
|
});
|
|
});
|
|
};
|
|
};
|
|
|
|
|
|
- const isSameDay = (first, second) => {
|
|
|
|
- return (
|
|
|
|
- first.getFullYear() === second.getFullYear() &&
|
|
|
|
- first.getMonth() === second.getMonth() &&
|
|
|
|
- first.getDate() === second.getDate()
|
|
|
|
- );
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
const getPhotoListHeader = (photoListHeader) => {
|
|
const getPhotoListHeader = (photoListHeader) => {
|
|
return {
|
|
return {
|
|
...photoListHeader,
|
|
...photoListHeader,
|
|
@@ -722,6 +721,62 @@ export function PhotoList({
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ const notSelectedFiles = displayFiles?.filter(
|
|
|
|
+ (item) => !galleryContext.selectedFile[item.id]
|
|
|
|
+ );
|
|
|
|
+ const unselectedDates = [
|
|
|
|
+ ...new Set(notSelectedFiles?.map((item) => getDate(item))), // to get file's date which were manually unselected
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ const localSelectedFiles = displayFiles.filter(
|
|
|
|
+ // to get files which were manually selected
|
|
|
|
+ (item) => !unselectedDates.includes(getDate(item))
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ const localSelectedDates = [
|
|
|
|
+ ...new Set(localSelectedFiles?.map((item) => getDate(item))),
|
|
|
|
+ ]; // to get file's date which were manually selected
|
|
|
|
+
|
|
|
|
+ unselectedDates.forEach((date) => {
|
|
|
|
+ setCheckedDates((prev) => ({
|
|
|
|
+ ...prev,
|
|
|
|
+ [date]: false,
|
|
|
|
+ })); // To uncheck select all checkbox if any of the file on the date is unselected
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ localSelectedDates.map((date) => {
|
|
|
|
+ setCheckedDates((prev) => ({
|
|
|
|
+ ...prev,
|
|
|
|
+ [date]: true,
|
|
|
|
+ }));
|
|
|
|
+ // To check select all checkbox if all of the files on the date is selected manually
|
|
|
|
+ });
|
|
|
|
+ }, [galleryContext.selectedFile]);
|
|
|
|
+
|
|
|
|
+ const handleSelect = handleSelectCreator(
|
|
|
|
+ galleryContext.setSelectedFiles,
|
|
|
|
+ activeCollectionID
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ const onChangeSelectAllCheckBox = (date: string) => {
|
|
|
|
+ const dates = { ...checkedDates, [date]: !checkedDates[date] };
|
|
|
|
+ const isDateSelected = !checkedDates[date];
|
|
|
|
+
|
|
|
|
+ setCheckedDates(dates);
|
|
|
|
+
|
|
|
|
+ const filesOnADay = displayFiles?.filter(
|
|
|
|
+ (item) => getDate(item) === date
|
|
|
|
+ ); // all files on a checked/unchecked day
|
|
|
|
+
|
|
|
|
+ filesOnADay.forEach((file) => {
|
|
|
|
+ handleSelect(
|
|
|
|
+ file.id,
|
|
|
|
+ file.ownerID === galleryContext?.user?.id
|
|
|
|
+ )(isDateSelected);
|
|
|
|
+ });
|
|
|
|
+ };
|
|
|
|
+
|
|
const renderListItem = (
|
|
const renderListItem = (
|
|
listItem: TimeStampListItem,
|
|
listItem: TimeStampListItem,
|
|
isScrolling: boolean,
|
|
isScrolling: boolean,
|
|
@@ -733,6 +788,15 @@ export function PhotoList({
|
|
.map((item) => [
|
|
.map((item) => [
|
|
<DateContainer key={item.date} span={item.span}>
|
|
<DateContainer key={item.date} span={item.span}>
|
|
{item.date}
|
|
{item.date}
|
|
|
|
+ <SelectAllCheckBoxContainer
|
|
|
|
+ key={item.date}
|
|
|
|
+ name={item.date}
|
|
|
|
+ checked={checkedDates[item.date]}
|
|
|
|
+ onChange={() =>
|
|
|
|
+ onChangeSelectAllCheckBox(item.date)
|
|
|
|
+ }
|
|
|
|
+ margin={columns}
|
|
|
|
+ />
|
|
</DateContainer>,
|
|
</DateContainer>,
|
|
<div key={`${item.date}-gap`} />,
|
|
<div key={`${item.date}-gap`} />,
|
|
])
|
|
])
|
|
@@ -740,6 +804,15 @@ export function PhotoList({
|
|
) : (
|
|
) : (
|
|
<DateContainer span={columns}>
|
|
<DateContainer span={columns}>
|
|
{listItem.date}
|
|
{listItem.date}
|
|
|
|
+ <SelectAllCheckBoxContainer
|
|
|
|
+ key={listItem.date}
|
|
|
|
+ name={listItem.date}
|
|
|
|
+ checked={checkedDates[listItem.date]}
|
|
|
|
+ onChange={() =>
|
|
|
|
+ onChangeSelectAllCheckBox(listItem.date)
|
|
|
|
+ }
|
|
|
|
+ margin={columns}
|
|
|
|
+ />
|
|
</DateContainer>
|
|
</DateContainer>
|
|
);
|
|
);
|
|
case ITEM_TYPE.SIZE_AND_COUNT:
|
|
case ITEM_TYPE.SIZE_AND_COUNT:
|