Skip to content

Commit

Permalink
User Group - Adding Youtube Playlist (#2216)
Browse files Browse the repository at this point in the history
* User Groups - Adding youtube playlist

* Refactoring code for generic use

* Adding Visual editing functionality for Youtube playlist component

* Update schema.json

* Fixing cursor pointer issue on video card

* Fixing UI and adding readmore functionality

* Fixing spacing between playlist button

* Expanding map based on presenter's block

* Mobile - Fixing button alignment on small screens

* Fixing background for the contact us tab

* Removing fields that are not in used

* removing random field
  • Loading branch information
amankumarrr authored Feb 29, 2024
1 parent fa32992 commit 951ffb9
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 188 deletions.
2 changes: 1 addition & 1 deletion .tina/__generated__/_graphql.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .tina/__generated__/_schema.json

Large diffs are not rendered by default.

42 changes: 2 additions & 40 deletions .tina/collections/usergroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { seoSchema } from "../../components/util/seo";

import React from "react";
import type { Collection } from "tinacms";
import { youtubePlaylistSchema } from "../../components/blocks/youtubePlaylist";
import { tipField } from "./shared-fields";

export const userGroupPageSchema: Collection = {
Expand Down Expand Up @@ -242,46 +243,7 @@ export const userGroupGlobalSchema: Collection = {
},
],
},
{
type: "object",
label: "Videos",
name: "videos",
list: true,
fields: [
{
type: "string",
label: "Link",
name: "link",
},
{
type: "string",
label: "Title",
name: "title",
},
],
ui: {
itemProps: (item) => ({
label: item?.title,
}),
},
},
{
type: "object",
label: "Featured Videos Button options",
name: "videosButton",
fields: [
{
type: "string",
label: "Link",
name: "link",
},
{
type: "string",
label: "Text",
name: "text",
},
],
},
youtubePlaylistSchema,
{
type: "object",
label: "Join Us Panel",
Expand Down
4 changes: 2 additions & 2 deletions components/blocks/aboutUs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ const AccordionItem = ({
<li>
<div
className={classNames(
"group mb-2 flex cursor-pointer items-center justify-between p-2 transition-all duration-500",
"group flex cursor-pointer items-center justify-between p-2 transition-all duration-500",
currentlySelected
? "bg-sswRed"
: onHover
Expand Down Expand Up @@ -254,7 +254,7 @@ const AccordionItem = ({

<div
className={classNames(
"overflow-hidden transition-all duration-500",
"overflow-hidden transition-all duration-500 mb-2 bg-white",
currentlySelected ? "max-h-52" : "max-h-0"
)}
>
Expand Down
63 changes: 43 additions & 20 deletions components/blocks/youtubePlaylist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@ import axios from "axios";
import { Key, useEffect, useState } from "react";
import { BsArrowRightCircle } from "react-icons/bs";
import { Template, TinaField } from "tinacms";
import { tinaField } from "tinacms/dist/react";
import { VideoLink } from "../../services/server/youtube";
import { CustomLink } from "../customLink";
import { VideoCard } from "../util/videoCards";

export type YoutubePlaylistProps = {
title?: string;
playlistId: string;
numberOfVideos: number;
textForPlaylistLink?: string;
videosCount?: number;
playlistButton?: {
text?: string;
link?: string;
animated?: boolean;
};
};

export const YoutubePlaylistBlock: React.FC<YoutubePlaylistProps> = ({
title,
playlistId,
textForPlaylistLink,
numberOfVideos,
}) => {
export const YoutubePlaylistBlock: React.FC<YoutubePlaylistProps> = (props) => {
const { title, playlistId, videosCount, playlistButton } = props;
const [playlistVideosLinks, setPlaylistVideosLinks] = useState([]);

useEffect(() => {
Expand All @@ -28,7 +29,7 @@ export const YoutubePlaylistBlock: React.FC<YoutubePlaylistProps> = ({
.get<VideoLink[]>("/api/get-youtube-playlist", {
params: {
playlistId: playlistId,
videosCount: numberOfVideos,
videosCount: videosCount,
},
})
.then((response) => {
Expand All @@ -40,10 +41,10 @@ export const YoutubePlaylistBlock: React.FC<YoutubePlaylistProps> = ({
}
};

if (playlistId && numberOfVideos) {
if (playlistId && videosCount) {
fetchPlaylist();
}
}, [playlistId, numberOfVideos]);
}, [playlistId, videosCount]);

if (!playlistId) {
return <></>;
Expand All @@ -60,13 +61,17 @@ export const YoutubePlaylistBlock: React.FC<YoutubePlaylistProps> = ({
<VideoCard {...video} theme="light" key={index} />
))}
</div>
{textForPlaylistLink && (
{playlistButton?.text && (
<div className="flex justify-center">
<CustomLink
href={`https://www.youtube.com/playlist?list=${playlistId}`}
className="done relative mx-2 mt-8 inline-flex overflow-hidden rounded border-none bg-sswRed pl-3 text-white"
href={`https://www.youtube.com/playlist?list=${
playlistButton?.link || playlistId
}`}
className="done relative mx-2 mb-6 mt-8 inline-flex overflow-hidden rounded border-none bg-sswRed pl-3 text-white"
data-aos={playlistButton.animated ? "fade-up" : undefined}
data-tina-field={tinaField(props.playlistButton, "text")}
>
{textForPlaylistLink}
{playlistButton.text}
<BsArrowRightCircle className="ml-1 inline" />
</CustomLink>
</div>
Expand Down Expand Up @@ -98,14 +103,32 @@ export const youtubePlaylistSchema: TinaField = {
},
{
type: "number",
label: "Number of vidoes",
name: "numberOfVideos",
label: "Videos Count",
name: "videosCount",
required: true,
},
{
type: "string",
name: "textForPlaylistLink",
label: "Text for Playlist link",
type: "object",
label: "Playlist Button",
name: "playlistButton",
fields: [
{
type: "string",
name: "text",
label: "Text",
},
{
type: "string",
name: "link",
label: "Link",
description: "DEFAULT: PlaylistId.",
},
{
type: "boolean",
name: "animated",
label: "Animated?",
},
],
},
],
};
Expand Down
6 changes: 4 additions & 2 deletions components/usergroup/readMore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ type ReadMoreProps = {
className?: string;
};

const sentenceSeparator = /\. |\.\n|\.\r|! |!\n|!\r/; // Matches "." or "!" followed by a space or a new line

const getCondensedText = (
text: string,
length: number,
previewSentenceCount: number
) => {
const formatted = text.split(". ");
const formatted = text.split(sentenceSeparator);
const selectedParagraphs = formatted.slice(0, previewSentenceCount);
const condensedText = selectedParagraphs.join(". ");

Expand All @@ -41,7 +43,7 @@ export const ReadMore = ({
const isReadMoreRequired = () =>
(length > 0 && text.length > length) ||
(previewSentenceCount > 1 &&
text.split(". ").length > previewSentenceCount);
text.split(sentenceSeparator).length > previewSentenceCount);

const condensedText = isReadMoreRequired()
? getCondensedText(sanitizedText, length, previewSentenceCount)
Expand Down
90 changes: 30 additions & 60 deletions components/usergroup/sections/videos.tsx
Original file line number Diff line number Diff line change
@@ -1,77 +1,47 @@
import Image from "next/image";
import type { Template } from "tinacms";
import { tinaField } from "tinacms/dist/react";
import { UtilityButton } from "../../blocks";
import {
YoutubePlaylistBlock,
YoutubePlaylistProps,
} from "../../blocks/youtubePlaylist";
import { Container } from "../../util/container";
import { VideoCard } from "../../util/videoCards";

type VideoType = {
link?: string;
title?: string;
};

type VideosSectionProps = {
globalUserGroupInfo?: {
videos?: VideoType[];
videosButton?: {
link?: string;
text?: string;
};
youtubePlaylist: YoutubePlaylistProps;
};
};

export const VideosSection = (props: VideosSectionProps) => {
const button = props.globalUserGroupInfo?.videosButton;
const youtubePlaylistProps = props.globalUserGroupInfo.youtubePlaylist;

return (
<section>
<Container>
<div>
<div className="flex flex-col items-center">
<div className="mb-12 flex-row items-center justify-center text-center md:flex">
<h2 className="!my-0 text-4xl font-semibold">
<span className="text-sswRed">Featured Videos </span> from{" "}
</h2>{" "}
<Image
src="/images/sswtv_logo.png"
alt="SSW TV logo"
className="mx-auto shrink-0 grow-0 object-contain pl-4"
height={50}
width={200}
/>
</div>
<div className="grid grid-cols-1 justify-center gap-8 lg:grid-cols-3">
{props.globalUserGroupInfo?.videos?.map((video, index) => (
<div
data-tina-field={tinaField(
props.globalUserGroupInfo?.videos[index],
"title"
)}
key={index}
>
<VideoCard {...video} theme="light" />
</div>
))}
</div>
{button && button.text && button.link && (
<div
data-tina-field={tinaField(
props.globalUserGroupInfo.videosButton,
"text"
)}
>
<UtilityButton
link={button.link}
buttonText={button.text}
className="mx-auto text-base font-semibold"
animated
/>
</div>
)}
</div>
<Container>
<div className="flex flex-col items-center">
<div className="mb-12 flex-row items-center justify-center text-center md:flex">
<h2 className="!my-0 text-4xl font-semibold">
<span className="text-sswRed">Featured Videos </span> from{" "}
</h2>{" "}
<Image
src="/images/sswtv_logo.png"
alt="SSW TV logo"
className="mx-auto shrink-0 grow-0 object-contain pl-4"
height={50}
width={200}
/>
</div>
</Container>
</section>
<section
data-tina-field={tinaField(
props.globalUserGroupInfo.youtubePlaylist,
"playlistId"
)}
>
{" "}
<YoutubePlaylistBlock {...youtubePlaylistProps} />
</section>
</div>
</Container>
);
};

Expand Down
3 changes: 1 addition & 2 deletions components/util/videoCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export const VideoCard: FC<VideoCardProps> = ({ link, title, theme }) => {
<VideoModal
url={link}
className={
theme === "light" &&
"h-full !cursor-pointer rounded-sm border-1 border-gray-200"
theme === "light" && "h-full rounded-sm border-1 border-gray-200"
}
>
<div className={classNames("flex justify-between bg-white p-5 h-full")}>
Expand Down
2 changes: 1 addition & 1 deletion components/videoModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const VideoModal = ({
className
)}
>
<div className="relative mx-auto aspect-video w-full">
<div className="relative mx-auto aspect-video w-full cursor-pointer">
{!clicked ? (
<div className="size-full" onClick={() => setClicked(true)}>
{imageSrc && (
Expand Down
2 changes: 1 addition & 1 deletion content/consulting/consulting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ If you are a new customer we need to schedule a free initial meeting. If you're
<YoutubePlaylistBlock
youtubePlaylist={{
playlistId: "PLpiOR7CBNvlovBGeEB3vVhYzVWYnkFpA-",
numberOfVideos: 6
videosCount: 6
}}
/>
</>}
Expand Down
7 changes: 5 additions & 2 deletions content/live/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ sswTvButton:
youtubePlaylist:
title: Recent Broadcasts
playlistId: PLpiOR7CBNvlpmhfwQeIVhbqZKxV-do0wY
numberOfVideos: 6
textForPlaylistLink: 'View more on Youtube'
videosCount: 6
playlistButton:
text: View more on Youtube
animated: false
---

User Group Live

Every 3rd Wednesday of the month at 6.30PM (Sydney time)
Expand Down
22 changes: 6 additions & 16 deletions content/netug/global/global.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,13 @@
],
"random": false
},
"videos": [
{
"link": "https://www.youtube.com/watch?v=dMgj1MdwrRE",
"title": "Pick a Side - Clean vs Vertical Slice Architecture | Luke Parker"
},
{
"link": "https://www.youtube.com/watch?v=gZ9VabDU81A",
"title": "Rules to Better Chat GPT and Using the Best API Ever | Adam Cogan"
},
{
"link": "https://www.youtube.com/watch?v=K1t73xArqs0",
"title": "Beyond Passwords: The Future (and Present) of Authentication | Matt Goldman"
"youtubePlaylist": {
"playlistId": "PLpiOR7CBNvlpmhfwQeIVhbqZKxV-do0wY",
"videosCount": 3,
"playlistButton": {
"text": "Watch more on the SSW TV YouTube channel",
"animated": true
}
],
"videosButton": {
"link": "https://www.youtube.com/watch?v=dMgj1MdwrRE&list=PLpiOR7CBNvlpmhfwQeIVhbqZKxV-do0wY",
"text": "Watch more on the SSW TV YouTube channel"
},
"joinUs": {
"link": "https://ssw.com.au/netug/present",
Expand Down
Loading

0 comments on commit 951ffb9

Please sign in to comment.