Skip to content

Commit 938fb63

Browse files
authored
Merge pull request #1454 from processing/1391-2
Fix Wrong Page Underlined as Current Page in Left Nav Bar [2.0]
2 parents ed1c88d + 6261f8c commit 938fb63

20 files changed

Lines changed: 33 additions & 82 deletions

‎src/components/Nav/index.astro‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
import { getCurrentLocale, getUiTranslator } from "@/src/i18n/utils";
3-
import { jumpToState } from "@/src/globals/state";
43
import styles from "./styles.module.scss";
54
import { NavPanels } from "./NavPanels";
65
@@ -9,6 +8,7 @@ const currentLocale = getCurrentLocale(Astro.url.pathname);
98
const pathMinusLocale = Astro.url.pathname.replace(`/${currentLocale}`, "");
109
const isHomepage = pathMinusLocale === "/";
1110
const t = await getUiTranslator(currentLocale);
11+
const { jumpToState } = Astro.props;
1212
1313
const mainLinks = [
1414
{ url: "/reference/", label: t("Reference") },

‎src/layouts/BaseLayout.astro‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import ItemPageHeader from "@/src/components/PageHeader/ItemPage.astro";
77
import HomePageHeader from "@/src/components/PageHeader/HomePage.astro";
88
import { getCurrentLocale, getUiTranslator } from "@i18n/utils";
99
import { capitalize, getTopicInfo, type PageTopic } from "../pages/_utils";
10+
import { type JumpToState } from "@src/globals/state";
1011
import "@styles/base.scss";
1112
import "@styles/global.css";
1213
import type { CollectionEntry } from "astro:content";
@@ -23,6 +24,7 @@ interface Props {
2324
variant?: "root" | "item" | "search" | "homepage";
2425
topic?: PageTopic;
2526
mainContentParentClass?: string;
27+
jumpToState?: JumpToState | null;
2628
/* Only needed for the homepage */
2729
homepageConfig?: CollectionEntry<"homepage">;
2830
}
@@ -36,6 +38,7 @@ const {
3638
variant = "root",
3739
mainContentParentClass = "mx-5 md:mx-lg mt-md",
3840
homepageConfig,
41+
jumpToState
3942
} = Astro.props;
4043
4144
const currentLocale = getCurrentLocale(Astro.url.pathname);
@@ -89,7 +92,7 @@ const headerTopic = topic
8992
</head>
9093
<body>
9194
<div class="top-layout-grid">
92-
<Nav />
95+
<Nav jumpToState={jumpToState} />
9396
<Settings hideSearch={variant === "search"} />
9497
<header class={homepageConfig && "h-[100vh] md:min-h-[calc(378px+50vh)]"}>
9598
{

‎src/layouts/CommunityLayout.astro‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import GridItemSketch from "@components/GridItem/Sketch.astro";
77
import GridItemLibrary from "@components/GridItem/Library.astro";
88
import GridItemEvent from "@components/GridItem/Event.astro";
99
import { getCurrentLocale, getUiTranslator } from "@i18n/utils";
10-
import { setJumpToState } from "../globals/state";
1110
import { type OpenProcessingCurationResponse } from "../api/OpenProcessing";
1211
1312
interface Props {
@@ -32,18 +31,18 @@ const sketches = Astro.props.sketches.slice(0, sketchesLimit),
3231
const currentLocale = getCurrentLocale(Astro.url.pathname);
3332
const t = await getUiTranslator(currentLocale);
3433
35-
setJumpToState({
34+
const jumpToState = {
3635
links: [
3736
{ label: t("Sketches") as string, url: "#sketches" },
3837
{ label: t("Libraries") as string, url: "#libraries" },
39-
{ label: t("Events") as string, url: "#events" },
40-
],
41-
});
38+
{ label: t("Events") as string, url: "#events" }
39+
]
40+
};
4241
---
4342

4443
<Head title={"Community"} locale={currentLocale} />
4544

46-
<BaseLayout title="Community">
45+
<BaseLayout title="Community" jumpToState={jumpToState}>
4746
<section>
4847
<h2>{t("Sketches")}<a id="sketches"></a></h2>
4948
<ul class="content-grid-simple">

‎src/layouts/ContributeLayout.astro‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import ContributeImage from "@content/ui/images/contribute.png";
66
import BaseLayout from "./BaseLayout.astro";
77
import { getCurrentLocale, getUiTranslator } from "@i18n/utils";
88
import GridItemContributorDoc from "@components/GridItem/ContributorDoc.astro";
9-
import { setJumpToState, type JumpToLink } from "../globals/state";
9+
import { type JumpToLink } from "../globals/state";
1010
1111
interface Props {
1212
entries: CollectionEntry<"contributor-docs">[];
@@ -39,10 +39,6 @@ const jumpToLinks = [
3939
url: "#donate",
4040
},
4141
];
42-
43-
setJumpToState({
44-
links: jumpToLinks as JumpToLink[],
45-
});
4642
---
4743

4844
<Head
@@ -51,7 +47,7 @@ setJumpToState({
5147
featuredImageSrc={ContributeImage.src}
5248
/>
5349

54-
<BaseLayout title="Contribute">
50+
<BaseLayout title="Contribute" jumpToState={{ links: jumpToLinks as JumpToLink[] }}>
5551
<section>
5652
<h2 id="docs">{t("Contributor Docs")}</h2>
5753
<div

‎src/layouts/ContributorDocLayout.astro‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ import { render } from 'astro:content';
44
import BaseLayout from "./BaseLayout.astro";
55
import Head from "@components/Head/index.astro";
66
import type { MarkdownHeading } from "astro";
7-
import {
8-
setJumpToState,
9-
type JumpToLink,
10-
type JumpToState,
11-
} from "../globals/state";
7+
import { type JumpToLink, type JumpToState } from "../globals/state";
128
import { getCurrentLocale, getUiTranslator } from "../i18n/utils";
139
1410
interface Props {
@@ -32,8 +28,6 @@ const jumpToState = {
3228
links: jumpToLinks as JumpToLink[],
3329
heading: t("Contributor Docs"),
3430
} as JumpToState;
35-
36-
setJumpToState(jumpToState);
3731
---
3832

3933
<Head title={entry.data.title} locale={currentLocale} />
@@ -44,6 +38,7 @@ setJumpToState(jumpToState);
4438
subtitle={null}
4539
topic="contribute"
4640
className="contribute"
41+
jumpToState={jumpToState}
4742
>
4843
<section class="rendered-markdown">
4944
<Content />

‎src/layouts/EventLayout.astro‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import BaseLayout from "./BaseLayout.astro";
66
import Image from "@components/Image/index.astro";
77
import FreeRatioImage from "@components/Image/FreeRatioImage.astro";
88
import RelatedItems from "@components/RelatedItems/index.astro";
9-
import { setJumpToState } from "../globals/state";
109
import { getCurrentLocale, getUiTranslator } from "../i18n/utils";
1110
import { getRelatedEntriesinCollection } from "../pages/_utils";
1211
@@ -18,8 +17,6 @@ interface Props {
1817
const { entry, title } = Astro.props;
1918
const { Content } = await render(entry);
2019
21-
setJumpToState(null);
22-
2320
const currentLocale = getCurrentLocale(Astro.url.pathname);
2421
const t = await getUiTranslator(currentLocale);
2522
const dayString = new Date(entry.data.date).toLocaleDateString(currentLocale, {
@@ -43,7 +40,7 @@ const relatedEvents =
4340
featuredImageSrc={entry.data.featuredImage.src}
4441
/>
4542

46-
<BaseLayout title={title} subtitle={dayString} variant="item" topic="community">
43+
<BaseLayout title={title} subtitle={dayString} variant="item" topic="community" jumpToState={null}>
4744
{
4845
entry.data.featuredImage && entry.data.featuredImageAlt && (
4946
<Image

‎src/layouts/EventsLayout.astro‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import BaseLayout from "./BaseLayout.astro";
55
import GridItemEvent from "@components/GridItem/Event.astro";
66
import PaginationNav from "@components/PaginationNav/index.astro";
77
import { eventsPerPage } from "../globals/globals";
8-
import { setJumpToState } from "../globals/state";
98
import { getCurrentLocale } from "../i18n/utils";
109
1110
interface Props {
@@ -17,12 +16,11 @@ interface Props {
1716
const currentLocale = getCurrentLocale(Astro.url.pathname);
1817
1918
const { entries, totalNumEvents, currentPage } = Astro.props;
20-
setJumpToState(null);
2119
---
2220

2321
<Head title={"Events"} locale={currentLocale} />
2422

25-
<BaseLayout title="Events" variant="item" topic="community">
23+
<BaseLayout title="Events" variant="item" topic="community" jumpToState={null}>
2624
<section>
2725
<ul class="content-grid-simple">
2826
{entries.map((entry) => (

‎src/layouts/ExampleLayout.astro‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import type { CollectionEntry } from "astro:content";
33
import { render } from "astro:content";
44
import Head from "@components/Head/index.astro";
5-
import { setJumpToState } from "../globals/state";
65
import { getCurrentLocale, getUiTranslator } from "../i18n/utils";
76
import {
87
generateJumpToState,
@@ -31,8 +30,6 @@ const jumpToState = await generateJumpToState(
3130
currentLocale
3231
);
3332
34-
setJumpToState(jumpToState);
35-
3633
const relatedReferences =
3734
example.data.relatedReference !== undefined
3835
? await getRelatedEntriesinCollection(
@@ -76,6 +73,7 @@ const remixHistoryHasCodeLinks = example.data.remix?.some(
7673
variant="item"
7774
topic="examples"
7875
className="example"
76+
jumpToState={jumpToState}
7977
>
8078
<div class="mt-xl mb-4xl lg:mb-3xl max-w-[770px]">
8179
<div class="rendered-markdown">

‎src/layouts/ExamplesLayout.astro‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Head from "@components/Head/index.astro";
44
import GridItemExample from "@components/GridItem/Example.astro";
55
import { getExampleCategory } from "../pages/_utils";
66
import { getCurrentLocale, getUiTranslator } from "../i18n/utils";
7-
import { setJumpToState } from "../globals/state";
7+
import { type JumpToLink } from "../globals/state";
88
import type { CollectionEntry } from "astro:content";
99
1010
interface Props {
@@ -44,17 +44,11 @@ const jumpToLinks = Array.from(examplesByCategory).map(({ name }) => ({
4444
label: name as string,
4545
url: `/examples/#${name.toLowerCase()}`,
4646
}));
47-
48-
const jumpToState = {
49-
links: jumpToLinks,
50-
};
51-
52-
setJumpToState(jumpToState);
5347
---
5448

5549
<Head title={"Examples"} locale={currentLocale} />
5650

57-
<BaseLayout title="Examples">
51+
<BaseLayout title="Examples" jumpToState={{ links: jumpToLinks as JumpToLink[] }}>
5852
{
5953
examplesByCategory.map((category) => (
6054
<section class="grid">

‎src/layouts/HomepageLayout.astro‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import GridItemSketch from "@components/GridItem/Sketch.astro";
55
import { getCurrentLocale, getUiTranslator } from "../i18n/utils";
66
import { getCurationSketches } from "../api/OpenProcessing";
77
import BaseLayout from "./BaseLayout.astro";
8-
import { setJumpToState } from "../globals/state";
98
import Head from "../components/Head/index.astro";
109
1110
interface Props {
@@ -25,8 +24,6 @@ const sketches = config.data.sketchIds.map(
2524
curationSketches.find((sk) => id === sk.visualID) ??
2625
curationSketches[i]
2726
);
28-
29-
setJumpToState(null);
3027
---
3128

3229
<Head
@@ -35,8 +32,8 @@ setJumpToState(null);
3532
locale={currentLocale}
3633
/>
3734

38-
<BaseLayout title="" variant="homepage" homepageConfig={config}>
39-
35+
<BaseLayout title="" variant="homepage" homepageConfig={config} jumpToState={null}>
36+
4037
<h1 class="text-5xl font-bold mb-xl col-span-full">{t("Welcome to p5.js")}</h1>
4138

4239
<div class="content-grid-simple mb-xl">

0 commit comments

Comments
 (0)