GithubHelp home page GithubHelp logo

wri / agriadapt Goto Github PK

View Code? Open in Web Editor NEW
1.0 8.0 0.0 98.11 MB

Web app for physical climate risk tool.

Home Page: https://agriadapt.org

JavaScript 56.26% SCSS 15.57% TypeScript 26.41% HTML 1.68% CSS 0.09%

agriadapt's Introduction

This is a Next.js project bootstrapped with create-next-app.

Getting Started

First, run the development server:

npm run dev
# or
yarn dev

Open http://localhost:3000 with your browser to see the result.

You can start editing the page by modifying pages/index.js. The page auto-updates as you edit the file.

API routes can be accessed on http://localhost:3000/api/hello. This endpoint can be edited in pages/api/hello.js.

The pages/api directory is mapped to /api/*. Files in this directory are treated as API routes instead of React pages.

Learn More

To learn more about Next.js, take a look at the following resources:

You can check out the Next.js GitHub repository - your feedback and contributions are welcome!

Deploy on Vercel

The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.

Check out our Next.js deployment documentation for more details.

agriadapt's People

Contributors

chrowe avatar kyleaig2 avatar naush-khiljee avatar vincentlinzhu avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

agriadapt's Issues

Handling Multiple Worldviews

  1. Once a user enters the site, their country is determined through request headers from CDN and saved securely to their browsing session
    import { withIronSessionSsr } from 'iron-session/next';
    import { GetServerSideProps } from 'next';
    // Replace usage when using an architecture that supports Next.js 12's Middleware
    export const withSession = (getServerSidePropsFunc?: GetServerSideProps) => {
    return withIronSessionSsr(
    async (context) => {
    const { req } = context;
    const worldview =
    req.headers['cloudfront-viewer-country'] ??
    req.session.user?.country ??
    'US';
    // const worldview = 'IN';
    req.session.user = {
    country: Array.isArray(worldview) ? worldview.join('') : worldview,
    };
    await req.session.save();
    if (getServerSidePropsFunc) {
  2. If the user attempts to view a dataset in Explore that is blacklisted from their worldview, they are redirected
    const worldview = req.session.user?.country;
    const india_worldview = worldview === 'IN';
    dispatch(actions.setWorldview(worldview));

    if (dataset) {
    dispatch(actions.setSelectedDataset(String(dataset)));
    datasetData = await fetchDataset(String(dataset), { language: locale });
    if (
    india_worldview &&
    INDIA_BLACKLIST_DATASET_IDS.includes(datasetData.id)
    )
    return {
    redirect: {
    destination: '/unauthorized',
    permanent: false,
    },
    };
    }
  3. For Crop pages, the user is directed to the proper geostore supporting their worldview
    const worldview = req.session.user?.country;
    const india_worldview = worldview === 'IN';
    dispatch(actions.setWorldview(worldview));
    if (india_worldview && geostore === 'fb119d758d39527a91307b7fed3debf4')
    return {
    redirect: {
    destination: '/crops/coffee/1252b02f0a27cf77fd19b8298be6a8db',
    permanent: false,
    },
    };
  4. For map widgets, a disclaimer is displayed if the user's country and the selected country are the same, and have disputed borders
    {caption && (
    <WidgetCaption
    {...(worldview === 'IN' &&
    disclaimer_aoi_ids.includes(String(aoiLayer?.id)) && {
    disclaimer: t(india_maps_disclaimer),
    })}
    text={caption}
    />
    )}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.