From 2435a43132756709ac7a8d108cadf59a5e27ee98 Mon Sep 17 00:00:00 2001 From: Alessio Cimarelli Date: Mon, 1 Jun 2020 16:46:43 +0200 Subject: [PATCH] Add contributors support --- src/components/GridItem/index.js | 14 ++++--- src/config.js | 10 +++++ src/pages/about.js | 67 +++++++++++++++++++++++++++++--- 3 files changed, 80 insertions(+), 11 deletions(-) diff --git a/src/components/GridItem/index.js b/src/components/GridItem/index.js index 74f08e2..f353855 100644 --- a/src/components/GridItem/index.js +++ b/src/components/GridItem/index.js @@ -20,11 +20,15 @@ export default ({ return ( - + { + !!image + && + + } diff --git a/src/config.js b/src/config.js index a3f9b45..2e6bac1 100644 --- a/src/config.js +++ b/src/config.js @@ -25,6 +25,7 @@ export const GSHEET_SHEET_TASKFORSES = 2 export const GSHEET_SHEET_MEMBERS = 3 export const GSHEET_SHEET_MINUTES = 4 export const GSHEET_SHEET_RESOURCES = 5 +export const GSHEET_SHEET_CONTRIBUTIONS = 6 export const GSHEET_MULTIFIELDS_SEPARATOR = `;` const getGSheetUrl = sheet => `/${sheet}/${GSHEET_SUFFIX}` @@ -228,6 +229,15 @@ export function getResourcesByTaskForseSync(id, resources) { ) : [] } +export async function getContributions() { + return normalizeGSheetJSON(await api.get(getGSheetUrl(GSHEET_SHEET_CONTRIBUTIONS))) +} + +export async function getContributors() { + const contributions = filter(await getContributions(), c => !!c["Autore"]) + return groupBy(contributions, "Autore") +} + function normalizeGSheetJSON(response) { const dataKeys = map( diff --git a/src/pages/about.js b/src/pages/about.js index 76b6696..c89531b 100644 --- a/src/pages/about.js +++ b/src/pages/about.js @@ -1,24 +1,41 @@ import { NextSeo } from 'next-seo' +import { + orderBy, + map, + keys, + values, + size, + sumBy, +} from 'lodash' + import { Container, Typography, List, ListItem, ListItemText, + Grid, } from '@material-ui/core' import { + REVALIDATE_INTERVAL, GFORM_URL_ISSUE, getGFormUrl, + getContributors, + getContributions, } from '../config' import { Header, Footer, + GridItem, } from '../components' -export default function Index() { +export default function Index({ contributionsByContributor, totalContributionsCount }) { + + const contributors = keys(contributionsByContributor) + const authoredContributionsCount = sumBy(values(contributionsByContributor), size) return ( <> @@ -62,7 +79,7 @@ export default function Index() { Giovedì 21 maggio alle 12:00 abbiamo presentato il progetto in un webinar in diretta su Facebook e Youtube con Alessio, Andrea, Alice, Jacopo e Lorenzo. - + onData - Associazione di promozione sociale @@ -86,7 +103,7 @@ export default function Index() { Questo sito è sviluppato e mantenuto con ♥ da jenkin, utilizzando NextJS e Material-UI. {` `} - Il nome è un'idea di aborruso, il graphic design di japi e la progettazione del database di lore e alice. + Il nome è un'idea di aborruso, il graphic design di japi la progettazione e gestione del database di lore e alice. @@ -94,9 +111,37 @@ export default function Index() { - Coming soon... + Finora hanno contribuito all'arricchimento del database {size(contributors)} persone per un totale di {authoredContributionsCount} contributi, a cui se ne aggiungono {totalContributionsCount - authoredContributionsCount} anonimi. Grazie! + + + + + + { + map( + orderBy( + contributors, + contributor => size(contributionsByContributor[contributor]), + "desc" + ), + contributor => ( + + 1 ? "i" : "o"}`} + /> + + ) + ) + } + + + + + + Roadmap @@ -104,10 +149,10 @@ export default function Index() { - Elenco contributori + Progressive Web Application - Progressive Web Application + Sitemap + Suggerisci... @@ -123,3 +168,13 @@ export default function Index() { ) } + +export async function getStaticProps() { + return { + props: { + contributionsByContributor: await getContributors(), + totalContributionsCount: size(await getContributions()), + }, + unstable_revalidate: REVALIDATE_INTERVAL, + } +}