Skip to content

Commit

Permalink
Misc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
catalinred committed Sep 8, 2024
1 parent e7bc4f0 commit 004163e
Show file tree
Hide file tree
Showing 12 changed files with 413 additions and 120 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: installing_yarn
run: yarn install
- name: formatting
run: yarn format
run: yarn format:check
stage:
name: Test linting...
needs: Format
Expand All @@ -37,4 +37,4 @@ jobs:
- name: installing_yarn & lint
run: |
yarn install
yarn run lint
yarn lint
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
yarn format
yarn format:check
yarn lint
15 changes: 4 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "solana-com",
"private": true,
"description": "The solana.com website",
"version": "3.0.0",
"author": "Solana Maintainers",
Expand Down Expand Up @@ -70,27 +69,21 @@
"eslint-plugin-react-hooks": "^4.6.2",
"husky": "^9.0.11",
"next-sitemap": "^4.2.3",
"next-transpile-modules": "^10.0.1",
"postcss": "^8.4.38",
"postcss-preset-env": "^9.5.14",
"prettier": "^3.2.5",
"svg-react-loader": "^0.4.6",
"typescript": "^5.4.5"
},
"scripts": {
"build": "echo 'Building solana-com...' && next build",
"build": "next build",
"dev": "next",
"develop": "yarn dev",
"start": "next start",
"format": "prettier --check \"**/*.{js,jsx,ts,tsx,json,md,scss}\"",
"format:fix": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md,scss}\"",
"format:check": "prettier --check \"**/*.{js,jsx,ts,tsx,json,md,scss}\"",
"format:all": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md,scss}\"",
"lint": "next lint",
"lint:fix": "yarn lint --fix",
"vdev": "vercel dev --debug",
"lint:fix": "next lint --fix",
"postbuild": "next-sitemap",
"prepare": "husky"
},
"msw": {
"workerDirectory": "public"
}
}
24 changes: 17 additions & 7 deletions src/components/ModalLauncher/ModalLauncher.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { useEffect, useState, useRef, createElement } from "react";
import {
useEffect,
useState,
useRef,
createElement,
useCallback,
useMemo,
} from "react";
import { useRouter } from "next/router";
import { Modal, CloseButton } from "react-bootstrap";
import ArtistsAndCreatorsNewsletter from "../newsletter/artistsAndCreators";
Expand All @@ -10,11 +17,14 @@ const ModalLauncher = () => {
const [modalLaunchId, setModalLaunchId] = useState("default");
const modalActionCompleted = useRef(false);

const modalMapping = {
artistAndCreatorsNewsletter: ArtistsAndCreatorsNewsletter,
};
const modalMapping = useMemo(
() => ({
artistAndCreatorsNewsletter: ArtistsAndCreatorsNewsletter,
}),
[],
);

const modalCloseHandler = () => {
const modalCloseHandler = useCallback(() => {
// if the modal action is not complete, track bounce
if (!modalActionCompleted.current && typeof window.gtag !== "undefined") {
window.gtag("event", "modal_bounce", {
Expand All @@ -37,7 +47,7 @@ const ModalLauncher = () => {
undefined,
{ shallow: true },
);
};
}, [modalLaunchId, router]);

useEffect(() => {
const { modalLaunch, modalLaunchId } = router.query;
Expand Down Expand Up @@ -68,7 +78,7 @@ const ModalLauncher = () => {
setShowModal(false);
setModalComponent(null);
}
}, [router.query]);
}, [router.query, modalCloseHandler, modalMapping]);

return (
<Modal
Expand Down
18 changes: 15 additions & 3 deletions src/components/blog/PostCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ const PostCard = ({ post, index, isFirstPage, variant = "primary" }) => {
height={1073}
/>
</Link>
<h2 className="post-card-title secondary">{post?.data?.title}</h2>
<h2 className="post-card-title secondary">
{typeof post?.data?.title === "string"
? post.data.title
: post?.data?.title?.Default}
</h2>
</div>
<Link to={url} className="post-card-button">
{t("blog.read-article")}
Expand Down Expand Up @@ -198,7 +202,11 @@ const PostCard = ({ post, index, isFirstPage, variant = "primary" }) => {
<small className="d-block post-card-date">
<PublishedAt publishedDateString={publishedDate} />
</small>
<h2 className="post-card-title">{post?.data?.title}</h2>
<h2 className="post-card-title">
{typeof post?.data?.title === "string"
? post.data.title
: post?.data?.title?.Default}
</h2>
<p className="post-card-excerpt">{excerpt}</p>
</div>
</div>
Expand Down Expand Up @@ -232,7 +240,11 @@ const PostCard = ({ post, index, isFirstPage, variant = "primary" }) => {
<span className="d-block post-card-date">
<PublishedAt publishedDateString={publishedDate} />
</span>
<h2 className="post-card-title">{post?.data?.title}</h2>
<h2 className="post-card-title">
{typeof post?.data?.title === "string"
? post.data.title
: post?.data?.title?.Default}
</h2>
<p className="post-card-excerpt">{excerpt}</p>
</div>
) : (
Expand Down
8 changes: 4 additions & 4 deletions src/components/news/CategorySelection.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRef, useState, useEffect } from "react";
import { useRef, useState, useEffect, useCallback } from "react";
import styles from "./CategorySelection.module.scss";
import classNames from "classnames";
import { SwitcherButtons } from "@solana-foundation/solana-lib";
Expand Down Expand Up @@ -29,7 +29,7 @@ const CategorySelection = ({
return arr.length; // Return -1 if the sum never exceeds maxNumber
};

const updateDisplayedItems = () => {
const updateDisplayedItems = useCallback(() => {
const containerWidth = categoryContainer.current.offsetWidth;
const dropdownWidth = moreCategoriesLabel?.length * 10 + 70; // 70 = padding + ~margin
maxDisplayItems.current = findExceedingIndex(
Expand All @@ -45,7 +45,7 @@ const CategorySelection = ({
setDisplayCategories(categories);
setMoreCategories([]);
}
};
}, [buttonWidths, moreCategoriesLabel, categories]); // Added 'categories' to dependencies

// estimate the widths of the category buttons on initial render
// note: can't rely on actual widths because some buttons are stored in the dropdown and are not accessible
Expand All @@ -66,7 +66,7 @@ const CategorySelection = ({
return () => {
window.removeEventListener("resize", updateDisplayedItems);
};
}, [buttonWidths]);
}, [buttonWidths, updateDisplayedItems]);

return (
<>
Expand Down
12 changes: 7 additions & 5 deletions src/components/possible/PossibleAnimatedIcons.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ const PossibleAnimatedIcons = ({
},
);

if (videoRef.current) {
observer.observe(videoRef.current);
const currentVideoRef = videoRef.current; // Store the current ref

if (currentVideoRef) {
observer.observe(currentVideoRef);
}

return () => {
if (videoRef.current) {
observer.unobserve(videoRef.current);
if (currentVideoRef) {
observer.unobserve(currentVideoRef);
}
};
}, [videoSrc]);
}, []);

const handleVideoError = () => {
setShowFallback(true);
Expand Down
18 changes: 9 additions & 9 deletions src/components/shared/Divider.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import styled from "styled-components";
const StyledDivider = styled.div`
height: ${(props) => props.height || "auto"};
${(props) =>
props.axis === "x"
props.$axis === "x"
? "border-top"
: props.axis === "y"
: props.$axis === "y"
? "border-right"
: "border"}: 1px solid
rgba(
${(props) =>
props.theme === "light"
props.$theme === "light"
? "255, 255, 255"
: props.theme === "dark"
: props.$theme === "dark"
? "0, 0, 0"
: "100,100,100"},
${(props) => props.alpha || 0.4}
: "100, 100, 100"},
${(props) => props.$alpha || 0.4}
);
`;

Expand All @@ -32,9 +32,9 @@ const StyledDivider = styled.div`
const Divider = ({ theme, alpha, axis, height, className }) => (
<StyledDivider
role="separator"
theme={theme}
alpha={alpha}
axis={axis}
$theme={theme}
$alpha={alpha}
$axis={axis}
height={height}
className={className}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/components/shared/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const Link = ({
asPath.includes(to) &&
!partiallyActiveIgnore.filter((el) => asPath.startsWith(el)).length)
);
}, [partiallyActive, asPath, to]);
}, [partiallyActive, asPath, to, partiallyActiveIgnore]); // Added partiallyActiveIgnore to dependencies

if (internal) {
const { scroll, prefetch, ...aProps } = other;
Expand Down
119 changes: 64 additions & 55 deletions src/pages/news/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRef, useState, useEffect } from "react";
import { useRef, useState, useEffect, useMemo } from "react";
import { builder, BuilderComponent } from "@builder.io/react";
import HTMLHead from "../../components/builder/HTMLHead";
import Layout from "../../components/layout";
Expand Down Expand Up @@ -36,20 +36,22 @@ const BlogIndex = ({ builderLocale, newsListingPage, pressRelease, posts }) => {
const newsContent = newsListingPage;

// convert Builder category data to switcherButtons data and prepend a 'All' category with a null value
const categoryFilters = [
{
category: "All",
value: null,
id: null,
},
...(categoryFiltersData?.map((item, index) => {
return {
category: item.category.value.name,
value: index + 1,
id: item.category.value.id,
};
}) || []),
];
const categoryFilters = useMemo(() => {
return [
{
category: "All",
value: null,
id: null,
},
...(categoryFiltersData?.map((item, index) => {
return {
category: item.category.value.name,
value: index + 1,
id: item.category.value.id,
};
}) || []),
];
}, [categoryFiltersData]);

// convert Builder press release data to Slider data
const pressReleaseSliderData =
Expand All @@ -66,45 +68,46 @@ const BlogIndex = ({ builderLocale, newsListingPage, pressRelease, posts }) => {
}) || [];

// convert Builder post data to CardDeck data
const allPostData =
posts
?.map((post) => {
const postData = post?.data;
if (!postData) {
return null;
}

return {
type: "blog",
publishedDate: postData?.datePublished,
heading: postData?.title,
body: postData?.intro,
backgroundImage: {
src: postData?.image || "/src/img/news/blogbackup.png",
},
tags:
postData?.tags?.map((item) => {
return item.tag ? item.tag.id : null;
}) || [],
callToAction: {
hierarchy: "link",
size: "md",
label: newsListingPage?.callToActionLabel || t("blog.readArticle"),
endIcon: "arrow-up-right",
iconSize: "sm",
url: `/news/${postData?.slug || ""}`,
},
};
})
.filter(Boolean)
.sort((a, b) => {
// Convert dates to a format that can be compared
const dateA = new Date(a.publishedDate);
const dateB = new Date(b.publishedDate);

// Compare the dates to determine the order
return dateB - dateA;
}) || [];
const allPostData = useMemo(() => {
return (
posts
?.map((post) => {
const postData = post?.data;
if (!postData) {
return null;
}

return {
type: "blog",
publishedDate: postData?.datePublished,
heading: postData?.title,
body: postData?.intro,
backgroundImage: {
src: postData?.image || "/src/img/news/blogbackup.png",
},
tags:
postData?.tags?.map((item) => {
return item.tag ? item.tag.id : null;
}) || [],
callToAction: {
hierarchy: "link",
size: "md",
label:
newsListingPage?.callToActionLabel || t("blog.readArticle"),
endIcon: "arrow-up-right",
iconSize: "sm",
url: `/news/${postData?.slug || ""}`,
},
};
})
.filter(Boolean)
.sort((a, b) => {
const dateA = new Date(a.publishedDate);
const dateB = new Date(b.publishedDate);
return dateB - dateA;
}) || []
);
}, [posts, newsListingPage?.callToActionLabel, t]);

// Set state for all post data
const [postResults, setPostResults] = useState(allPostData);
Expand Down Expand Up @@ -155,7 +158,13 @@ const BlogIndex = ({ builderLocale, newsListingPage, pressRelease, posts }) => {
setPostResults(results);
setNumResults(postsPerPage);
}
}, [categoryFilter, searchFilter]);
}, [
categoryFilter,
searchFilter,
allPostData,
categoryFilters,
postsPerPage,
]);

return (
<Layout>
Expand Down
Loading

0 comments on commit 004163e

Please sign in to comment.