Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

feat(AssignPersonDialog):add-search-bar

Aswin Asokce18a1d9c4e4
diff --git a/desktop/changes/search-people-when-assigning.md b/desktop/changes/search-people-when-assigning.md
new file mode 100644
index 0000000000..645484cd24
--- /dev/null
+++ b/desktop/changes/search-people-when-assigning.md
@@ -0,0 +1 @@
+- Search for people when assigning photos.
diff --git a/web/packages/new/photos/components/AssignPersonDialog.tsx b/web/packages/new/photos/components/AssignPersonDialog.tsx
index d6c39bf746..3abe92c31b 100644
--- a/web/packages/new/photos/components/AssignPersonDialog.tsx
+++ b/web/packages/new/photos/components/AssignPersonDialog.tsx
@@ -1,8 +1,13 @@
+import SearchIcon from "@mui/icons-material/Search";
import {
Dialog,
DialogContent,
DialogTitle,
+ Divider,
+ InputAdornment,
+ Stack,
styled,
+ TextField,
Typography,
useMediaQuery,
} from "@mui/material";
@@ -10,7 +15,8 @@ import { SpacedRow } from "ente-base/components/containers";
import { DialogCloseIconButton } from "ente-base/components/mui/DialogCloseIconButton";
import type { ModalVisibilityProps } from "ente-base/components/utils/modal";
import type { Person } from "ente-new/photos/services/ml/people";
-import React from "react";
+import { t } from "i18next";
+import React, { useState } from "react";
import { ItemCard, LargeTileButton, LargeTileTextOverlay } from "./Tiles";
export type AssignPersonDialogProps = ModalVisibilityProps & {
@@ -40,39 +46,119 @@ export const AssignPersonDialog: React.FC<AssignPersonDialogProps> = ({
onSelectPerson,
}) => {
const isFullScreen = useMediaQuery("(max-width: 490px)");
+ const [searchTerm, setSearchTerm] = useState("");
+ const query = searchTerm.trim().toLowerCase();
+ const filteredPeople = query
+ ? people.filter((person) => person.name?.toLowerCase().includes(query))
+ : people;
return (
- <Dialog
+ <StyledDialog
{...{ open, onClose }}
fullWidth
fullScreen={isFullScreen}
- slotProps={{ paper: { sx: { maxWidth: "490px" } } }}
+ slotProps={{
+ paper: { sx: { maxWidth: "490px", minHeight: "80svh" } },
+ transition: { onExited: () => setSearchTerm("") },
+ }}
>
- <SpacedRow sx={{ padding: "10px 8px 6px 0" }}>
- <DialogTitle variant="h3">{title}</DialogTitle>
- <DialogCloseIconButton {...{ onClose }} />
- </SpacedRow>
- <DialogContent_>
- {people.map((person) => (
- <ItemCard
- key={person.id}
- TileComponent={LargeTileButton}
- coverFile={person.displayFaceFile}
- coverFaceID={person.displayFaceID}
- onClick={() => onSelectPerson(person.id)}
- >
- <LargeTileTextOverlay>
- <Typography>{person.name ?? ""}</Typography>
- </LargeTileTextOverlay>
- </ItemCard>
- ))}
- </DialogContent_>
- </Dialog>
+ <DialogTitle>
+ <Stack sx={{ gap: 1.5 }}>
+ <SpacedRow>
+ <Typography variant="h3">{title}</Typography>
+ <DialogCloseIconButton {...{ onClose }} />
+ </SpacedRow>
+ <TextField
+ fullWidth
+ type="search"
+ size="small"
+ placeholder={t("search")}
+ value={searchTerm}
+ onChange={(event) => setSearchTerm(event.target.value)}
+ autoFocus
+ slotProps={{
+ htmlInput: {
+ "aria-label": `${t("search")} ${t("people")}`,
+ },
+ input: {
+ startAdornment: (
+ <InputAdornment position="start">
+ <SearchIcon />
+ </InputAdornment>
+ ),
+ },
+ }}
+ sx={searchFieldSx}
+ />
+ </Stack>
+ </DialogTitle>
+ <Divider />
+ {filteredPeople.length ? (
+ <DialogContent_>
+ {filteredPeople.map((person) => (
+ <ItemCard
+ key={person.id}
+ TileComponent={LargeTileButton}
+ coverFile={person.displayFaceFile}
+ coverFaceID={person.displayFaceID}
+ onClick={() => onSelectPerson(person.id)}
+ >
+ <LargeTileTextOverlay>
+ <Typography>{person.name ?? ""}</Typography>
+ </LargeTileTextOverlay>
+ </ItemCard>
+ ))}
+ </DialogContent_>
+ ) : (
+ <NoResultsContent>
+ <Typography sx={{ color: "text.muted" }}>
+ {t("no_results")}
+ </Typography>
+ </NoResultsContent>
+ )}
+ </StyledDialog>
);
};
+const StyledDialog = styled(Dialog)(({ theme }) => ({
+ "& .MuiDialogTitle-root": { padding: theme.spacing(2) },
+ "& .MuiDialogContent-root": { padding: theme.spacing(2) },
+}));
+
const DialogContent_ = styled(DialogContent)`
- display: flex;
- flex-wrap: wrap;
+ display: grid;
+ grid-template-columns: repeat(auto-fill, 150px);
gap: 4px;
+ align-content: start;
+
+ @media (min-width: 491px) {
+ justify-content: center;
+ }
+`;
+
+const NoResultsContent = styled(DialogContent)`
+ display: flex;
+ justify-content: center;
+ align-items: center;
`;
+
+const searchFieldSx = {
+ "& .MuiOutlinedInput-root": {
+ backgroundColor: "background.searchInput",
+ borderColor: "transparent",
+ "&:hover": { borderColor: "accent.light" },
+ "&.Mui-focused": { borderColor: "accent.main", boxShadow: "none" },
+ },
+ "& .MuiInputBase-input": {
+ color: "text.base",
+ paddingTop: "8.5px !important",
+ paddingBottom: "8.5px !important",
+ },
+ "& .MuiInputAdornment-root": {
+ color: "stroke.muted",
+ marginTop: "0 !important",
+ marginRight: "8px",
+ },
+ "& .MuiOutlinedInput-notchedOutline": { borderColor: "transparent" },
+ "& .MuiInputBase-input::placeholder": { color: "text.muted", opacity: 1 },
+};