Skip to content

Commit

Permalink
Merge pull request #352 from colonial-heritage/title-user-enrichment
Browse files Browse the repository at this point in the history
Title and language to metadata
  • Loading branch information
barbarah authored Dec 7, 2023
2 parents 1c6591a + 1c60181 commit dfb526c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {getFormatter} from 'next-intl/server';
import classNames from 'classnames';
import {InformationCircleIcon} from '@heroicons/react/24/outline';
import type {AdditionalType} from '@colonial-collections/enricher';
import ISO6391 from 'iso-639-1-dir';
import {LanguageCode} from 'iso-639-1-dir/dist/data';

const useMetadata = create<{
translationKey: string;
Expand Down Expand Up @@ -59,13 +61,15 @@ interface MetadataEntryProps {
citation?: string;
creator?: {name: string};
children?: ReactNode;
languageCode?: LanguageCode;
}

export async function MetadataEntry({
isCurrentPublisher = false,
dateCreated,
citation,
creator,
languageCode,
children,
}: MetadataEntryProps) {
const {translationKey} = useMetadata.getState();
Expand All @@ -87,7 +91,14 @@ export async function MetadataEntry({

return (
<div className="border-t border-blueGrey-100 flex flex-col lg:flex-row justify-between gap-2">
<div className="w-full lg:w-2/3 py-3 px-2">{children}</div>
<div className="w-full lg:w-2/3 py-3 px-2">
{children}
{languageCode && (
<div className="text-xs font-normal text-neutral-500 ">
{ISO6391.getName(languageCode)}
</div>
)}
</div>
<div
className={classNames(
'px-2 py-3 text-xs my-1 self-start w-full lg:w-1/3',
Expand Down Expand Up @@ -148,6 +159,7 @@ export async function MetadataEntries({children}: {children: ReactNode}) {
dateCreated={enrichment.dateCreated}
citation={enrichment.citation}
creator={enrichment.creator}
languageCode={enrichment.inLanguage as LanguageCode}
>
{enrichment.description}
</MetadataEntry>
Expand All @@ -158,7 +170,7 @@ export async function MetadataEntries({children}: {children: ReactNode}) {

export function AddMetadataEnrichment() {
const t = useTranslations('ObjectDetails');
const {enrichmentType} = useMetadata.getState();
const {enrichmentType, translationKey} = useMetadata.getState();
const objectId = useObject.getState().objectId;

if (!enrichmentType) {
Expand All @@ -172,8 +184,12 @@ export function AddMetadataEnrichment() {
id={`${enrichmentType}-form`}
className="py-2 px-3 transition flex items-center gap-1 p-1 sm:py-2 sm:px-3 rounded-full text-xs bg-neutral-200/50 hover:bg-neutral-300/50 text-neutral-800"
>
{t('addUserEnrichmentButton')}
<ChatBubbleBottomCenterTextIcon className="w-4 h-4 fill-consortiumBlue-800" />
<>
{t.rich('addUserEnrichmentButton', {
name: () => <span>{t(translationKey)}</span>,
})}
<ChatBubbleBottomCenterTextIcon className="w-4 h-4 fill-consortiumBlue-800" />
</>
</SlideOutButton>
</div>
<SlideOut id={`${enrichmentType}-form`}>
Expand Down
30 changes: 27 additions & 3 deletions apps/researcher/src/app/[locale]/(objects)/objects/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import ObjectListsMenu from './object-lists-menu';
import {SignedIn} from '@clerk/nextjs';
import {fetcher} from '@/lib/enricher-instances';
import {AdditionalType} from '@colonial-collections/enricher';
import ISO6391 from 'iso-639-1-dir';
import {LanguageCode} from 'iso-639-1-dir/dist/data';

export const dynamic = 'force-dynamic';

Expand Down Expand Up @@ -89,6 +91,9 @@ export default async function Details({params}: Props) {

const enrichments = await fetcher.getById(id);
useObject.setState({objectId: object.id, locale, enrichments});
const enrichmentsAboutName = enrichments?.filter(
enrichment => enrichment.additionalType === AdditionalType.Name
);

let organization;
if (object.isPartOf?.publisher?.id) {
Expand Down Expand Up @@ -119,15 +124,27 @@ export default async function Details({params}: Props) {
</div>
</div>

<div className="px-4 sm:px-10 my-4 flex flex-col gap-4">
<div className="px-4 sm:px-10 my-4 flex flex-col gap-4 w-full bg max-w-[1800px] mx-auto">
<h1
className="flex flex-row gap-4 gap-y-2 items-start flex-wrap text-2xl md:text-3xl"
className="text-2xl md:text-4xl md:items-center"
data-testid="page-title"
>
{object.name}
</h1>

<Notifications />
<div className="flex flex-row items-start flex-wrap">
{enrichmentsAboutName?.slice(0, 3).map(enrichment => (
<div
key={enrichment.id}
className="border-r border-neutral-200 mr-4 pr-4"
>
<div className="">{enrichment.description}</div>
<div className="text-xs font-normal hidden sm:block text-neutral-500">
{ISO6391.getName(enrichment.inLanguage as LanguageCode)}
</div>
</div>
))}
</div>

<div className="text-neutral-500 text-sm flex flex-col sm:flex-row justify-between items-start sm:items-center">
<div className="flex flex-row justify-start gap-1 ">
Expand Down Expand Up @@ -171,10 +188,17 @@ export default async function Details({params}: Props) {
</div>
<div className="flex flex-col md:flex-row h-full items-stretch grow content-stretch self-stretch gap-4 md:gap-16 w-full mx-auto px-4 sm:px-10">
<main className="w-full md:w-2/3 order-2 md:order-1">
<Notifications />
<div className=" mb-4 mt-10 flex justify-between">
<h2 className="text-2xl">{t('metadata')}</h2>
</div>
<div className="flex flex-col gap-8 self-stretch">
<MetadataContainer
translationKey="name"
enrichmentType={AdditionalType.Name}
>
<MetadataEntries>{object.name}</MetadataEntries>
</MetadataContainer>
<MetadataContainer
translationKey="description"
enrichmentType={AdditionalType.Description}
Expand Down
6 changes: 4 additions & 2 deletions apps/researcher/src/messages/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"noData": "No <subject></subject> available",
"identifier": "ID: {identifier}",
"metadata": "Metadata",
"name": "Title",
"description": "Description",
"license": "License",
"materials": "Materials",
Expand All @@ -74,7 +75,8 @@
"createNewListButton": "Create new list",
"discussion": "Discussion",
"types": "Types",
"descriptionSubTitle": "A short description about the object",
"titleSubTitle": "The name of the object.",
"descriptionSubTitle": "A short description about the object.",
"materialsSubTitle": "What kind of material is used. Click on the i of the material to learn more.",
"typesSubTitle": "",
"techniquesSubTitle": "",
Expand All @@ -85,7 +87,7 @@
"noOrganizationFound": "No organization found.",
"dateCreated": "Date Made",
"dateCreatedSubTitle": "When was the object made? Could be an exact date or a range.",
"addUserEnrichmentButton": "Add",
"addUserEnrichmentButton": "Add your narrative to <name></name>",
"noListsInCommunity": "No lists",
"objectAddedToList": "Object added to list <name></name>.",
"errorObjectAddedToList": "There was a problem adding the object to the list. Please try again later.",
Expand Down
6 changes: 4 additions & 2 deletions apps/researcher/src/messages/nl/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"noData": "Geen <subject></subject> beschikbaar",
"identifier": "ID: {identifier}",
"metadata": "Metadata",
"name": "titel",
"description": "Beschrijving",
"license": "Licentie",
"materials": "Materialen",
Expand All @@ -74,7 +75,8 @@
"createNewListButton": "Nieuwe lijst maken",
"discussion": "Discussie",
"types": "Types",
"descriptionSubTitle": "Een korte omschrijving over het object",
"nameSubTitle": "De naam van het object.",
"descriptionSubTitle": "Een korte omschrijving over het object.",
"materialsSubTitle": "Wat voor materiaal is gebruikt. Klik op de i van het materiaal voor meer informatie.",
"typesSubTitle": "",
"techniquesSubTitle": "",
Expand All @@ -85,7 +87,7 @@
"noOrganizationFound": "Geen organisatie gevonden.",
"dateCreated": "Datum van creatie",
"dateCreatedSubTitle": "Wanneer is het voorwerp gemaakt? Dit kan een exacte datum of een datumbereik zijn.",
"addUserEnrichmentButton": "Toevoegen",
"addUserEnrichmentButton": "Voeg uw verhaal toe aan <name></name>",
"noListsInCommunity": "Geen lijsten",
"objectAddedToList": "Object toegevoegd aan lijst <name></name>.",
"errorObjectAddedToList": "Er is een probleem opgetreden bij het toevoegen van het object aan de lijst. Probeer het later opnieuw.",
Expand Down

2 comments on commit dfb526c

@vercel
Copy link

@vercel vercel bot commented on dfb526c Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on dfb526c Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.