Skip to content

Alpha 11 #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 43 additions & 37 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,46 @@
# This workflow performs basic checks:
#
# 1. run a preparation step to install and cache node modules
# 2. once prep succeeds, lint and test run in parallel
#
# The checks only run on non-draft Pull Requests. They don't run on the main
# branch prior to deploy. It's recommended to use branch protection to avoid
# pushes straight to 'main'.

name: Checks
on:
push:
branches:
- main

on:
pull_request:
branches:
- main
types:
- opened
- synchronize
- reopened
- ready_for_review

env:
NODE: 16
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
prep:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest

steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.8.0
with:
access_token: ${{ github.token }}

- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Use Node.js ${{ env.NODE }}
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE }}
node-version-file: '.nvmrc'

- name: Cache node_modules
uses: actions/cache@v2
uses: actions/cache@v4
id: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}
key: ${{ runner.os }}-build-${{ hashFiles('**/package.json') }}

- name: Install
run: yarn install
Expand All @@ -45,74 +51,74 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Use Node.js ${{ env.NODE }}
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE }}
node-version-file: '.nvmrc'

- name: Cache node_modules
uses: actions/cache@v2
uses: actions/cache@v4
id: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}
key: ${{ runner.os }}-build-${{ hashFiles('**/package.json') }}

- name: Install
run: yarn install

- name: Lint
run: yarn lint
run: yarn run lint

test:
needs: prep
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Use Node.js ${{ env.NODE }}
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE }}
node-version-file: '.nvmrc'

- name: Cache node_modules
uses: actions/cache@v2
uses: actions/cache@v4
id: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}
key: ${{ runner.os }}-build-${{ hashFiles('**/package.json') }}

- name: Install
run: yarn install

- name: Test
run: yarn test
run: yarn run test

build:
needs: test
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Use Node.js ${{ env.NODE }}
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE }}
node-version-file: '.nvmrc'

- name: Cache node_modules
uses: actions/cache@v2
uses: actions/cache@v4
id: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}
key: ${{ runner.os }}-build-${{ hashFiles('**/package.json') }}

- name: Install
run: yarn install

- name: Test
run: yarn build
- name: Build
run: yarn run build
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": true,
"trailingComma": "none",
"singleQuote": true,
"jsxSingleQuote": true,
"printWidth": 80
}
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@developmentseed/stac-react",
"version": "0.1.0-alpha.10",
"version": "0.1.0-alpha.11",
"description": "React components and hooks for building STAC-API front-ends",
"repository": "git@github.com:developmentseed/stac-react.git",
"author": "Oliver Roick <oliver@roick.email>",
Expand All @@ -11,8 +11,8 @@
"types": "./dist/index.d.ts",
"source": "./src/index.ts",
"peerDependencies": {
"react": "^18.1.0",
"react-dom": "^18.1.0"
"react": ">=18.1.0",
"react-dom": ">=18.1.0"
},
"devDependencies": {
"@rollup/plugin-typescript": "^9.0.2",
Expand Down Expand Up @@ -42,5 +42,5 @@
"lint": "eslint 'src/**/*.ts' 'src/**/*.tsx'",
"build": "rollup -c rollup.config.mjs"
},
"dependencies": {}
}
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
16 changes: 16 additions & 0 deletions src/context/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createContext } from 'react';
import StacApi from '../stac-api';
import { CollectionsResponse, Item } from '../types/stac';

type StacApiContextType = {
stacApi?: StacApi;
collections?: CollectionsResponse;
setCollections: (collections?: CollectionsResponse) => void;
getItem: (id: string) => Item | undefined;
addItem: (id: string, item: Item) => void;
deleteItem: (id: string) => void;
};

export const StacApiContext = createContext<StacApiContextType>(
{} as StacApiContextType
);
79 changes: 37 additions & 42 deletions src/context/index.tsx
Original file line number Diff line number Diff line change
@@ -1,70 +1,65 @@
import React, { useMemo, useContext, useState, useCallback } from 'react';
import { createContext } from 'react';

import StacApi from '../stac-api';
import useStacApi from '../hooks/useStacApi';
import type { CollectionsResponse, Item } from '../types/stac';
import { GenericObject } from '../types';

type StacApiContextType = {
stacApi?: StacApi;
collections?: CollectionsResponse;
setCollections: (collections?: CollectionsResponse) => void;
getItem: (id: string) => Item | undefined;
addItem: (id: string, item: Item) => void;
deleteItem: (id: string) => void;
}
import { StacApiContext } from './context';

type StacApiProviderType = {
apiUrl: string;
children: React.ReactNode;
options?: GenericObject;
}
};

export const StacApiContext = createContext<StacApiContextType>({} as StacApiContextType);

export function StacApiProvider({ children, apiUrl, options }: StacApiProviderType) {
export function StacApiProvider({
children,
apiUrl,
options
}: StacApiProviderType) {
const { stacApi } = useStacApi(apiUrl, options);
const [ collections, setCollections ] = useState<CollectionsResponse>();
const [ items, setItems ] = useState(new Map<string, Item>());
const [collections, setCollections] = useState<CollectionsResponse>();
const [items, setItems] = useState(new Map<string, Item>());

const getItem = useCallback((id: string) => items.get(id), [items]);

const addItem = useCallback((itemPath: string, item: Item) => {
setItems(new Map(items.set(itemPath, item)));
}, [items]);
const addItem = useCallback(
(itemPath: string, item: Item) => {
setItems(new Map(items.set(itemPath, item)));
},
[items]
);

const deleteItem = useCallback((itemPath: string) => {
const tempItems = new Map(items);
items.delete(itemPath);
setItems(tempItems);
}, [items]);
const deleteItem = useCallback(
(itemPath: string) => {
const tempItems = new Map(items);
items.delete(itemPath);
setItems(tempItems);
},
[items]
);

const contextValue = useMemo(() => ({
stacApi,
collections,
setCollections,
getItem,
addItem,
deleteItem
}), [addItem, collections, deleteItem, getItem, stacApi]);
const contextValue = useMemo(
() => ({
stacApi,
collections,
setCollections,
getItem,
addItem,
deleteItem
}),
[addItem, collections, deleteItem, getItem, stacApi]
);

return (
<StacApiContext.Provider value={contextValue}>
{ children }
{children}
</StacApiContext.Provider>
);
}

export function useStacApiContext() {
const {
stacApi,
collections,
setCollections,
getItem,
addItem,
deleteItem
} = useContext(StacApiContext);
const { stacApi, collections, setCollections, getItem, addItem, deleteItem } =
useContext(StacApiContext);

return {
stacApi,
Expand Down
Loading
Loading