0.0.23 • Published 3 years ago

rice-instructor v0.0.23

Weekly downloads
52
License
MIT
Repository
-
Last release
3 years ago

Usage

LoginForm and getClient

import * as React from 'react'
import { ApolloProvider } from '@apollo/client'

import { BrowserRouter, Switch, Route } from 'react-router-dom'
import { Home } from './Home'
import { LoginForm, getClient } from 'rice-instructor'

const submitCredential = async (username: string, password: string) => {
  const res = await fetch(`http://localhost:8888/login`, {
    method: 'POST',
    body: JSON.stringify({ username, password }),
    headers: {
      'Content-Type': 'application/json',
      'X-Requested-With': 'XMLHttpRequest',
    },
  })

  const data = await res.json()
  if (data.code === 200) {
    sessionStorage.setItem('authToken', data.token)
    // Redirect to root
    window.location.href = '/'
  } else {
    throw data
  }
  return data
}

const Routes = () => {
  return (
    <BrowserRouter>
      <div>
        <Switch>
          <Route exact path="/LoginPage">
            <LoginForm onSubmitCredential={submitCredential} />
          </Route>
          <Route path="/" component={Home}></Route>
        </Switch>
      </div>
    </BrowserRouter>
  )
}
const client = getClient({ uri: 'http://localhost:8888/graphql' })
const App = () => {
  return (
    <ApolloProvider client={client}>
      <Routes />
    </ApolloProvider>
  )
}

Directory, SnackProvider and Admin

import * as React from 'react'
import { ThemeProvider } from '@material-ui/core/styles'

import { SnackProvider, Admin, Directory } from 'rice-instructor'

import { theme } from '../theme'

const routes = [{ path: '/Admin', children: <Admin /> }]
export const Home = () => {
  return (
    <ThemeProvider theme={theme}>
      <SnackProvider>
        <Directory routes={routes} redirectToLoginIfUnauthenticated={true} />
      </SnackProvider>
    </ThemeProvider>
  )
}

Install locally

  • yarn install && yarn build && yarn link
  • In another repo: yarn link "rice-instructor"
0.0.20

3 years ago

0.0.21

3 years ago

0.0.22

3 years ago

0.0.23

3 years ago

0.0.19

3 years ago

0.0.17

3 years ago

0.0.18

3 years ago

0.0.16

3 years ago

0.0.15

3 years ago

0.0.14

5 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8-rc2

6 years ago

0.0.8-rc1

6 years ago

0.0.7

6 years ago

0.0.7-rc5

6 years ago

0.0.7-rc4

6 years ago

0.0.7-rc3

6 years ago

0.0.7-rc2

6 years ago

0.0.7-rc1

6 years ago

0.0.6

6 years ago

0.0.6-rc3

6 years ago

0.0.6-rc2

6 years ago

0.0.6-rc1

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago

0.0.0

6 years ago