Skip to content

Commit 90a1ca9

Browse files
authored
Merge pull request #977 from CodeForAfrica/fix/climatemappedafrica_fixes
Fix @/climatemappedafrica images on Dev
2 parents 18d75cb + 9fec4b8 commit 90a1ca9

File tree

12 files changed

+87
-43
lines changed

12 files changed

+87
-43
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ README.md
1010
**/.turbo
1111
**/.vscode
1212
**/build
13+
**/media

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ storybook-static
5757

5858
mongo-keyfile
5959

60-
#Google credentials
60+
# Google credentials
6161
credentials.json
6262

6363
# Sentry Config File
@@ -67,3 +67,6 @@ credentials.json
6767
# SQLite files
6868
**.db
6969
**.sqlite
70+
71+
# Payload media folder
72+
media
Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
# Learn more about ENV variables at https://github.com/WebDevStudios/nextjs-wordpress-starter/wiki/env-variables
2-
3-
# Tells Next.js we're in development mode. You do not need a Vercel account for this.
4-
VERCEL_ENV="development"
5-
6-
NEXT_PUBLIC_APP_URL = 'http://localhost:3000'
7-
8-
# Allows Node to work with local, self-signed certificates.
9-
NODE_TLS_REJECT_UNAUTHORIZED="0"
1+
NEXT_PUBLIC_APP_URL="http://localhost:3000"
102

113
# The domain where your images are hosted on.
124
# See https://nextjs.org/docs/basic-features/image-optimization#domains
@@ -16,9 +8,6 @@ NEXT_PUBLIC_IMAGE_DOMAINS="cms.dev.codeforafrica.org"
168
# See https://vega.github.io/vega/docs/api/view/#view_toImageURL
179
NEXT_PUBLIC_IMAGE_SCALE_FACTOR=2
1810

19-
# HURUmap URL
20-
HURUMAP_API_URL="https://ng.hurumap.org/api/v1/"
21-
2211
# openAFRICA domains
2312
# A comma-separated list of domains to openAFRICA (or any CKAN-based site domain)
2413
NEXT_PUBLIC_OPENAFRICA_DOMAINS=
@@ -28,11 +17,19 @@ NEXT_PUBLIC_OPENAFRICA_DOMAINS=
2817
# based site domain)
2918
NEXT_PUBLIC_SOURCEAFRICA_DOMAINS=
3019

20+
# Google Analytics
21+
NEXT_PUBLIC_GOOGLE_ANALYTICS_ID = "G-xxxxxxxx"
22+
3123
# AWS S3 bucket for storing images
32-
S3_UPLOAD_KEY=AAAAAAAAAAAAAAAAAAAA
33-
S3_UPLOAD_SECRET=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
34-
S3_UPLOAD_BUCKET=name-of-s3-bucket
35-
S3_UPLOAD_REGION=bucket-region-us-east-1
24+
S3_ACCESS_KEY_ID=AAAAAAAAAAAAAAAAAAAA
25+
S3_SECRET_ACCESS_KEY=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
26+
S3_BUCKET=name-of-s3-bucket
27+
S3_REGION=bucket-region-us-east-1
3628

37-
#Analytics
38-
NEXT_PUBLIC_GOOGLE_ANALYTICS_ID = "G-xxxxxxxx"
29+
# Payload
30+
MONGO_URL="mongodb+srv://<user>:<pass>@host/db"
31+
PAYLOAD_PUBLIC_APP_URL="http://localhost:3000"
32+
PAYLOAD_SECRET="secure random string"
33+
34+
# HURUmap
35+
HURUMAP_API_URL="https://ng.hurumap.org/api/v1/"

