Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💸 Presenter has needlessly nested props #2967

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
31 changes: 29 additions & 2 deletions .github/workflows/get-people-profiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,25 @@ const GetPeopleProfiles = async ( {
presenterJson = existingPresenterFile.data;
}

const remoteData = peopleMatter.data;

// this is required to flatten presenter object
if (!!presenterJson.presenter) {
presenterJson = flattenObject(presenterJson);
}

// this is required to flatten presenter object
if (!!remoteData.presenter) {
remoteData = flattenObject(remoteData);
}

// merge remote data with existing data giving preference to remote data
presenterJson = {
...presenterJson,
...peopleMatter.data,
...remoteData,
};

const personName = presenterJson.presenter?.name?.split(' ')?.join('-') ?? 'not-found';
const personName = presenterJson.name?.split(' ')?.join('-') ?? 'not-found';
const profileImageRelativePath = `${peopleImagePath}/${personName}.jpg`;
const peopleProfileImagePath = `${peopleDirectory}/${personName}/Images/${personName}-Profile.jpg`;

Expand All @@ -60,4 +73,18 @@ const GetPeopleProfiles = async ( {
}
}

const flattenObject = (obj) => {
const flattened = {};

for (const [key, value] of Object.entries(obj)) {
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
Object.assign(flattened, flattenObject(value));
} else {
flattened[key] = value;
}
}

return flattened;
};

module.exports = GetPeopleProfiles;
14 changes: 6 additions & 8 deletions app/live-steam-banner/liveStreamWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import Script from "next/script";
import { useEffect, useState } from "react";
import { TfiAngleDown, TfiAngleUp } from "react-icons/tfi";
import { Tooltip } from "react-tooltip";
import { LiveStreamProps } from "../../hooks/useLiveStreamProps";
import { TinaMarkdown } from "tinacms/dist/rich-text";
import { LiveStreamProps } from "../../hooks/useLiveStreamProps";

