WhoAmI
Quando accetta la tua vista nella webapp la persona condivide sempre con la vista il suo nickname. Può anche spuntare i campi pubblici del suo profilo che la vista potrà vedere. WhoAmI mostra il nickname seguito dal nome completo, dall'organizzazione e dal luogo della persona se li ha condivisi. Mettilo in un angolo della vista per mostrare alla persona che cosa la vista sa di lei oppure usalo come punto di partenza del tuo pannello del profilo.
import { useWorld } from './useWorld.js';
// The component: copy this part.
/**
* Makes the lines that say who the person is, from what they shared: their
* full name, their organization, and where they live. A line is left out
* when the person did not share any of its fields.
* @param {object|undefined} me - The person, from `world.me`.
* @returns {string[]} The lines, in order.
*/
function linesOf(me) {
const fullName = [me?.title, me?.name, me?.surname].filter(Boolean).join(' ');
const place = [me?.city, me?.country].filter(Boolean).join(', ');
return [fullName, me?.organization, place].filter(Boolean);
}
/**
* WhoAmI: who the person is, from what they chose to share with your view
* when they accepted it in the webapp: their nickname and the profile fields
* they ticked. Your view gets nothing else about them.
* @param {object} props
* @param {object} props.world - The world, from useWorld.
*/
export function WhoAmI({ world }) {
// `me` holds the nickname, always, and only the fields the person ticked.
// It is missing with a webapp older than this kit.
const me = world.me;
const lines = linesOf(me);
let note = 'What you chose to share with this view.';
if (!me) note = 'This webapp does not say who you are.';
else if (lines.length === 0) note = 'You shared only your nickname with this view.';
return (
<section aria-label="Who you are" style={{ display: 'grid', gap: 4, padding: 16, borderRadius: 14, border: '1px solid rgba(127, 127, 127, 0.3)' }}>
<strong style={{ fontSize: 18 }}>{me?.nickname ?? 'Guest'}</strong>
<div style={{ display: 'grid', gap: 2 }}>
{lines.map((text) => <span key={text}>{text}</span>)}
</div>
<small style={{ opacity: 0.75 }}>{note}</small>
</section>
);
}
// Using it, on a fake world.
// A fake world to build with. Its `me` is the person as the webapp would give them, with the fields they ticked.
const rowing = {
name: 'Rowing club',
me: { nickname: 'ada', name: 'Ada', surname: 'Rossi', organization: 'Siena Rowing Club', city: 'Siena', country: 'Italy' },
};
export default function App() {
// While building: the fake world. In the webapp: useWorld()
const { world, error } = useWorld({ fake: { world: rowing } });
if (error) return <p>Could not connect ({error.code}).</p>;
if (!world) return <p>Connecting…</p>;
return (
<div style={{ display: 'grid', gap: 12, maxWidth: 420 }}>
<h2 style={{ margin: 0 }}>{world.name}</h2>
<WhoAmI world={world} />
</div>
);
}import { connectToHost } from '@unaiverse/gui-kit';
// The component: copy this part.
/**
* Makes the lines that say who the person is, from what they shared: their
* full name, their organization, and where they live. A line is left out
* when the person did not share any of its fields.
* @param {object|undefined} me - The person, from `world.me`.
* @returns {string[]} The lines, in order.
*/
function linesOf(me) {
const fullName = [me?.title, me?.name, me?.surname].filter(Boolean).join(' ');
const place = [me?.city, me?.country].filter(Boolean).join(', ');
return [fullName, me?.organization, place].filter(Boolean);
}
/**
* Draws who the person is into `container`, then again at every change: their
* nickname and the profile fields they chose to share with your view when
* they accepted it in the webapp. Your view gets nothing else about them.
* @param {HTMLElement} container - Where to draw it.
* @param {object} world - The world, from connectToHost.
* @returns {() => void} Stops following the world and removes what it drew.
*/
export function whoAmI(container, world) {
const box = document.createElement('section');
box.setAttribute('aria-label', 'Who you are');
Object.assign(box.style, { display: 'grid', gap: '4px', padding: '16px', borderRadius: '14px', border: '1px solid rgba(127, 127, 127, 0.3)' });
const nickname = document.createElement('strong');
nickname.style.fontSize = '18px';
const details = document.createElement('div');
Object.assign(details.style, { display: 'grid', gap: '2px' });
const note = document.createElement('small');
note.style.opacity = '0.75';
box.append(nickname, details, note);
container.append(box);
// Called at once, then after every change of the world.
const stop = world.subscribe((node) => {
// `me` holds the nickname, always, and only the fields the person ticked.
// It is missing with a webapp older than this kit.
const me = node.me;
const lines = linesOf(me);
nickname.textContent = me?.nickname ?? 'Guest';
details.replaceChildren(...lines.map((text) => {
const line = document.createElement('span');
line.textContent = text;
return line;
}));
if (!me) note.textContent = 'This webapp does not say who you are.';
else note.textContent = lines.length > 0 ? 'What you chose to share with this view.' : 'You shared only your nickname with this view.';
});
return () => {
stop();
box.remove();
};
}
// Using it, on a fake world.
// A fake world to build with. Its `me` is the person as the webapp would give them, with the fields they ticked.
const rowing = {
name: 'Rowing club',
me: { nickname: 'ada', name: 'Ada', surname: 'Rossi', organization: 'Siena Rowing Club', city: 'Siena', country: 'Italy' },
};
// While building: the fake world. In the webapp: const world = await connectToHost();
const world = await connectToHost({ fake: { world: rowing } });
const page = document.createElement('div');
Object.assign(page.style, { display: 'grid', gap: '12px', maxWidth: '420px' });
const title = document.createElement('h2');
title.style.margin = '0';
title.textContent = world.name;
const place = document.createElement('div');
page.append(title, place);
document.body.append(page);
whoAmI(place, world);In world.me (Chi è la persona) il componente trova solo il nickname e i campi spuntati dalla persona. Mostra fino a tre righe: (1) titolo, nome e cognome, (2) l'organizzazione e (3) città e paese. Una riga i cui campi mancano tutti viene omessa. Sotto le righe una nota dice "What you chose to share with this view." quando c'è almeno una riga e "You shared only your nickname with this view." quando non ce n'è nessuna. Una webapp precedente al 6 novembre 2026 non fornisce me e in quel caso il componente mostra Guest con la nota "This webapp does not say who you are.".
Dato che me non porta nessuna firma, usalo per salutare la persona e per riempire la pagina ma mai per concedere qualcosa di valore sul tuo server (Scopri chi è la persona).
Props
| Prop | Predefinito | Che cos'è |
|---|---|---|
world | (obbligatorio) | Il mondo, da useWorld. |
Parametri
whoAmI(container, world) disegna il riquadro dentro container e lo ridisegna a ogni cambiamento del mondo.
| Parametro | Che cos'è |
|---|---|
container | L'elemento in cui disegnare. |
world | Il mondo, da connectToHost. |
Restituisce una funzione che annulla l'iscrizione al mondo e rimuove il riquadro.
Modificalo
- Solo il nickname: togli le righe di
linesOfe mostra soltantome.nicknamein un piccolo angolo dello schermo. - Un altro ordine: in un mondo di lavoro cambia
linesOfper mettere prima l'organizzazione. - La lingua della persona: le note sono in inglese. Scegli i tuoi testi in base a
world.webapp.language. - Un'immagine:
menon contiene nessuna immagine della persona. Disegna le sue iniziali dal nickname come faAvatarper i membri di un mondo.
Vedi anche
- Scopri chi è la persona:
mein poche righe e che cosa può farne il tuo server. identityeGuiMe: la chiamata e tutti i campi dime.- Chi è la persona.