Skip to content

Commit

Permalink
feat: remove unnecessary prop lifting
Browse files Browse the repository at this point in the history
  • Loading branch information
fbuireu committed Aug 1, 2024
1 parent fae958e commit db6e8fc
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 57 deletions.
26 changes: 13 additions & 13 deletions src/application/dto/tag/utils/getArticlesByTag/getArticlesByTag.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { ArticleDTO } from "@application/dto/article/types.ts";
import type { RawTag } from "@application/dto/tag/types.ts";

interface GetArticlesProps {
tag: RawTag;
articles: ArticleDTO[];
}

export function getArticlesByTag({ tag, articles }: GetArticlesProps) {
return articles.filter((article) =>
article.tags.map((tag) => tag.slug).includes(tag.fields.slug as unknown as string),
);
}
import type { ArticleDTO } from "@application/dto/article/types.ts";
import type { RawTag } from "@application/dto/tag/types.ts";

interface GetArticlesProps {
tag: RawTag;
articles: ArticleDTO[];
}

export function getArticlesByTag({ tag, articles }: GetArticlesProps) {
return articles.filter((article) =>
article.tags.map((tag) => tag.slug).includes(tag.fields.slug as unknown as string),
);
}
2 changes: 1 addition & 1 deletion src/application/dto/tag/utils/getArticlesByTag/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./getArticlesByTag.ts";
export * from "./getArticlesByTag.ts";
2 changes: 1 addition & 1 deletion src/pages/about.astro
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const bianca = (await authorDTO.render(rawAuthors as RawAuthor[]))
---

<BaseLayout title="" description="">
<Breadcrumbs classNames="about-page" />
<Breadcrumbs />
<AboutIntro />
<LittleMoreOfMe client:only="react" cities={cities} />
<AboutLatestArticles />
Expand Down
2 changes: 1 addition & 1 deletion src/pages/articles/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const { article } = Astro.props as ArticleProps;
</section>
)
}
<Breadcrumbs classNames="article-page" />
<Breadcrumbs />
<div class="article__details">
<h1 class="article__title">
{article.title}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/articles/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const featuredArticle = getFeaturedArticle(articles);

<BaseLayout title="" description="">
<h1 class="articles__title section-title">The Blog</h1>
<Breadcrumbs classNames="articles-page" />
<Breadcrumbs />
<FeaturedArticle featuredArticle={featuredArticle} />
<section class="articles__grid common-wrapper">
<ul class="articles__grid__list flex row-wrap justify-space-between">
Expand Down
2 changes: 1 addition & 1 deletion src/pages/contact.astro
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Breadcrumbs from '@shared/ui/components/breadcrumbs/Breadcrumbs.astro';
import LatestArticles from '@shared/ui/components/latestArticles/LatestArticles.astro';---
<BaseLayout title="" description="">
<Breadcrumbs classNames="contact-page" />
<Breadcrumbs />
<ContactIntro />
<Tabs />
<LatestArticles />
Expand Down
1 change: 0 additions & 1 deletion src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Welcome from "@modules/home/components/welcome/Welcome.astro";
import BaseLayout from "@shared/ui/components/baseLayout/BaseLayout.astro";
import LatestArticles from "@shared/ui/components/latestArticles/LatestArticles.astro";
// todo: use location for breadrumbs instead of passing the classname
// todo: add related articles card?
// todo: how to deploy cloudfare pages
// todo: add thinner svg lines
Expand Down
2 changes: 1 addition & 1 deletion src/pages/tags/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const tags = await tagDTO.render(rawTags as RawTag[]);
---