type LiveStreamWidgetProps = {
isLive?: boolean;
Expand Down Expand Up @@ -290,23 +290,21 @@ export const LiveStreamWidget = ({ isLive, event }: LiveStreamWidgetProps) => {
{!!presenterDetails.profileImg && (
<Image
src={presenterDetails.profileImg}
alt={presenterDetails.presenter.name}
alt={presenterDetails.name}
width={200}
height={200}
/>
)}
</div>
<div className="col-span-5">
<p className="mb-3 font-bold">
{presenterDetails.presenter.name}
</p>
<p className="mb-3 font-bold">{presenterDetails.name}</p>
<TinaMarkdown content={presenterDetails.about} />
{!!presenterDetails.presenter.peopleProfileURL && (
{!!presenterDetails.peopleProfileURL && (
<CustomLink
className="float-right border-b-1 border-dotted border-gray-450 !no-underline"
href={presenterDetails.presenter.peopleProfileURL}
href={presenterDetails.peopleProfileURL}
>
{`${presenterDetails.presenter.name}'s profile >`}
{`${presenterDetails.name}'s profile >`}
</CustomLink>
)}
</div>
Expand Down
2 changes: 1 addition & 1 deletion components/articles/articlesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const ArticlesList = () => {
url: `/articles/${filename}`,
title,
authorImage: author?.profileImg,
authorName: author?.presenter?.name,
authorName: author?.name,
authorPosition: author?.position,
body: description,
};
Expand Down
14 changes: 6 additions & 8 deletions components/liveStream/liveStreamWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Script from "next/script";
import { useEffect, useState } from "react";
import { TfiAngleDown, TfiAngleUp } from "react-icons/tfi";
import { Tooltip } from "react-tooltip";
import { TinaMarkdown } from "tinacms/dist/rich-text";
import layoutData, {
default as globals,
} from "../../content/global/index.json";
Expand All @@ -18,7 +19,6 @@ import { InlineJotForm } from "../blocks";
import { CustomLink } from "../customLink";
import { YouTubeEmbed } from "../embeds/youtubeEmbed";
import { SocialIcons } from "../socialIcons/socialIcons";
import { TinaMarkdown } from "tinacms/dist/rich-text";

type LiveStreamWidgetProps = {
isLive?: boolean;
Expand Down Expand Up @@ -291,23 +291,21 @@ export const LiveStreamWidget = ({ isLive, event }: LiveStreamWidgetProps) => {
{!!presenterDetails.profileImg && (
<Image
src={presenterDetails.profileImg}
alt={presenterDetails.presenter.name}
alt={presenterDetails.name}
width={200}
height={200}
/>
)}
</div>
<div className="col-span-5">
<p className="mb-3 font-bold">
{presenterDetails.presenter.name}
</p>
<p className="mb-3 font-bold">{presenterDetails.name}</p>
<TinaMarkdown content={presenterDetails.about} />
{!!presenterDetails.presenter.peopleProfileURL && (
{!!presenterDetails.peopleProfileURL && (
<CustomLink
className="float-right border-b-1 border-dotted border-gray-450 !no-underline"
href={presenterDetails.presenter.peopleProfileURL}
href={presenterDetails.peopleProfileURL}
>
{`${presenterDetails.presenter.name}'s profile >`}
{`${presenterDetails.name}'s profile >`}
</CustomLink>
)}
</div>
Expand Down
6 changes: 3 additions & 3 deletions components/training/presenterBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ const PresenterCard = ({ presenter, schema, index }) => {
className="not-prose flex flex-col items-center"
data-tina-field={tinaField(
schema[index].presenter,
presenterSchemaConstants.presenter.peopleProfileURL
presenterSchemaConstants.peopleProfileURL
)}
>
<span className="size-32 overflow-hidden rounded-full">
<Image
alt={`Picture of ${presenter?.presenter?.name ?? "Presenter"}`}
alt={`Picture of ${presenter?.name ?? "Presenter"}`}
src={presenter?.profileImg ?? ""}
height={120}
width={120}
Expand All @@ -79,7 +79,7 @@ const PresenterCard = ({ presenter, schema, index }) => {
className="mt-4 font-normal"
data-tina-field={tinaField(
schema[index].presenter?.presenter,
presenterSchemaConstants.presenter.name
presenterSchemaConstants.name
)}
>
{presenter?.presenter?.name}
Expand Down
4 changes: 2 additions & 2 deletions pages/articles/[filename].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ export default function ArticlesPage(
{!!data.articles.author && (
<Section className="mx-auto w-full max-w-9xl px-8">
<ArticleAuthor
name={author?.presenter?.name}
name={author?.name}
position={author?.position}
image={author?.profileImg}
url={author?.presenter?.peopleProfileURL}
url={author?.peopleProfileURL}
/>
</Section>
)}
Expand Down
8 changes: 3 additions & 5 deletions services/server/events.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TinaMarkdownContent } from "tinacms/dist/rich-text";
import { EventTrimmed } from "../../components/filter/events";
import client from "../../tina/__generated__/client";
import { TinaMarkdownContent } from "tinacms/dist/rich-text";

/**
* Querying TinaCMS event data for the next UG event
Expand Down Expand Up @@ -87,10 +87,8 @@ export interface EventInfo extends EventTrimmed {
presenter?: {
profileImg?: string;
torsoImg?: string;
presenter?: {
name?: string;
peopleProfileURL?: string;
};
name?: string;
peopleProfileURL?: string;
about?: TinaMarkdownContent;
tip?: string;
};
Expand Down
30 changes: 10 additions & 20 deletions tina/collections/presenter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ export const presenterSchemaConstants = {
value: "presenter",
profileImg: "profileImg",
torsoImg: "torsoImg",
presenter: {
value: "presenter",
name: "name",
peopleProfileURL: "peopleProfileURL",
},
name: "name",
peopleProfileURL: "peopleProfileURL",
about: "about",
position: "position",
skills: "skills",
Expand Down Expand Up @@ -39,21 +36,14 @@ export const presenterSchema: Collection = {
uploadDir: () => "people",
},
{
type: "object",
name: presenterSchemaConstants.presenter.value,
label: "Presenter",
fields: [
{
type: "string",
label: "Full Name",
name: presenterSchemaConstants.presenter.name,
},
{
type: "string",
label: "People Profile URL",
name: presenterSchemaConstants.presenter.peopleProfileURL,
},
],
type: "string",
label: "Full Name",
name: presenterSchemaConstants.name,
},
{
type: "string",
label: "People Profile URL",
name: presenterSchemaConstants.peopleProfileURL,
},
{
type: "rich-text",
Expand Down
2 changes: 1 addition & 1 deletion tina/tina-lock.json

Large diffs are not rendered by default.

Loading