Skip to content

Commit

Permalink
feat: 🎸 WIP Switch school platform
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorlarsson committed Nov 12, 2021
1 parent 1aaaeb6 commit 916ebc5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,40 @@ import initHjarntorget from '@skolplattformen/api-hjarntorget'
import { ApiProvider } from '@skolplattformen/hooks'
import { ApplicationProvider, IconRegistry } from '@ui-kitten/components'
import { EvaIconsPack } from '@ui-kitten/eva-icons'
import React, { useContext } from 'react'
import React, { useEffect, useState } from 'react'
import { StatusBar, useColorScheme } from 'react-native'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import { AppNavigator } from './components/navigation.component'
import { LanguageProvider } from './context/language/languageContext'
import {
SchoolPlatformProvider,
SchoolPlatformContext,
} from './context/schoolPlatform/schoolPlatformContext'
import { SchoolPlatformProvider } from './context/schoolPlatform/schoolPlatformContext'
import { default as customMapping } from './design/mapping.json'
import { darkTheme, lightTheme } from './design/themes'
import useSettingsStorage from './hooks/useSettingsStorage'
import { translations } from './utils/translation'
import { Reporter } from '@skolplattformen/hooks'
import { Api } from '@skolplattformen/api'

const apiSkolplattformen = initSkolplattformen(fetch, CookieManager)
const apiHjarntorget = initHjarntorget(fetch, CookieManager)
const ApiList = new Map<string, Api>([
// @ts-expect-error Why is fetch failing here?
['stockholm-skolplattformen', initSkolplattformen(fetch, CookieManager)],
// @ts-expect-error Why is fetch failing here?
['goteborg-hjarntorget', initHjarntorget(fetch, CookieManager)],
])

const reporter = __DEV__
const reporter: Reporter | undefined = __DEV__
? {
log: (message) => console.log(message),
error: (error, label) => console.error(label, error),
log: (message: string) => console.log(message),
error: (error: Error, label?: string) => console.error(label, error),
}
: undefined

if (__DEV__) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const DevMenu = require('react-native-dev-menu')
DevMenu.addItem('Log AsyncStorage contents', () => logAsyncStorage())
}

const safeJsonParse = (maybeJson) => {
const safeJsonParse = (maybeJson: string) => {
if (maybeJson) {
try {
return JSON.parse(maybeJson)
Expand All @@ -63,17 +67,18 @@ const logAsyncStorage = async () => {

export default () => {
const [usingSystemTheme] = useSettingsStorage('usingSystemTheme')
const [currentSchoolPlatform] = useSettingsStorage('currentSchoolPlatform')
const [theme] = useSettingsStorage('theme')
const systemTheme = useColorScheme()

const colorScheme = usingSystemTheme ? systemTheme : theme

//const api = ApiList.get(currentSchoolPlatform)!
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const api = ApiList.get('goteborg-hjarntorget')!

return (
<SchoolPlatformProvider>
<ApiProvider
api={apiSkolplattformen}
storage={AsyncStorage}
reporter={reporter}
>
<ApiProvider api={api} storage={AsyncStorage} reporter={reporter}>
<SafeAreaProvider>
<StatusBar
backgroundColor={colorScheme === 'dark' ? '#2E3137' : '#FFF'}
Expand All @@ -83,6 +88,7 @@ export default () => {
<IconRegistry icons={EvaIconsPack} />
<ApplicationProvider
{...eva}
// @ts-expect-error Unknown error
customMapping={customMapping}
theme={colorScheme === 'dark' ? darkTheme : lightTheme}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const LanguageContext = React.createContext<LanguageContextProps>({
interface Props {
children: ReactNode
data: any
initialLanguageCode: string
initialLanguageCode?: string
cache: any
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import useSettingsStorage from '../../hooks/useSettingsStorage'
import React, { createContext } from 'react'

interface SchoolPlatformProps {
currentSchoolPlatform: string
currentSchoolPlatform?: string
changeSchoolPlatform: (platform: string) => void
}

const defaultState: SchoolPlatformProps = {
currentSchoolPlatform: 'stockholm-skolplattformen',
changeSchoolPlatform: (platform: string) =>
console.log('DEBUG ONLY: changing to', platform),
}
Expand Down
1 change: 1 addition & 0 deletions libs/hooks/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './provider'
export * from './context'
export * from './hooks'
export * from './types'
4 changes: 2 additions & 2 deletions libs/hooks/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
import { Action, Reducer } from 'redux'

export interface Reporter {
log: (message: string) => void
error: (error: Error, label?: string) => void
log?: (message: string) => void
error?: (error: Error, label?: string) => void
}

export interface IApiContext {
Expand Down

0 comments on commit 916ebc5

Please sign in to comment.