apps/climatemappedafrica/next.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ module.exports = {
1313
domains: process.env.NEXT_PUBLIC_IMAGE_DOMAINS?.split(",")
1414
?.map((d) => d.trim())
1515
?.filter((d) => d),
16+
loader: "custom",
17+
loaderFile: "./payload.image.loader.js",
1618
unoptimized:
1719
process.env.NEXT_PUBLIC_IMAGE_UNOPTIMIZED?.trim()?.toLowerCase() ===
1820
"true",

apps/climatemappedafrica/payload.config.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,16 @@ const csrf =
3434
?.map((d) => d.trim())
3535
?.filter(Boolean) ?? [];
3636

37-
const adapter = s3Adapter({
37+
const accessKeyId = process?.env?.S3_ACCESS_KEY_ID;
38+
const secretAccessKey = process?.env?.S3_SECRET_ACCESS_KEY;
39+
const enableCloudStorage = Boolean(accessKeyId && secretAccessKey);
40+
41+
const cloudStorageAdapter = s3Adapter({
3842
config: {
3943
region: process?.env?.S3_REGION,
4044
credentials: {
41-
accessKeyId: process?.env?.S3_ACCESS_KEY_ID,
42-
secretAccessKey: process?.env?.S3_SECRET_ACCESS_KEY,
45+
accessKeyId,
46+
secretAccessKey,
4347
},
4448
},
4549
bucket: process?.env?.S3_BUCKET,
@@ -106,11 +110,11 @@ export default buildConfig({
106110
},
107111
plugins: [
108112
cloudStorage({
113+
enabled: enableCloudStorage,
109114
collections: {
110115
media: {
111-
adapter,
112-
// TODO(kilemensi): Toogle this depending on ENV?
113-
disableLocalStorage: false,
116+
adapter: cloudStorageAdapter,
117+
disableLocalStorage: enableCloudStorage,
114118
prefix: "media",
115119
},
116120
},
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"use client";
2+
3+
import site from "@/climatemappedafrica/utils/site";
4+
5+
export default function payloadImageLoader({ src }) {
6+
// Handle relative paths (/media) only
7+
if (src?.startsWith("/media")) {
8+
return `${site.url}${src}`;
9+
}
10+
return src;
11+
}

apps/climatemappedafrica/src/components/HURUmap/LocationHeader/useStyles.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import makeStyles from "@mui/styles/makeStyles";
22

3-
const useStyles = makeStyles(({ typography, palette }) => ({
3+
const useStyles = makeStyles(({ breakpoints, palette, typography }) => ({
44
root: {
55
borderBottom: `solid 1px ${palette.divider}`,
66
paddingTop: typography.pxToRem(20),
7+
[breakpoints.up("lg")]: {
8+
position: "relative",
9+
},
710
},
811
titleContent: {
912
display: "flex",
@@ -33,6 +36,10 @@ const useStyles = makeStyles(({ typography, palette }) => ({
3336
height: typography.pxToRem(44),
3437
minWidth: typography.pxToRem(44),
3538
boxShadow: "none",
39+
[breakpoints.up("lg")]: {
40+
// quick fix to ensure print button aligns with rich data/pin buttons
41+
marginTop: "10px",
42+
},
3643
},
3744
closeButton: {
3845
marginLeft: typography.pxToRem(20),

apps/climatemappedafrica/src/components/HURUmap/Panel/DesktopPanel/PanelButtons.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ function PanelButtons({
139139
}),
140140
({ widths }) =>
141141
open && {
142-
left: `max(calc((100vw - ${widths.values.lg}px)/2 + 833px),1100px)`,
142+
// must match min width of TreeView + Profile
143+
left: `max(calc((100vw - ${widths.values.lg}px)/2 + 79px + 800px),1100px)`,
143144
},
144145
]}
145146
/>

apps/climatemappedafrica/src/components/HURUmap/Panel/MobilePanel/MobilePanel.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React from "react";
44

55
import RichData from "./RichData";
66

7-
import PrintIcon from "@/climatemappedafrica/assets/icons/print.svg";
7+
import printIcon from "@/climatemappedafrica/assets/icons/print.svg?url";
88
import TopIcon from "@/climatemappedafrica/assets/icons/top.svg";
99
import LocationHeader from "@/climatemappedafrica/components/HURUmap/LocationHeader";
1010
import PinAndCompare from "@/climatemappedafrica/components/HURUmap/PinAndCompare";
@@ -52,7 +52,7 @@ function MobilePanel({ activeType, scrollToTopLabel, sx, ...props }) {
5252
<Section>
5353
<LocationHeader
5454
variant="primary"
55-
icon={PrintIcon}
55+
icon={printIcon}
5656
title={geography.name}
5757
{...geography}
5858
/>

apps/climatemappedafrica/src/components/HURUmap/Panel/Profile.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React, { forwardRef } from "react";
44

55
import ProfileItems from "./ProfileItems";
66

7-
import Print from "@/climatemappedafrica/assets/icons/print.svg";
7+
import printIcon from "@/climatemappedafrica/assets/icons/print.svg?url";
88
import LocationHeader from "@/climatemappedafrica/components/HURUmap/LocationHeader";
99
import PinAndCompare from "@/climatemappedafrica/components/HURUmap/PinAndCompare";
1010
import Loading from "@/climatemappedafrica/components/Loading";
@@ -85,11 +85,15 @@ const Profile = forwardRef(function Profile(
8585
return (
8686
<Box
8787
sx={[
88-
({ palette, typography, zIndex }) => ({
88+
({ palette, typography, widths, zIndex }) => ({
8989
backgroundColor: palette.background.default,
90+
// must match min width of TreeView
91+
left: {
92+
lg: `max(calc((100vw - ${widths.values.lg}px)/2 + 79px), 300px)`,
93+
},
9094
marginLeft: {
9195
xs: typography.pxToRem(20),
92-
lg: `max(calc((100vw - 1160px)/2 + 79px), 300px)`,
96+
lg: 0,
9397
},
9498
marginRight: {
9599
xs: typography.pxToRem(20),
@@ -104,10 +108,11 @@ const Profile = forwardRef(function Profile(
104108
md: typography.pxToRem(80),
105109
lg: typography.pxToRem(17),
106110
},
107-
width: { lg: typography.pxToRem(800) },
108-
minHeight: { lg: "100%" },
109111
paddingTop: { lg: typography.pxToRem(67.7) },
110112
paddingRight: { lg: typography.pxToRem(17) },
113+
position: { lg: "absolute" },
114+
width: { lg: typography.pxToRem(800) },
115+
minHeight: { lg: "100%" },
111116
zIndex: { lg: zIndex.drawer },
112117
}),
113118
...(Array.isArray(sx) ? sx : [sx]),
@@ -117,7 +122,7 @@ const Profile = forwardRef(function Profile(
117122
{isLoading && <Loading />}
118123
<LocationHeader
119124
variant="primary"
120-
icon={Print}
125+
icon={printIcon}
121126
title={primaryProfile.geography.name}
122127
onClick={handleClick(primaryProfile)}
123128
{...primaryProfile.geography}

apps/climatemappedafrica/src/pages/[[...slugs]].js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,15 @@ function Index({ blocks, menus, footer: footerProps, seo = {}, fallback }) {
5151
}
5252
}
5353

54-
const tutorialBlock = blocks.find((block) => block.blockType === "tutorial");
55-
5654
let TutorialComponent = React.Fragment;
55+
let TutorialComponentProps;
56+
const tutorialBlock = blocks.find((block) => block.blockType === "tutorial");
5757
if (tutorialBlock) {
5858
TutorialComponent = Tutorial;
59+
TutorialComponentProps = {
60+
...tutorialBlock,
61+
defaultOpen: Number.parseInt(showTutorial, 10) === 1,
62+
};
5963
}
6064

6165
let PageConfig = React.Fragment;
@@ -65,11 +69,7 @@ function Index({ blocks, menus, footer: footerProps, seo = {}, fallback }) {
6569
pageConfigProps = { value: { fallback } };
6670
}
6771
return (
68-
<TutorialComponent
69-
key={showTutorial}
70-
{...tutorialBlock}
71-
defaultOpen={Number.parseInt(showTutorial, 10) === 1}
72-
>
72+
<TutorialComponent key={showTutorial} {...TutorialComponentProps}>
7373
<Navigation {...menus} />
7474
<NextSeo
7575
{...pageSeo}

apps/climatemappedafrica/src/payload/blocks/Hero.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { slateEditor } from "@payloadcms/richtext-slate";
2+
13
import richText from "../fields/richText";
24

35
const Hero = {
@@ -12,13 +14,24 @@ const Hero = {
1214
richText({
1315
name: "title",
1416
required: true,
15-
label: "Title",
1617
localized: true,
18+
editor: slateEditor({
19+
admin: {
20+
elements: [],
21+
leaves: ["bold"],
22+
},
23+
}),
1724
}),
1825
richText({
1926
name: "subtitle",
2027
required: true,
2128
localized: true,
29+
editor: slateEditor({
30+
admin: {
31+
elements: [],
32+
leaves: ["bold", "code", "italic", "strikethrough", "underline"],
33+
},
34+
}),
2235
}),
2336
{
2437
name: "searchLabel",

0 commit comments

Comments
 (0)