Skip to content

Commit

Permalink
Added /collectives/ayowecca, + fixes for /collectives
Browse files Browse the repository at this point in the history
  • Loading branch information
xdamman committed Feb 15, 2022
1 parent aeec949 commit 40ecae1
Show file tree
Hide file tree
Showing 9 changed files with 378 additions and 108 deletions.
26 changes: 16 additions & 10 deletions components/CollectiveCard.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import styled from 'styled-components';
import { Flex, Box } from 'rebass';
import numeral from '../lib/numeral';
import styled from "styled-components";
import { Flex, Box } from "rebass";
import numeral from "../lib/numeral";

const Collective = styled.div`
width: 150px;
height: 230px;
float: left;
padding: 10px;
border: 1px solid #eee;
border-radius: 3px;
border-radius: 10px;
overflow: hidden;
margin: 5px;
`;
Expand All @@ -20,13 +20,15 @@ const H1 = styled.h1`
display: flex;
align-items: center;
justify-content: center;
line-height: 1;
`;

const Description = styled.p`
font-size: 12px;
font-size: 11.5px;
overflow: hidden;
color: #222;
height: 45px;
font-weight: 500;
line-height: 1.3;
`;

Expand All @@ -50,7 +52,7 @@ const Number = styled.div`
`;

const Label = styled.label`
font-size: 10px;
font-size: 10px;
`;

