This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react' | |
import {FullPageSpinner} from '~/components/lib' | |
const AuthContext = React.createContext() | |
function AuthProvider(props) { | |
// code for pre-loading the user's information if we have their token in | |
// localStorage goes here | |
// 🚨 this is the important bit. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
const context = React.createContext(); | |
export function QueryClientProvider({ children, client }) { | |
React.useEffect(() => { | |
const onFocus = () => { | |
client.queries.forEach((query) => { | |
query.subscribers.forEach((subscriber) => { | |
subscriber.fetch(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const PrivateRoute = ({ component: Component, roles, ...rest }) => ( | |
<Route {...rest} render={props => { | |
const currentUser = authenticationService.currentUserValue; | |
if (!currentUser) { | |
// not logged in so redirect to login page with the return url | |
return <Redirect to={{ pathname: '/login', state: { from: props.location } }} /> | |
} | |
// check if route is restricted by role | |
if (roles && roles.indexOf(currentUser.role) === -1) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Observable, of} from "rxjs"; | |
import {catchError, map} from "rxjs/operators"; | |
import {ajax} from "rxjs/ajax"; | |
class Http { | |
public get<T extends Object = Object>(url: string, headers?: any): Observable<T> { | |
return ajax.get.apply(undefined, [`${url}`, headers]).pipe(catchError(this.catchError), map(this.map)); | |
} | |
public post<T extends Object = Object>(url: string, body?: any, headers?: any): Observable<T> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useCallback, useState } from 'react'; | |
// Usage | |
function App() { | |
// Call the hook which returns, current value and the toggler function | |
const [isTextChanged, setIsTextChanged] = useToggle(); | |
return ( | |
<button onClick={setIsTextChanged}>{isTextChanged ? 'Toggled' : 'Click to Toggle'}</button> |