mirror of
https://github.com/IliesAllali/parenthese.git
synced 2026-11-17 16:42:23 +00:00
Contributions fiables : prénom, mot d'accompagnement, liens gardés
- Prénom demandé à l'envoi d'une contribution et d'un souvenir, retenu sur l'appareil pour la fois suivante (submittedByLabel). Le propriétaire lit « par Camille » au lieu de « par Contributeur ». - Mot d'accompagnement enregistré (ContributionSession.comment, migration additive) et affiché à la relecture. - Une personne ajoutée par la famille garde ses liens : identifiant provisoire « tmp:… » remplacé par le vrai id à l'application ; un lien vers une personne refusée est écarté au lieu de faire échouer la relecture. Frère ou sœur : parents calculés aussi pour la famille. - Soumission et relecture en transaction, appliquées dans l'ordre personnes, unions, liens : tout ou rien. - Bouton « Ajouter une personne » pour la famille sur ordinateur ; après l'ajout, le panneau se ferme et un message confirme que la personne est dans les modifications ; il ne réapparaît plus au retour en édition. - Relecture : les liens se lisent « Léon, enfant de Marc ». Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
66752aa1b6
commit
8bfc78b2f5
12 files changed
+491
-141
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { API_BASE_URL } from '../api/client'
|
||||
import { persons as treePersons } from '../data/mockData'
|
||||
import { Check, ChevronDown, Copy, RefreshCw, X } from 'lucide-react'
|
||||
import './SettingsPanels.css'
|
||||
import PzBusy from './PzBusy.jsx'
|
||||
@@ -71,7 +72,39 @@ function displayVal(v) {
|
||||
return String(v)
|
||||
}
|
||||
|
||||
function getPersonDisplayName(change) {
|
||||
// Nom d'une personne citée par un lien : dans l'arbre, ou ajoutée dans la même contribution (id provisoire « tmp: »)
|
||||
function nameOfPersonRef(id, sessionChanges = []) {
|
||||
if (!id) return null
|
||||
const key = String(id)
|
||||
if (key.startsWith('tmp:')) {
|
||||
const added = sessionChanges.find((c) => c.entityType === 'person' && c.afterJson?.ref === key)
|
||||
const name = `${added?.afterJson?.firstName || ''} ${added?.afterJson?.lastName || ''}`.trim()
|
||||
return name || 'la nouvelle personne'
|
||||
}
|
||||
const person = treePersons.find((candidate) => String(candidate.id) === key)
|
||||
const name = `${person?.firstName || ''} ${person?.lastName || ''}`.trim()
|
||||
return name || null
|
||||
}
|
||||
|
||||
function getRelationLabel(change, sessionChanges) {
|
||||
const data = change.afterJson && typeof change.afterJson === 'object' ? change.afterJson : null
|
||||
if (!data) return null
|
||||
if (change.entityType === 'parent_child_link') {
|
||||
const child = nameOfPersonRef(data.childPersonId, sessionChanges)
|
||||
const parent = nameOfPersonRef(data.parentPersonId, sessionChanges)
|
||||
return child && parent ? `${child}, enfant de ${parent}` : null
|
||||
}
|
||||
if (change.entityType === 'union') {
|
||||
const a = nameOfPersonRef(data.partner1PersonId, sessionChanges)
|
||||
const b = nameOfPersonRef(data.partner2PersonId, sessionChanges)
|
||||
return a && b ? `${a} et ${b}` : null
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
function getPersonDisplayName(change, sessionChanges = []) {
|
||||
const relationLabel = getRelationLabel(change, sessionChanges)
|
||||
if (relationLabel) return relationLabel
|
||||
if (change.entityType === 'annotation') {
|
||||
const data = change.afterJson || change.after || {}
|
||||
return formatAnnotationType(data.type)
|
||||
@@ -413,7 +446,7 @@ const ContributionPanel = ({
|
||||
const decision = getChangeDecision(session.id, change.id)
|
||||
const isApproved = decision === 'approved'
|
||||
const isRejected = decision === 'rejected'
|
||||
const personName = getPersonDisplayName(change)
|
||||
const personName = getPersonDisplayName(change, session.changes || [])
|
||||
const fields = getFieldRows(change)
|
||||
const annPreview = change.entityType === 'annotation' ? getAnnotationPreview(change) : null
|
||||
const mediaPreview = change.entityType === 'media' ? getMediaPreview(change, treeId, mediaToken) : null
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useState, useEffect } from 'react'
|
||||
import { Send, X } from 'lucide-react'
|
||||
import './ContributionSessionModal.css'
|
||||
import PzBusy from './PzBusy.jsx'
|
||||
import { readContributorName } from '../utils/contributorName'
|
||||
|
||||
function formatAction(action) {
|
||||
if (action === 'create') return 'Ajout'
|
||||
@@ -23,13 +24,15 @@ function formatAction(action) {
|
||||
* @param {Function} props.onSubmit - Handler soumission ({ comment })
|
||||
* @param {Function} props.onCancel - Handler annulation
|
||||
*/
|
||||
function ContributionSessionModal({ visible, changes = [], recap = {}, loading = false, error = '', onSubmit, onCancel }) {
|
||||
function ContributionSessionModal({ visible, changes = [], recap = {}, loading = false, error = '', askName = true, onSubmit, onCancel }) {
|
||||
const [comment, setComment] = useState('')
|
||||
const [name, setName] = useState('')
|
||||
|
||||
// Reset à l'ouverture
|
||||
// Reset à l'ouverture ; le prénom déjà donné sur cet appareil est repris
|
||||
useEffect(() => {
|
||||
if (visible) {
|
||||
setComment('')
|
||||
setName(readContributorName())
|
||||
}
|
||||
}, [visible])
|
||||
|
||||
@@ -47,7 +50,8 @@ function ContributionSessionModal({ visible, changes = [], recap = {}, loading =
|
||||
|
||||
const handleSubmit = (e) => {
|
||||
e.preventDefault()
|
||||
onSubmit({ comment: comment.trim() })
|
||||
if (askName && !name.trim()) return
|
||||
onSubmit({ comment: comment.trim(), name: name.trim() })
|
||||
}
|
||||
|
||||
const totalChanges = (recap.added || 0) + (recap.modified || 0) + (recap.deleted || 0)
|
||||
@@ -94,6 +98,20 @@ function ContributionSessionModal({ visible, changes = [], recap = {}, loading =
|
||||
)}
|
||||
|
||||
<form className="cs-form" onSubmit={handleSubmit}>
|
||||
{askName && (
|
||||
<div className="pz-field">
|
||||
<label htmlFor="cs-name">Votre prénom</label>
|
||||
<input
|
||||
id="cs-name"
|
||||
type="text"
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value.slice(0, 120))}
|
||||
placeholder="Pour que la famille sache qui a ajouté quoi"
|
||||
autoComplete="given-name"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="pz-field">
|
||||
<label htmlFor="cs-comment">
|
||||
Un mot pour accompagner <span className="cs-optional">facultatif</span>
|
||||
@@ -115,7 +133,7 @@ function ContributionSessionModal({ visible, changes = [], recap = {}, loading =
|
||||
<button type="button" className="pz-btn pz-btn--ghost" onClick={onCancel} disabled={loading}>
|
||||
Annuler
|
||||
</button>
|
||||
<button type="submit" className="pz-btn pz-btn--primary" disabled={loading}>
|
||||
<button type="submit" className="pz-btn pz-btn--primary" disabled={loading || (askName && !name.trim())}>
|
||||
<Send size={16} strokeWidth={2} />
|
||||
<PzBusy busy={loading} busyLabel="Envoi en cours">Envoyer mes contributions</PzBusy>
|
||||
</button>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useMemo, useState } from 'react'
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { readContributorName } from '../utils/contributorName'
|
||||
import { ArrowDown, ArrowUp, FileText, Image, MapPin, Mic, Plus, Quote, Route, Trash2, Upload, Video, X } from 'lucide-react'
|
||||
import { getAcceptForMediaType } from '../utils/mediaUpload'
|
||||
import GeoMediaThumbnail from './GeoMediaThumbnail'
|
||||
@@ -40,6 +41,11 @@ const MediaManagerPanel = ({
|
||||
const [citationText, setCitationText] = useState('')
|
||||
const [videoMode, setVideoMode] = useState('file') // 'file' | 'youtube'
|
||||
const [youtubeUrl, setYoutubeUrl] = useState('')
|
||||
const [contributorName, setContributorName] = useState(() => readContributorName())
|
||||
// Le panneau est monté dès le départ : relire le prénom à chaque ouverture (il a pu être donné entre-temps)
|
||||
useEffect(() => {
|
||||
if (visible) setContributorName((current) => current || readContributorName())
|
||||
}, [visible])
|
||||
|
||||
const isCitation = mediaType === 'citation'
|
||||
const isYoutubeVideo = mediaType === 'video' && videoMode === 'youtube'
|
||||
@@ -48,6 +54,10 @@ const MediaManagerPanel = ({
|
||||
return false
|
||||
}
|
||||
|
||||
if (!canManage && !contributorName.trim()) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (isCitation) {
|
||||
return citationText.trim().length > 0
|
||||
}
|
||||
@@ -57,7 +67,7 @@ const MediaManagerPanel = ({
|
||||
}
|
||||
|
||||
return Boolean(file)
|
||||
}, [citationText, file, isCitation, isYoutubeVideo, loading, youtubeUrl])
|
||||
}, [canManage, citationText, contributorName, file, isCitation, isYoutubeVideo, loading, youtubeUrl])
|
||||
const fileAccept = useMemo(() => getAcceptForMediaType(mediaType), [mediaType])
|
||||
|
||||
if (!visible || !person) {
|
||||
@@ -77,6 +87,7 @@ const MediaManagerPanel = ({
|
||||
mediaType,
|
||||
citationText: citationText.trim(),
|
||||
youtubeUrl: isYoutubeVideo ? youtubeUrl.trim() : null,
|
||||
submittedByLabel: canManage ? null : contributorName.trim(),
|
||||
})
|
||||
setFile(null)
|
||||
setCaption('')
|
||||
@@ -228,6 +239,20 @@ const MediaManagerPanel = ({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{!canManage && (
|
||||
<div className="pz-field">
|
||||
<label htmlFor="mm-contributor-name">Votre prénom</label>
|
||||
<input
|
||||
id="mm-contributor-name"
|
||||
type="text"
|
||||
value={contributorName}
|
||||
onChange={(e) => setContributorName(e.target.value.slice(0, 120))}
|
||||
placeholder="Pour que la famille sache qui l'a ajouté"
|
||||
autoComplete="given-name"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{errorMessage && <div className="pz-error" role="alert">{errorMessage}</div>}
|
||||
{notice && !errorMessage && <div className="pz-success" role="status">{notice}</div>}
|
||||
|
||||
|
||||
@@ -175,7 +175,15 @@ function ContextualNavbar({
|
||||
icon={<Edit3 size={20} strokeWidth={2} />}
|
||||
label="Contribuer à l'arbre"
|
||||
onClick={onEditClick}
|
||||
active={editModeActive}
|
||||
/>
|
||||
{editModeActive && (
|
||||
<NavButton
|
||||
icon={<UserPlus size={20} strokeWidth={2} />}
|
||||
label="Ajouter une personne"
|
||||
onClick={onAddPersonClick}
|
||||
/>
|
||||
)}
|
||||
<NavButton
|
||||
icon={<User size={20} strokeWidth={2} />}
|
||||
label="Créer un compte"
|
||||
|
||||
Reference in new issue
Block a user