Giter VIP home page Giter VIP logo

agriadapt's People

Contributors

kyleaig2 avatar naush-khiljee avatar vincentlinzhu avatar

Stargazers

 avatar

Watchers

 avatar  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.