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] Use reducer for gallery - Fin 7/7 #3811

Merged
merged 6 commits into from
Oct 23, 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
71 changes: 11 additions & 60 deletions web/apps/photos/src/pages/gallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ import {
SearchResultsHeader,
} from "@/new/photos/components/gallery";
import {
deriveAlbumishFilteredFiles,
derivePeopleFilteredFiles,
deriveTrashFilteredFiles,
uniqueFilesByID,
useGalleryReducer,
type GalleryBarMode,
Expand All @@ -32,7 +29,6 @@ import { shouldShowWhatsNew } from "@/new/photos/services/changelog";
import {
ALL_SECTION,
DUMMY_UNCATEGORIZED_COLLECTION,
TRASH_SECTION,
isHiddenCollection,
} from "@/new/photos/services/collection";
import { areOnlySystemCollections } from "@/new/photos/services/collection/ui";
Expand Down Expand Up @@ -306,15 +302,7 @@ export default function Gallery() {
const collections = state.collections;
const files = state.files;
const hiddenFiles = state.hiddenFiles;
const trashedFiles = state.trashedFiles;
const archivedCollectionIDs = state.archivedCollectionIDs;
const hiddenFileIDs = state.hiddenFileIDs;
const collectionNameMap = state.allCollectionNameByID;
const fileToCollectionsMap = state.fileCollectionIDs;
const collectionSummaries = state.collectionSummaries;
const hiddenCollectionSummaries = state.hiddenCollectionSummaries;
const tempDeletedFileIDs = state.tempDeletedFileIDs;
const tempHiddenFileIDs = state.tempHiddenFileIDs;
const barMode = state.view?.type ?? "albums";
const activeCollectionID =
state.view?.type == "people"
Expand All @@ -328,7 +316,7 @@ export default function Gallery() {
const isInSearchMode = state.isInSearchMode;
const filteredFiles = state.filteredFiles;

if (process.env.NEXT_PUBLIC_ENTE_WIP_CL) console.log("render", { state });
if (process.env.NEXT_PUBLIC_ENTE_WIP_CL) console.log("render", state);

const router = useRouter();

Expand Down Expand Up @@ -483,51 +471,13 @@ export default function Gallery() {

// TODO: Make this a normal useEffect.
useMemoSingleThreaded(async () => {
if (
!files ||
!user ||
!trashedFiles ||
!hiddenFiles ||
!archivedCollectionIDs
) {
dispatch({
type: "setFilteredFiles",
filteredFiles: [],
});
return;
}

let filteredFiles: EnteFile[];
if (selectedSearchOption) {
filteredFiles = await filterSearchableFiles(
const searchResults = await filterSearchableFiles(
selectedSearchOption.suggestion,
);
} else if (state.view?.type == "people") {
filteredFiles = derivePeopleFilteredFiles(state, state.view);
} else if (activeCollectionID === TRASH_SECTION) {
filteredFiles = deriveTrashFilteredFiles(state);
} else {
filteredFiles = deriveAlbumishFilteredFiles(state);
dispatch({ type: "setSearchResults", searchResults });
}

dispatch({
type: "setFilteredFiles",
filteredFiles,
});
}, [
barMode,
files,
trashedFiles,
hiddenFiles,
tempDeletedFileIDs,
tempHiddenFileIDs,
hiddenFileIDs,
selectedSearchOption,
activeCollectionID,
archivedCollectionIDs,
peopleState,
activePersonID,
]);
}, [selectedSearchOption]);

const selectAll = (e: KeyboardEvent) => {
// ignore ctrl/cmd + a if the user is typing in a text field
Expand Down Expand Up @@ -923,8 +873,8 @@ export default function Gallery() {
[],
);

if (!user || !filteredFiles) {
// Don't render until we get the logged in user and dispatch "mount".
if (!user) {
// Don't render until we dispatch "mount" with the logged in user.
return <div></div>;
}

Expand Down Expand Up @@ -1046,7 +996,8 @@ export default function Gallery() {
activeCollection,
activeCollectionID,
setActiveCollectionID: handleSetActiveCollectionID,
hiddenCollectionSummaries,
hiddenCollectionSummaries:
state.hiddenCollectionSummaries,
showPeopleSectionButton,
people:
(state.view.type == "people"
Expand Down Expand Up @@ -1129,8 +1080,8 @@ export default function Gallery() {
activeCollectionID={activeCollectionID}
activePersonID={activePerson?.id}
enableDownload={true}
fileToCollectionsMap={fileToCollectionsMap}
collectionNameMap={collectionNameMap}
fileToCollectionsMap={state.fileCollectionIDs}
collectionNameMap={state.allCollectionNameByID}
showAppDownloadBanner={
files.length < 30 && !isInSearchMode
}
Expand Down Expand Up @@ -1185,7 +1136,7 @@ export default function Gallery() {
<ExportModal
show={exportModalView}
onHide={closeExportModal}
collectionNameMap={collectionNameMap}
collectionNameMap={state.allCollectionNameByID}
/>
<AuthenticateUserModal
open={authenticateUserModalView}
Expand Down
8 changes: 1 addition & 7 deletions web/packages/new/photos/components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { searchOptionsForString } from "@/new/photos/services/search";
import type { SearchOption } from "@/new/photos/services/search/types";
import { nullToUndefined } from "@/utils/transform";
import CalendarIcon from "@mui/icons-material/CalendarMonth";
import ChevronRightIcon from "@mui/icons-material/ChevronRight";
import CloseIcon from "@mui/icons-material/Close";
import ImageIcon from "@mui/icons-material/Image";
import LocationIcon from "@mui/icons-material/LocationOn";
Expand Down Expand Up @@ -425,12 +424,7 @@ const EmptyState: React.FC<Pick<SearchBarProps, "onSelectPerson">> = ({

const SearchPeopleHeader: React.FC<ButtonishProps> = ({ onClick }) => (
<SearchPeopleHeaderButton {...{ onClick }}>
<Stack direction="row" color="text.muted">
<Typography color="text.base" variant="large">
{t("people")}
</Typography>
<ChevronRightIcon />
</Stack>
<Typography color="text.muted">{t("people")}</Typography>
</SearchPeopleHeaderButton>
);

Expand Down
Loading