mirror of
https://github.com/IliesAllali/parenthese.git
synced 2026-11-17 08:42:23 +00:00
Immich : le choix de la source passe par un menu sur « Changer » ; « Retirer » désassigne les visages Immich
- PersonCard : le lien « Depuis Immich » empilé sous « Changer »/« Retirer » disparaît ; « Changer »/« Ajouter une photo » ouvre un menu contextuel (portail, pz-menu) proposant « Depuis un fichier » ou « Depuis Immich », seulement quand l'arbre a une connexion Immich ou que la personne garde un portrait venu d'Immich (sinon sélecteur direct). La connexion se lit via GET /trees/:id/immich/config à l'ouverture en édition. - « Retirer » transmet l'origine du portrait ; App route vers unassignImmichPerson quand il vient d'Immich (portrait + association retirés ensemble) au lieu de la suppression seule qui laissait une association pendante. Erreurs du chemin Immich mappées par getImmichErrorMessage. - i18n en : « Depuis un fichier », « Source du portrait ». Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
1 parent
310f2fb597
commit
8803463ce4
4 files changed
+102
-11
No files matched your search
+15
-4
@@ -45,6 +45,7 @@ import {
|
||||
updatePerson,
|
||||
uploadAnnotationPhoto,
|
||||
} from './api/treeApi'
|
||||
import { getImmichErrorMessage, unassignImmichPerson } from './api/immichApi.js'
|
||||
import { useAuth } from './hooks/useAuth'
|
||||
import { useTreeAccess, getTreeTokenStorageKey, getSlugFromPathname, readTreeAccessRole, TREE_ID_FROM_ENV } from './hooks/useTreeAccess'
|
||||
import { useMediaManager } from './hooks/useMediaManager'
|
||||
@@ -1540,18 +1541,28 @@ function App() {
|
||||
await refreshTreeAndKeepSelection(personId, { relayout: false, avatarCacheBust: Date.now() })
|
||||
}, [refreshTreeAndKeepSelection])
|
||||
|
||||
const handlePersonAvatarDelete = useCallback(async (personId) => {
|
||||
const handlePersonAvatarDelete = useCallback(async (personId, avatarFromImmich = false) => {
|
||||
const accessToken = tree.treeContext.accessToken || auth.userAuth.token
|
||||
if (!accessToken || !tree.treeContext.treeId) return
|
||||
|
||||
setAvatarActionState({ loading: true, error: '' })
|
||||
|
||||
try {
|
||||
await deletePersonAvatar(tree.treeContext.treeId, personId, accessToken)
|
||||
await refreshTreeAndKeepSelection(personId, { relayout: true })
|
||||
// Portrait venu d'Immich : le désassignement retire le portrait et l'association d'un
|
||||
// coup ; la suppression seule laisserait une association pendante en base.
|
||||
if (avatarFromImmich) {
|
||||
await unassignImmichPerson(tree.treeContext.treeId, personId, accessToken)
|
||||
await refreshTreeAndKeepSelection(personId, { relayout: false, avatarCacheBust: Date.now() })
|
||||
} else {
|
||||
await deletePersonAvatar(tree.treeContext.treeId, personId, accessToken)
|
||||
await refreshTreeAndKeepSelection(personId, { relayout: true })
|
||||
}
|
||||
setAvatarActionState({ loading: false, error: '' })
|
||||
} catch (error) {
|
||||
setAvatarActionState({ loading: false, error: getAccountErrorMessage(error) })
|
||||
setAvatarActionState({
|
||||
loading: false,
|
||||
error: avatarFromImmich ? getImmichErrorMessage(error, t) : getAccountErrorMessage(error),
|
||||
})
|
||||
}
|
||||
}, [auth.userAuth.token, tree.treeContext.accessToken, tree.treeContext.treeId, refreshTreeAndKeepSelection])
|
||||
|
||||
|
||||
@@ -55,6 +55,9 @@
|
||||
.pc-photo--add:focus-visible { outline: 2px solid var(--pz-a500); outline-offset: 3px; }
|
||||
.pc-photo--add:disabled { opacity: .6; cursor: default; }
|
||||
.pc-photo-actions { display: grid; gap: 4px; justify-items: center; }
|
||||
/* Menu du choix de source du portrait : au-dessus de la fiche (z-index 1000), sous la modale Immich (2200) */
|
||||
.pc-source-backdrop { position: fixed; inset: 0; z-index: 1100; }
|
||||
.pc-source-menu { position: fixed; z-index: 1150; min-width: 220px; }
|
||||
.pc-photo-btn {
|
||||
border: 0; background: none; padding: 2px 4px; cursor: pointer;
|
||||
font: 500 12px var(--pz-sans); color: var(--pz-a700); text-decoration: underline; text-underline-offset: 2px;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { useState, useEffect, useRef, forwardRef } from 'react'
|
||||
import { createPortal } from 'react-dom'
|
||||
import { Save, Trash2, Plus, X, Search, Check, Play, ImagePlus, Sparkles } from 'lucide-react'
|
||||
import { getParents, getChildren, getPersonUnions, getPersonMedias, filiations, persons, unions } from '../data/mockData'
|
||||
import { fetchImmichConfig } from '../api/immichApi.js'
|
||||
import GeoMediaThumbnail from './GeoMediaThumbnail'
|
||||
import ImmichFacePanel from './ImmichFacePanel.jsx'
|
||||
import './PersonCard.css'
|
||||
@@ -60,6 +62,13 @@ const PersonCard = ({
|
||||
const [saveSuccess, setSaveSuccess] = useState(false)
|
||||
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false)
|
||||
const [showImmichPanel, setShowImmichPanel] = useState(false)
|
||||
// null : connexion Immich de l'arbre inconnue, puis booléen. Le menu de source ne se propose
|
||||
// qu'à qui peut agir (owner/admin de l'arbre, comme pour toute action Immich) et seulement
|
||||
// si l'arbre est connecté ou qu'une association passée demande un nettoyage.
|
||||
const [immichConfigured, setImmichConfigured] = useState(null)
|
||||
const [showSourceMenu, setShowSourceMenu] = useState(false)
|
||||
const [sourceMenuPos, setSourceMenuPos] = useState({ top: 0, left: 0 })
|
||||
const sourceBtnRef = useRef(null)
|
||||
|
||||
// Inline relation search state
|
||||
const [activeRelationSearch, setActiveRelationSearch] = useState(null) // 'parent' | 'spouse' | 'child' | null
|
||||
@@ -75,8 +84,48 @@ const PersonCard = ({
|
||||
setActiveRelationSearch(null)
|
||||
setRelationSearchQuery('')
|
||||
setSaveSuccess(false)
|
||||
setShowSourceMenu(false)
|
||||
}, [person.id])
|
||||
|
||||
// Connexion Immich de l'arbre : métadonnées sans clé. Une erreur (rôle périmé, réseau) se
|
||||
// traduit par « non configuré » : la fiche reste utilisable, simplement sans choix de source.
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
setImmichConfigured(null)
|
||||
setShowSourceMenu(false)
|
||||
if (!editMode || !treeId || !onImmichChange || !immichToken) return undefined
|
||||
fetchImmichConfig(treeId, immichToken)
|
||||
.then(({ config }) => { if (!cancelled) setImmichConfigured(Boolean(config?.configured)) })
|
||||
.catch(() => { if (!cancelled) setImmichConfigured(false) })
|
||||
return () => { cancelled = true }
|
||||
}, [editMode, treeId, immichToken, onImmichChange])
|
||||
|
||||
useEffect(() => {
|
||||
if (!showSourceMenu) return undefined
|
||||
const onKeyDown = (event) => { if (event.key === 'Escape') setShowSourceMenu(false) }
|
||||
window.addEventListener('keydown', onKeyDown)
|
||||
return () => window.removeEventListener('keydown', onKeyDown)
|
||||
}, [showSourceMenu])
|
||||
|
||||
const immichUsable = Boolean(immichConfigured || person.avatarFromImmich)
|
||||
const openAvatarPicker = () => {
|
||||
if (avatarActionLoading) return
|
||||
if (immichUsable) {
|
||||
const rect = sourceBtnRef.current?.getBoundingClientRect()
|
||||
if (rect) {
|
||||
setSourceMenuPos({
|
||||
top: Math.round(rect.bottom) + 6,
|
||||
left: Math.round(Math.min(rect.left, window.innerWidth - 252)),
|
||||
})
|
||||
}
|
||||
setShowSourceMenu(true)
|
||||
} else {
|
||||
avatarInputRef.current?.click()
|
||||
}
|
||||
}
|
||||
const chooseFileSource = () => { setShowSourceMenu(false); avatarInputRef.current?.click() }
|
||||
const chooseImmichSource = () => { setShowSourceMenu(false); setShowImmichPanel(true) }
|
||||
|
||||
// Focus search input when relation search opens
|
||||
useEffect(() => {
|
||||
if (activeRelationSearch) {
|
||||
@@ -368,19 +417,27 @@ const PersonCard = ({
|
||||
)}
|
||||
{editMode && onAvatarUpload && (
|
||||
<div className="pc-photo-actions">
|
||||
<button type="button" className="pc-photo-btn" onClick={() => avatarInputRef.current?.click()} disabled={avatarActionLoading}>
|
||||
<button
|
||||
ref={sourceBtnRef}
|
||||
type="button"
|
||||
className="pc-photo-btn"
|
||||
onClick={openAvatarPicker}
|
||||
disabled={avatarActionLoading}
|
||||
aria-haspopup="menu"
|
||||
aria-expanded={showSourceMenu}
|
||||
>
|
||||
{person.photo ? t('Changer') : t('Ajouter une photo')}
|
||||
</button>
|
||||
{person.photo && (
|
||||
<button type="button" className="pc-photo-btn pc-photo-btn--danger" onClick={() => onAvatarDelete?.(person.id)} disabled={avatarActionLoading}>
|
||||
<button
|
||||
type="button"
|
||||
className="pc-photo-btn pc-photo-btn--danger"
|
||||
onClick={() => onAvatarDelete?.(person.id, person.avatarFromImmich)}
|
||||
disabled={avatarActionLoading}
|
||||
>
|
||||
{t('Retirer')}
|
||||
</button>
|
||||
)}
|
||||
{treeId && onImmichChange && (
|
||||
<button type="button" className="pc-photo-btn" onClick={() => setShowImmichPanel(true)} disabled={avatarActionLoading}>
|
||||
<Sparkles size={14} aria-hidden="true" /> {person.avatarFromImmich ? t('Visage Immich') : t('Depuis Immich')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
@@ -701,6 +758,24 @@ const PersonCard = ({
|
||||
</footer>
|
||||
)}
|
||||
|
||||
{/* ── Choix de la source du portrait (menu contextuel) ── */}
|
||||
{showSourceMenu && (
|
||||
createPortal(
|
||||
<>
|
||||
<div className="pc-source-backdrop" onClick={() => setShowSourceMenu(false)} />
|
||||
<div className="pc-source-menu pz-menu" role="menu" aria-label={t('Source du portrait')} style={{ top: `${sourceMenuPos.top}px`, left: `${sourceMenuPos.left}px` }}>
|
||||
<button type="button" role="menuitem" className="pz-menu-item" onClick={chooseFileSource}>
|
||||
<ImagePlus size={16} aria-hidden="true" /> {t('Depuis un fichier')}
|
||||
</button>
|
||||
<button type="button" role="menuitem" className="pz-menu-item" onClick={chooseImmichSource}>
|
||||
<Sparkles size={16} aria-hidden="true" /> {t('Depuis Immich')}
|
||||
</button>
|
||||
</div>
|
||||
</>,
|
||||
document.body,
|
||||
)
|
||||
)}
|
||||
|
||||
{/* ── Association d'un visage Immich (modale) ── */}
|
||||
{showImmichPanel && treeId && (
|
||||
<ImmichFacePanel
|
||||
|
||||
@@ -261,6 +261,8 @@ export default {
|
||||
'Inconnu': 'Unknown',
|
||||
// Visages venus d'Immich (PersonCard, ImmichFacePanel, immichApi)
|
||||
'Depuis Immich': 'From Immich',
|
||||
'Depuis un fichier': 'From a file',
|
||||
'Source du portrait': 'Portrait source',
|
||||
'Visage Immich': 'Immich face',
|
||||
'Reconnaissance des visages': 'Face recognition',
|
||||
'Immich n’est pas configuré pour cet arbre.': 'Immich is not configured for this tree.',
|
||||
|
||||
Reference in new issue
Block a user