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

[web] UI tweaks to the select all checkbox #704

Merged
merged 2 commits into from
Mar 6, 2024
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
12 changes: 6 additions & 6 deletions web/apps/photos/src/components/PhotoFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ import DownloadManager, {
LivePhotoSourceURL,
SourceURLs,
} from "services/download";
import {
handleSelectCreator,
updateFileMsrcProps,
updateFileSrcProps,
} from "utils/photoFrame";
import { EnteFile } from "types/file";
import {
SelectedState,
SetFilesDownloadProgressAttributesCreator,
} from "types/gallery";
import {
handleSelectCreator,
updateFileMsrcProps,
updateFileSrcProps,
} from "utils/photoFrame";
import { PhotoList } from "./PhotoList";
import { DedupePhotoList } from "./PhotoList/dedupe";
import PreviewCard from "./pages/gallery/PreviewCard";
Expand Down Expand Up @@ -234,7 +234,7 @@ const PhotoFrame = ({
const handleSelect = handleSelectCreator(
setSelected,
activeCollectionID,
setRangeStart
setRangeStart,
);

const onHoverOver = (index: number) => () => {
Expand Down
38 changes: 19 additions & 19 deletions web/apps/photos/src/components/PhotoList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { FlexWrapper } from "@ente/shared/components/Container";
import { ENTE_WEBSITE_LINK } from "@ente/shared/constants/urls";
import { formatDate, getDate, isSameDay } from "@ente/shared/time/format";
import { convertBytesToHumanReadable } from "@ente/shared/utils/size";
import { Box, Link, Typography, Checkbox, styled } from "@mui/material";
import { Box, Checkbox, Link, Typography, styled } from "@mui/material";
import {
DATE_CONTAINER_HEIGHT,
GAP_BTW_TILES,
Expand All @@ -22,10 +23,9 @@ import {
ListChildComponentProps,
areEqual,
} from "react-window";
import { PublicCollectionGalleryContext } from "utils/publicCollectionGallery";
import { formatDate, getDate, isSameDay } from "@ente/shared/time/format";
import { handleSelectCreator } from "utils/photoFrame";
import { EnteFile } from "types/file";
import { handleSelectCreator } from "utils/photoFrame";
import { PublicCollectionGalleryContext } from "utils/publicCollectionGallery";

const A_DAY = 24 * 60 * 60 * 1000;
const FOOTER_HEIGHT = 90;
Expand Down Expand Up @@ -186,10 +186,6 @@ const NothingContainer = styled(ListItemContainer)`
justify-content: center;
`;

const SelectAllCheckBoxContainer = styled(Checkbox)<{ margin: number }>`
margin-left: ${(props) => props.margin}px;
`;

interface Props {
height: number;
width: number;
Expand Down Expand Up @@ -723,15 +719,15 @@ export function PhotoList({

useEffect(() => {
const notSelectedFiles = displayFiles?.filter(
(item) => !galleryContext.selectedFile[item.id]
(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))
(item) => !unselectedDates.includes(getDate(item)),
);

const localSelectedDates = [
Expand All @@ -756,7 +752,7 @@ export function PhotoList({

const handleSelect = handleSelectCreator(
galleryContext.setSelectedFiles,
activeCollectionID
activeCollectionID,
);

const onChangeSelectAllCheckBox = (date: string) => {
Expand All @@ -766,13 +762,13 @@ export function PhotoList({
setCheckedDates(dates);

const filesOnADay = displayFiles?.filter(
(item) => getDate(item) === date
(item) => getDate(item) === date,
); // all files on a checked/unchecked day

filesOnADay.forEach((file) => {
handleSelect(
file.id,
file.ownerID === galleryContext?.user?.id
file.ownerID === galleryContext?.user?.id,
)(isDateSelected);
});
};
Expand All @@ -787,32 +783,36 @@ export function PhotoList({
listItem.dates
.map((item) => [
<DateContainer key={item.date} span={item.span}>
{item.date}
<SelectAllCheckBoxContainer
<Checkbox
key={item.date}
name={item.date}
checked={checkedDates[item.date]}
onChange={() =>
onChangeSelectAllCheckBox(item.date)
}
margin={columns}
size="small"
sx={{ pl: 0 }}
disableRipple={true}
/>
{item.date}
</DateContainer>,
<div key={`${item.date}-gap`} />,
])
.flat()
) : (
<DateContainer span={columns}>
{listItem.date}
<SelectAllCheckBoxContainer
<Checkbox
key={listItem.date}
name={listItem.date}
checked={checkedDates[listItem.date]}
onChange={() =>
onChangeSelectAllCheckBox(listItem.date)
}
margin={columns}
size="small"
sx={{ pl: 0 }}
disableRipple={true}
/>
{listItem.date}
</DateContainer>
);
case ITEM_TYPE.SIZE_AND_COUNT:
Expand Down
3 changes: 2 additions & 1 deletion web/apps/photos/src/pages/gallery/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,8 @@ export default function Gallery() {
isClipSearchResult,
selectedFile: selected,
setSelectedFiles: setSelected,
}}>
}}
>
<FullScreenDropZone
getDragAndDropRootProps={getDragAndDropRootProps}
>
Expand Down
8 changes: 4 additions & 4 deletions web/apps/photos/src/utils/photoFrame/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FILE_TYPE } from "constants/file";
import { EnteFile } from "types/file";
import { logError } from "@ente/shared/sentry";
import { FILE_TYPE } from "constants/file";
import { LivePhotoSourceURL, SourceURLs } from "services/download";
import { EnteFile } from "types/file";
import { SetSelectedState } from "types/gallery";

const WAIT_FOR_VIDEO_PLAYBACK = 1 * 1000;
Expand Down Expand Up @@ -135,11 +135,11 @@ export const handleSelectCreator =
(
setSelected: SetSelectedState,
activeCollectionID: number,
setRangeStart?
setRangeStart?,
) =>
(id: number, isOwnFile: boolean, index?: number) =>
(checked: boolean) => {
if (typeof index !== 'undefined') {
if (typeof index !== "undefined") {
if (checked) {
setRangeStart(index);
} else {
Expand Down
6 changes: 3 additions & 3 deletions web/packages/shared/time/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ export const isSameDay = (first, second) => {
export const getDate = (item) => {
const currentDate = item.metadata.creationTime / 1000;
const date = isSameDay(new Date(currentDate), new Date())
? t('TODAY')
? t("TODAY")
: isSameDay(new Date(currentDate), new Date(Date.now() - A_DAY))
? t('YESTERDAY')
: formatDate(currentDate);
? t("YESTERDAY")
: formatDate(currentDate);

return date;
};
Loading