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

style: changed date formatting and pr fixes #176

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions common-util/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import get from 'lodash/get';
import isFinite from 'lodash/isFinite';
import qs from 'qs';

const URL = `${process.env.NEXT_PUBLIC_API_URL}/api`;
const API_URL = `${process.env.NEXT_PUBLIC_API_URL}/api`;

const apiCall = async (subURL, params) => {
const stringifyParams = qs.stringify(params);

try {
const url = `${URL}/${subURL}${params ? '?' : ''}${stringifyParams}`;
const url = `${API_URL}/${subURL}${params ? '?' : ''}${stringifyParams}`;
const response = await fetch(url);
const json = await response.json();
return json;
Expand Down
10 changes: 10 additions & 0 deletions common-util/formatDate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const formatDate = (date) => {
const newDate = new Date(date);
const options = {
day: '2-digit',
month: 'long',
atepem marked this conversation as resolved.
Show resolved Hide resolved
year: '2-digit',
};
const formattedDate = newDate.toLocaleDateString('en-GB', options);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const formattedDate = newDate.toLocaleDateString('en-GB', options);
const formattedDate = newDate.toLocaleDateString('en-US', options);

as we use American english, afaik the order of the day and month is different

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Mmm I think GB works better as it displays it as 11-Nov-24 instead of Nov-28,-24

Copy link
Collaborator

@truemiller truemiller Nov 29, 2024

Choose a reason for hiding this comment

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

the replace call below makes this weird

would remove the - replacement, and set as en-US, not 100% on product preference, but US > GB in market share

- dates tend~ to be for numeric dates

minor either way, clock still ticks haha

return formattedDate.replace(/ /g, '-');
};
5 changes: 4 additions & 1 deletion common-util/useFetchApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ export const useFetchVideos = (limit = 1000) => {
thumbnail,
video: videoUploaded,
} = attributes || {};
const imageFilename = `${process.env.NEXT_PUBLIC_API_URL}${get(thumbnail, 'data.attributes.url') || ''}`;
const thumbnailUrl = get(thumbnail, 'data.attributes.url');
const imageFilename = thumbnailUrl
? `${process.env.NEXT_PUBLIC_API_URL}${thumbnailUrl}`
: '';
const video_url = `${process.env.NEXT_PUBLIC_API_URL}${get(videoUploaded, 'data[0].attributes.url') || ''}`;
atepem marked this conversation as resolved.
Show resolved Hide resolved

return {
Expand Down
8 changes: 5 additions & 3 deletions components/Content/Article.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import PropTypes from 'prop-types';
import { useMemo, useState } from 'react';

import { CARD_CLASS } from 'common-util/classes';
import { formatDate } from 'common-util/formatDate';

const imageDomain = process.env.NEXT_PUBLIC_API_URL;

Expand All @@ -22,20 +23,21 @@ const Article = ({ article, href, showReadTime, showDate }) => {

const { title, datePublished, readTime } = article.attributes;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const { title, datePublished, readTime } = article.attributes;
const { title, datePublished: unFormattedDatePublished, readTime } = article.attributes;

const { url, width, height } = image || {};
const formattedDate = formatDate(datePublished);
atepem marked this conversation as resolved.
Show resolved Hide resolved

const moreInfo = useMemo(() => {
const moreInfoArray = [];

if (showDate && datePublished) {
moreInfoArray.push(datePublished);
if (showDate && formattedDate) {
moreInfoArray.push(formattedDate);
}

if (showReadTime && readTime) {
moreInfoArray.push(`${readTime} ${readTime === 1 ? 'MIN' : 'MINS'} READ`);
}

return moreInfoArray.join(' • ');
}, [showDate, datePublished, showReadTime, readTime]);
}, [showDate, formattedDate, showReadTime, readTime]);

return (
<Link href={href}>
Expand Down
4 changes: 2 additions & 2 deletions components/Content/Articles.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import useSWR from 'swr';
import { Spinner } from '../Spinner';
import Article from './Article';

const URL = `${process.env.NEXT_PUBLIC_API_URL}/api`;
const API_URL = `${process.env.NEXT_PUBLIC_API_URL}/api`;
const subURL = 'blog-posts';
const fetcher = (...args) => fetch(...args).then((res) => res.json());

Expand All @@ -21,7 +21,7 @@ const Articles = ({ limit, showSeeAll, displayFolders }) => {
const stringifyParams = qs.stringify(params);

const { data, isLoading } = useSWR(
`${URL}/${subURL}${params ? '?' : ''}${stringifyParams}`,
`${API_URL}/${subURL}${params ? '?' : ''}${stringifyParams}`,
fetcher,
);

Expand Down
9 changes: 6 additions & 3 deletions components/Content/Videos.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import { Spinner } from 'components/Spinner';
import Image from 'next/image';

import { CARD_CLASS } from 'common-util/classes';
import { formatDate } from 'common-util/formatDate';

const Video = ({ video }) => (
<a
href={video.platform_link || video.drive_link || video.video_url}
target="_blank"
rel="noopener noreferrer"
>
<article
<div
className={`${CARD_CLASS} max-w-full h-full overflow-hidden min-h-[300px] `}
>
{video.imageFilename && (
Expand All @@ -30,10 +31,12 @@ const Video = ({ video }) => (
{video.title}
</h2>
<div className="text-gray-500 mt-auto">
<span className="text-sm md:text-xl lg:text-sm">{video.date}</span>
<span className="text-sm md:text-xl lg:text-sm">
{formatDate(video.date)}
</span>
</div>
</div>
</article>
</div>
</a>
);

Expand Down
8 changes: 5 additions & 3 deletions components/HomepageSection/Media.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ import Articles from 'components/Content/Articles';
import { Videos } from 'components/Content/Videos';
import SectionWrapper from 'components/Layout/SectionWrapper';

const limit = 3;
atepem marked this conversation as resolved.
Show resolved Hide resolved

const Media = () => {
const { videos, isLoading } = useFetchVideos(3);
const { videos, isLoading } = useFetchVideos(limit);

return (
<SectionWrapper
backgroundType="SUBTLE_GRADIENT"
customClasses="px-4 md:px-8 py-12 lg:p-24 border-b"
>
<div className="max-w-screen-xl mx-auto flex flex-col gap-10">
<Videos isLoading={isLoading} videos={videos} limit={3} />
<Articles limit={3} tagFilter="bonds" showSeeAll />
<Videos isLoading={isLoading} videos={videos} limit={limit} />
<Articles limit={limit} tagFilter="bonds" showSeeAll />
</div>
</SectionWrapper>
);
Expand Down
4 changes: 3 additions & 1 deletion pages/blog/[id].jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getBlog } from 'common-util/api';
import { formatDate } from 'common-util/formatDate';
import Markdown from 'common-util/Markdown';
import PageWrapper from 'components/Layout/PageWrapper';
import Meta from 'components/Meta';
Expand Down Expand Up @@ -28,6 +29,7 @@ const BlogItem = () => {
body: content,
headerImage,
} = blogItem.attributes;
const formattedDate = formatDate(datePublished);
const imagePath = headerImage?.data?.[0]?.attributes?.formats?.large?.url;
const imageUrl = `${process.env.NEXT_PUBLIC_API_URL}${imagePath}`;

Expand All @@ -46,7 +48,7 @@ const BlogItem = () => {
/>
)}
<div className={`${TITLE.SMALL} mb-4`}>{title}</div>
<div className={`${TEXT} mb-4`}>{datePublished}</div>
<div className={`${TEXT} mb-4`}>{formattedDate}</div>
<Markdown>{content}</Markdown>
</div>
</PageWrapper>
Expand Down