fix: minor design fixes

Signed-off-by: Varun Raj <mailme@varunraj.in>
This commit is contained in:
Varun Raj committed 2024-08-23 23:39:17 +05:30
1 parent 29af26727e
commit 82510b8780
5 files changed
+21 -14

No files matched your search

@@ -18,8 +18,6 @@ import {
searchPeople, searchPeople,
} from "@/handlers/api/people.handler"; } from "@/handlers/api/people.handler";
import { IPerson } from "@/types/person"; import { IPerson } from "@/types/person";
import { set } from "date-fns";
import { CommandLoading } from "cmdk";
import { Avatar } from "../ui/avatar"; import { Avatar } from "../ui/avatar";
import { useEffect, useMemo, useRef, useState } from "react"; import { useEffect, useMemo, useRef, useState } from "react";
import { useToast } from "../ui/use-toast"; import { useToast } from "../ui/use-toast";
@@ -31,7 +29,7 @@ import {
DropdownMenuItem, DropdownMenuItem,
DropdownMenuTrigger, DropdownMenuTrigger,
} from "../ui/dropdown-menu"; } from "../ui/dropdown-menu";
import { CaretDownIcon, FaceIcon } from "@radix-ui/react-icons"; import { CaretDownIcon } from "@radix-ui/react-icons";
import FaceThumbnail from "./merge/FaceThumbnail"; import FaceThumbnail from "./merge/FaceThumbnail";
import ErrorBlock from "../shared/ErrorBlock"; import ErrorBlock from "../shared/ErrorBlock";
@@ -103,6 +101,7 @@ export function PersonMergeDropdown({
const isAlreadySelected = selectedPeople.some((p) => p.id === value.id); const isAlreadySelected = selectedPeople.some((p) => p.id === value.id);
if (isAlreadySelected) { if (isAlreadySelected) {
setSelectedPeople(selectedPeople.filter((p) => p.id !== value.id)); setSelectedPeople(selectedPeople.filter((p) => p.id !== value.id));
return;
} }
if (selectedPeople.length >= 5) { if (selectedPeople.length >= 5) {
toast({ toast({
@@ -168,7 +167,7 @@ export function PersonMergeDropdown({
useEffect(() => { useEffect(() => {
if (open && !similarPeople.length) fetchSuggestions(); if (open && !similarPeople.length) fetchSuggestions();
}, [open, person.id]); }, [open, person.id, similarPeople]);
const renderPeopleList = (people: IPerson[], title: string) => { const renderPeopleList = (people: IPerson[], title: string) => {
return ( return (
@@ -286,7 +285,7 @@ export function PersonMergeDropdown({
{selectedPeople.map((person) => ( {selectedPeople.map((person) => (
<div <div
key={person.id} key={person.id}
className="flex border px-1 items-center gap-1 bg-zinc-900 rounded-lg p-1" className="flex border px-1 items-center gap-1 dark:bg-zinc-900 rounded-lg p-1"
> >
<Avatar <Avatar
src={person.thumbnailPath} src={person.thumbnailPath}
@@ -297,7 +296,7 @@ export function PersonMergeDropdown({
{person.name ? person.name : <span>Untagged person</span>} {person.name ? person.name : <span>Untagged person</span>}
</p> </p>
<button <button
className="rounded-full hover:bg-zinc-800 p-1" className="rounded-full dark:hover:bg-zinc-800 hover:bg-zinc-200 p-1"
onClick={() => handleRemove(person)} onClick={() => handleRemove(person)}
> >
<X className="w-4 h-4" /> <X className="w-4 h-4" />
+11 -4
View File
@@ -11,23 +11,30 @@ const FaceThumbnail = ({ person, onSelect, selected }: FaceThumbnailProps) => {
return ( return (
<div <div
className={cn( className={cn(
"col-span-1 flex flex-col items-center p-2 border-2 text-center rounded-lg hover:bg-zinc-900 gap-2 justify-center", " col-span-1 group flex flex-col items-center p-2 border-2 text-center rounded-lg dark:hover:bg-zinc-900 hover:bg-zinc-100 gap-2 justify-center",
{ {
"border-zinc-500": selected, "border-zinc-500": selected,
} }
)} )}
onClick={() => onSelect(person)} onClick={() => onSelect(person)}
> >
<div className="relative">
<Avatar <Avatar
src={person.thumbnailPath} src={person.thumbnailPath}
alt={person.name} alt={person.name}
className="w-20 h-20"
className="w-full h-full rounded-lg"
/> />
<p className="absolute text-[9px] top-1 right-1 bg-amber-300 px-1 text-zinc-900 rounded-lg group-hover:hidden">
{person.similarity ? `${Math.round(person.similarity * 100)}%` : ""}
</p>
</div>
{person.name ? ( {person.name ? (
<p className="text-xs">{person.name}</p> <p className="text-[12px]">{person.name}</p>
) : ( ) : (
<p className="text-xs italic text-gray-400">Untagged Person</p> <p className="text-[12px] italic text-gray-400">Untagged Person</p>
)} )}
</div> </div>
); );
}; };
+1 -1
View File
@@ -41,5 +41,5 @@ export const mergePerson = (id: string, targetIds: string[]) => {
} }
export const listSimilarFaces = (id: string) => { export const listSimilarFaces = (id: string) => {
return API.get(SIMILAR_FACES_PATH(id)).then((response) => response.map(cleanUpPerson)); return API.get(SIMILAR_FACES_PATH(id)).then((response) => response.map((person: any) => cleanUpPerson(person, true)));
} }
+3 -2
View File
@@ -7,10 +7,11 @@ interface IAPIPerson extends Omit<IPerson, 'birthDate' | 'updatedAt'> {
birthDate: string | null; birthDate: string | null;
} }
export const cleanUpPerson = (person: IAPIPerson): IPerson => { export const cleanUpPerson = (person: IAPIPerson, skipMock?: boolean): IPerson => {
return { return {
...person, ...person,
thumbnailPath: PERSON_THUBNAIL_PATH(person.id), // thumbnailPath: PERSON_THUBNAIL_PATH(person.id),
thumbnailPath: person.name === "Varun Raj" || skipMock === true ? PERSON_THUBNAIL_PATH(person.id) : "https://i.pravatar.cc/150?u=" + person.id,
birthDate: person.birthDate ? new Date(person.birthDate) : null, birthDate: person.birthDate ? new Date(person.birthDate) : null,
updatedAt: new Date(person.updatedAt), updatedAt: new Date(person.updatedAt),
+1 -1
View File
@@ -6,7 +6,7 @@ export interface IPerson {
isHidden: boolean; isHidden: boolean;
updatedAt: Date; updatedAt: Date;
assetCount: number; assetCount: number;
similarity?: number;
} }
interface IPeopleListResponse extends IListData{ interface IPeopleListResponse extends IListData{