<BaseLayout title="" description="">
<Breadcrumbs classNames="tags-page" />
<Breadcrumbs />
<section class="common-wrapper">
<h1 class="flex justify-center">All tags</h1>
<ul class="tags__list flex row-wrap">
Expand Down
32 changes: 16 additions & 16 deletions src/shared/ui/components/articleCard/ArticleCard.astro
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
---
import { Image } from "astro:assets";
import type { ArticleDTO } from "@application/dto/article/types";
import { ArticleType } from "@application/dto/article/types";
import clsx from "clsx";
import { getLocation } from "./utils/getLocation";
import "./article-card.css";
export interface ArticleCardProps extends ArticleDTO {
origin: URL;
href: string;
}
const { href, title, description, variant, featuredImage, publishDate, author, tags } = Astro.props as ArticleCardProps;
const { pathname } = Astro.url;
const origin = getLocation(Astro.url);
import { Image } from "astro:assets";
import type { ArticleDTO } from "@application/dto/article/types";
import { ArticleType } from "@application/dto/article/types";
import clsx from "clsx";
import { getLocation } from "./utils/getLocation";
import "./article-card.css";
export interface ArticleCardProps extends ArticleDTO {
origin: URL;
href: string;
}
const { href, title, description, variant, featuredImage, publishDate, author, tags } = Astro.props as ArticleCardProps;
const { pathname } = Astro.url;
const origin = getLocation(Astro.url);
---

<a class="article__link-card" href={href} aria-label={title}>{" "}</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const PATHS_MAP = {
article: "/articles/",
articles: "/articles",
about: "/about",
tag: "/tag",
tags: "/tags",
contact: "/contact",
home: "/",
};

Expand Down
21 changes: 8 additions & 13 deletions src/shared/ui/components/breadcrumbs/Breadcrumbs.astro
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
---
import { breadcrumbDTO } from "@application/dto/breadcrumb/breadcrumbDTO";
import "./breadcrumbs.css";
interface BreadcrumbProps {
classNames?: string;
}
const { classNames } = Astro.props as BreadcrumbProps;
const { pathname: currentPath, origin } = Astro.url;
const breadcrumbs = breadcrumbDTO.render({ currentPath });
import { breadcrumbDTO } from "@application/dto/breadcrumb/breadcrumbDTO";
import { getLocation } from "../articleCard/utils/getLocation";
import "./breadcrumbs.css";
const breadcrumbs = breadcrumbDTO.render({ currentPath: Astro.url.pathname });
const origin = getLocation(Astro.url);
---

<section class:list={[`breadcrumbs__wrapper ${classNames}`, { 'common-wrapper': classNames }]}>
<section class:list={[`breadcrumbs__wrapper common-wrapper`, `--is-${origin}` ]}>
<ul class="breadcrumbs__list flex justify-center align-center font-sans-serif">
{breadcrumbs?.map(({ link, label }, index) => {
const isLast = breadcrumbs.at(-1).link === link
Expand All @@ -29,7 +24,7 @@ const breadcrumbs = breadcrumbDTO.render({ currentPath });
"@type": "ListItem",
"position": index + 1,
"item": {
"@id": `${origin}${link}`,
"@id": `${Astro.url.origin}${link}`,
"name": label
}
})}/>
Expand Down
11 changes: 6 additions & 5 deletions src/shared/ui/components/breadcrumbs/breadcrumbs.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,29 @@
color: var(--primary-main)
}

.article-page .breadcrumbs__list {

.--is-article .breadcrumbs__list {
justify-content: flex-start;
margin: 0 auto;
max-width: var(--grid-small);
padding-block-start: 2rem;
width: 100%;
}

.articles-page .breadcrumbs__list {
.--is-articles .breadcrumbs__list {
margin-bottom: 5rem;

@media (width <= 960px) {
margin-bottom: 2rem;
}
}

.projects-page .breadcrumbs__list{
.--is-projects .breadcrumbs__list{
display: none;
}

.about-page .breadcrumbs__list,
.contact-page .breadcrumbs__list {
.--is-about .breadcrumbs__list,
.--is-contact .breadcrumbs__list {
justify-content: flex-start;
padding-top: 2rem;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
import Breadcrumbs from "@shared/ui/components/breadcrumbs/Breadcrumbs.astro";
import "./projects-intro.css";
import Breadcrumbs from "@shared/ui/components/breadcrumbs/Breadcrumbs.astro";
import "./projects-intro.css";
---
<section class="projects-intro__wrapper">
<h1 class="articles__title section-title">Projects</h1>
<Breadcrumbs classNames="projects-page" />
<Breadcrumbs />
</section>

0 comments on commit db6e8fc

Please sign in to comment.