export default ({ data }) => {
Expand All @@ -67,16 +69,20 @@ export default ({ data }) => {
<Label>backers</Label>
</Box>
<Box>
<Number>{numeral(data.stats.balance / 100).format('$0,0')}</Number>
<Number>
{numeral(data.stats.balance / 100).format("$0,0")}
</Number>
<Label>balance</Label>
</Box>
<Box>
<Number>{numeral(data.stats.monthlySpending / 100).format('$0,0')}</Number>
<Number>
{numeral(data.stats.monthlySpending / 100).format("$0,0")}
</Number>
<Label>burn</Label>
</Box>
</Flex>
</Stats>
</Collective>
</A>
)
}
);
};
7 changes: 5 additions & 2 deletions components/Footer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const Footer = ({ googleDocId }) => (
<div className="footer mt-8 border-t border-gray-300 flex flex-row justify-between items-center w-screen max-w-screen-md mx-auto p-3">
<div className="footer mt-8 flex flex-row justify-between items-center w-screen max-w-screen-md mx-auto p-3">
<div>
<a href="https://allforclimate.earth">
<a
href="https://dao.allforclimate.earth"
title="Go back to dao.allforclimate.earth"
>
<img
src="/images/allforclimate-icon-black.png"
alt="All for Climate Logo"
Expand Down
12 changes: 12 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ module.exports = {
destination:
"https://drive.google.com/drive/u/0/folders/1g14Qyf_DmvGuevk4Ks5NgfkWPN5V6H6O",
},
{
source: "/(.*)",
has: [
{
type: "host",
value: "join.allforclimate.earth",
},
],
permanent: false,
destination:
"https://jz04xmgcexm.typeform.com/to/lPbcL9nj?typeform-source=join.allforclimate.earth",
},
{
source: "/(.*)",
has: [
Expand Down
182 changes: 182 additions & 0 deletions pages/collectives/[googleDocId].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
import Head from "next/head";
import { getHTMLFromGoogleDocId } from "../../lib/googledoc";
import { getPageMetadata } from "../../lib/lib";
import Outline from "../../components/Outline";
import Footer from "../../components/Footer";
import ErrorNotPublished from "../../components/ErrorNotPublished";
import ErrorInvalidDocId from "../../components/ErrorInvalidDocId";
import RenderGoogleDoc from "../../components/RenderGoogleDoc";
import sitemap from "../../sitemap.json";
import { useEffect, useState } from "react";
import { times } from "lodash";

const defaultValues = sitemap.index;

export async function getStaticPaths() {
const paths = [];
Object.keys(sitemap).forEach((key) => {
if (!key.match(/^collectives\//)) return;
console.log(">>> key", key);
paths.push({
params: {
googleDocId: sitemap[key].googleDocId,
},
});
paths.push({
params: {
googleDocId: key.replace("collectives/", ""),
},
});
});
console.log(paths);
return {
paths,
fallback: true,
};
}

export async function getStaticProps({ params }) {
const pageInfo = getPageMetadata(`collectives/${params.googleDocId}`);
const googleDocId = pageInfo.googleDocId || params.googleDocId;
let doc = {},
error = null;
try {
doc = await getHTMLFromGoogleDocId(googleDocId);
} catch (e) {
error = e.message;
}

const page = {
title: pageInfo.title || doc.title || null,
description: pageInfo.description || doc.description || null,
image: pageInfo.image || null,
body: doc.body || null,
outline: doc.outline || null,
googleDocId,
error,
};

return {
props: { page },
// we will attempt to re-generate the page:
// - when a request comes in
// - at most once every 180 seconds
revalidate: 180,
};
}

export default function Home({ page }) {
if (!page) return <div />;
const { title, description, outline, body, image, googleDocId, error } = page;
const [currentSection, setCurrentSection] = useState();
const [currentDocWidth, setCurrentDocWidth] = useState(0);

function changeCurrentSection(section) {
setCurrentSection(section);
document.querySelectorAll("#outline a").forEach((el) => {
const href = el.getAttribute("href");
if (href === `#${section}`) {
el.classList.add("bg-gray-300");
console.log(">>> adding active to", el);
} else {
el.classList.remove("bg-gray-300");
}
});
console.log(">>> current section", section);
history.replaceState(
null,
null,
document.location.pathname + (section ? "#" + section : "")
);
}

function logit() {
const y = window.pageYOffset;
if (y % 5 !== 0) return false;

let section = null,
index = 0;
outline.forEach((item, i) => {
if (y >= item.offsetTop - 60) {
section = item.slug;
index = i;
}
});
if (section !== currentSection) {
changeCurrentSection(section);
}
}

function computeOffset() {
const docEl = document.querySelector("#document");
if (!docEl) return;
if (Math.abs(docEl.offsetWidth - currentDocWidth) < 50) {
return;
}
console.log(
"computeOffset",
currentDocWidth,
Math.abs(docEl.offsetWidth - currentDocWidth)
);
setCurrentDocWidth(Number(docEl.offsetWidth) || 120);
docEl.querySelectorAll("h1,h2,h3,h4,h5,h6").forEach((el) => {
const slug = el.getAttribute("id");
const item = outline.find((o) => o.slug === slug);
if (!item) return;
item.offsetTop = el.offsetTop;
item.el = el;
});
}

useEffect(() => {
// we only highlight the current section on large screens
// where the outline is visible side by side
if (window.innerWidth < 768) return false;

function addListeners() {
window.addEventListener("scroll", logit);
window.addEventListener("resize", computeOffset);
}
computeOffset();
addListeners();
return () => {
window.removeEventListener("scroll", logit);
window.removeEventListener("resize", computeOffset);
};
});

return (
<div className="w-full">
<Head>
<title>{title || defaultValues.title}</title>
<link rel="icon" href={defaultValues.favicon} />
<meta
name="description"
content={description || defaultValues.description}
/>
<meta name="og:image" content={image || defaultValues.image} />
</Head>

<main className="relative min-h-screen md:flex">
{outline && (
<Outline outline={outline} onChange={() => computeOffset()} />
)}
<div className="content px-4 mx-auto max-w-screen-md flex-1 overflow-auto">
{!body && !error && <p>Loading...</p>}
{error === "not_published" && (
<ErrorNotPublished googleDocId={googleDocId} />
)}
{error === "invalid_googledocid" && (
<ErrorInvalidDocId googleDocId={googleDocId} />
)}
{body && (
<div id="document">
<RenderGoogleDoc html={body} />
<Footer googleDocId={googleDocId} />
</div>
)}
</div>
</main>
</div>
);
}
Loading

0 comments on commit 40ecae1

Please sign in to comment.