Skip to content

Commit

Permalink
feat: 🎸 Fix image load and typescript errors (kolplattformen#570)
Browse files Browse the repository at this point in the history
* Update Cocoapods version
* Use new api GetRequestHeaders to get headers
* Remove warnings of missing colors and brushes
* Fix typing errors
* Change affected main branch to main
* Remove unused feature toggle
* Add dummy login checker to remove using any
  • Loading branch information
whyer authored Dec 2, 2021
1 parent aea848f commit 933a884
Show file tree
Hide file tree
Showing 36 changed files with 84 additions and 54 deletions.
2 changes: 1 addition & 1 deletion apps/skolplattformen-app/components/calendar.component.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CalendarItem } from '@skolplattformen/api-skolplattformen'
import { CalendarItem } from '@skolplattformen/api'
import { useCalendar } from '@skolplattformen/hooks'
import {
Divider,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Child } from '@skolplattformen/api-skolplattformen'
import { Child } from '@skolplattformen/api'
import React, { createContext, useContext } from 'react'

interface ChildProviderProps {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable react-native-a11y/has-accessibility-hint */
import { useNavigation } from '@react-navigation/native'
import { StackNavigationProp } from '@react-navigation/stack'
import { Child } from '@skolplattformen/api-skolplattformen'
import { Child } from '@skolplattformen/api'
import {
useCalendar,
useClassmates,
Expand Down
2 changes: 1 addition & 1 deletion apps/skolplattformen-app/components/children.component.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useNavigation } from '@react-navigation/core'
import { Child } from '@skolplattformen/api-skolplattformen'
import { Child } from '@skolplattformen/api'
import { useApi, useChildList } from '@skolplattformen/hooks'
import {
Button,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Classmate } from '@skolplattformen/api-skolplattformen'
import { Classmate } from '@skolplattformen/api'
import { useClassmates } from '@skolplattformen/hooks'
import {
Divider,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable react-native-a11y/has-accessibility-hint */
import { Classmate } from '@skolplattformen/api-skolplattformen'
import { Classmate } from '@skolplattformen/api'
import {
Button,
MenuGroup,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Child } from '@skolplattformen/api-skolplattformen'
import { Child } from '@skolplattformen/api'
import { useTimetable } from '@skolplattformen/hooks'
import { StyleService, Text, useStyleSheet } from '@ui-kitten/components'
import moment, { Moment } from 'moment'
Expand Down
4 changes: 2 additions & 2 deletions apps/skolplattformen-app/components/image.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const Image = ({
resizeMode = 'contain',
}: ImageProps) => {
const { api } = useApi()
const [headers, setHeaders] = useState()
const [headers, setHeaders] = useState<{ [index: string]: string }>()
const { width: windowWidth } = useWindowDimensions()
const [dimensions, setDimensions] = useState({ width: 0, height: 0 })

Expand All @@ -40,7 +40,7 @@ export const Image = ({
const prefetchImageInformation = useCallback(
async (url: string) => {
if (!url) return
const { headers: newHeaders } = await api.getSession(url)
const newHeaders = await api.getSessionHeaders(url)

console.log('[IMAGE] Getting image dimensions with headers', {
debugImageName,
Expand Down
2 changes: 1 addition & 1 deletion apps/skolplattformen-app/components/menu.component.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MenuItem } from '@skolplattformen/api-skolplattformen'
import { MenuItem } from '@skolplattformen/api'
import { useMenu } from '@skolplattformen/hooks'
import {
Divider,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MenuItem } from '@skolplattformen/api-skolplattformen'
import { MenuItem } from '@skolplattformen/api'
import { StyleService, Text, useStyleSheet } from '@ui-kitten/components'
import React from 'react'
import { View } from 'react-native'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ export const ModalWebView = ({
const [modalVisible, setModalVisible] = React.useState(true)
const { api } = useApi()
const [title, setTitle] = React.useState('...')
const [headers, setHeaders] = useState()
const [headers, setHeaders] = useState<{ [index: string]: string }>()

useEffect(() => {
const getHeaders = async (urlToGetSessionFor: string) => {
if (sharedCookiesEnabled) return
const { headers: newHeaders } = await api.getSession(urlToGetSessionFor)
const newHeaders = await api.getSessionHeaders(urlToGetSessionFor)
setHeaders(newHeaders)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NavigationContainer } from '@react-navigation/native'
import {
Child as ChildType,
NewsItem as NewsItemType,
} from '@skolplattformen/api-skolplattformen'
} from '@skolplattformen/api'
import { useApi } from '@skolplattformen/hooks'
import { useTheme } from '@ui-kitten/components'
import { Library } from 'libraries.json'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useNavigation } from '@react-navigation/native'
import { StackNavigationProp } from '@react-navigation/stack'
import { NewsItem } from '@skolplattformen/api-skolplattformen'
import { NewsItem } from '@skolplattformen/api'
import { StyleService, useStyleSheet } from '@ui-kitten/components'
import moment from 'moment'
import React, { ReactNode } from 'react'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Notification as NotificationType } from '@skolplattformen/api-skolplattformen'
import { Notification as NotificationType } from '@skolplattformen/api'
import { StyleService, Text, useStyleSheet } from '@ui-kitten/components'
import moment from 'moment'
import React from 'react'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CalendarItem } from '@skolplattformen/api-skolplattformen'
import { CalendarItem } from '@skolplattformen/api'
import { Button, MenuItem, OverflowMenu, Text } from '@ui-kitten/components'
import React from 'react'
import RNCalendarEvents from 'react-native-calendar-events'
Expand Down
6 changes: 1 addition & 5 deletions apps/skolplattformen-app/components/week.component.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
Child,
MenuItem,
TimetableEntry,
} from '@skolplattformen/api-skolplattformen'
import { Child, MenuItem, TimetableEntry } from '@skolplattformen/api'
import { useMenu, useTimetable } from '@skolplattformen/hooks'
import {
List,
Expand Down
3 changes: 2 additions & 1 deletion apps/skolplattformen-app/context/feature/featureContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { Features, FeatureType } from '@skolplattformen/api'
import React from 'react'

export const FeatureFlagsContext = React.createContext<Features>({
LOGIN_BANK_ID_SAME_DEVICE: false,
LOGIN_BANK_ID_SAME_DEVICE_WITHOUT_ID: true,
FOOD_MENU: false,
CLASS_LIST: true,
})

interface Props {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const SchoolPlatformProvider: React.FC = ({ children }) => {
'currentSchoolPlatform'
)

const changeSchoolPlatform = (platform: string) => {
const changeSchoolPlatform = (platform) => {
setCurrentSchoolPlatform(platform)
}

Expand Down
4 changes: 2 additions & 2 deletions apps/skolplattformen-app/data/schoolPlatforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ export const schoolPlatforms = [
{
id: 'stockholm-skolplattformen',
displayName: 'Stockholm stad (Skolplattformen)',
api: initSkolplattformen(fetch, CookieManager),
api: initSkolplattformen(fetch as any, CookieManager),
features: featuresSkolPlattformen,
},
{
id: 'goteborg-hjarntorget',
displayName: 'Göteborg stad (Hjärntorget)',
api: initHjarntorget(fetch, CookieManager),
api: initHjarntorget(fetch as any, CookieManager),
features: featuresHjarntorget,
},
]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import AsyncStorage from '@react-native-async-storage/async-storage'
import { User } from '@skolplattformen/api-skolplattformen'
import { User } from '@skolplattformen/api'
import { act, renderHook } from '@testing-library/react-hooks'
import usePersonalStorage from '../usePersonalStorage'

Expand Down
2 changes: 1 addition & 1 deletion apps/skolplattformen-app/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -669,4 +669,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 85f5a2dfa1de342b427eecb6e9652410ad153247

COCOAPODS: 1.10.1
COCOAPODS: 1.11.2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import AsyncStorage from '@react-native-async-storage/async-storage'
import { User } from '@skolplattformen/api-skolplattformen'
import { User } from '@skolplattformen/api'
import AppStorage from '../appStorage'

beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion apps/skolplattformen-app/services/appStorage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import AsyncStorage from '@react-native-async-storage/async-storage'
import { User } from '@skolplattformen/api-skolplattformen'
import { User } from '@skolplattformen/api'

export default class AppStorage {
static settingsStorageKeyPrefix = 'appsetting_'
Expand Down
2 changes: 1 addition & 1 deletion apps/skolplattformen-app/utils/peopleHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Guardian } from '@skolplattformen/api-skolplattformen'
import { Guardian } from '@skolplattformen/api'

export const studentName = (name?: string) => name?.replace(/\s?\(\w+\)$/, '')

Expand Down
2 changes: 1 addition & 1 deletion apps/skolplattformen-app/utils/search.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NewsItem } from '@skolplattformen/api-skolplattformen'
import { NewsItem } from '@skolplattformen/api'
import { useNews } from '@skolplattformen/hooks'
import { MatchData, Searcher } from 'fast-fuzzy'
import React, { ReactNode, useMemo } from 'react'
Expand Down
3 changes: 2 additions & 1 deletion apps/skolplattformen-app/utils/testHelpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { EvaIconsPack } from '@ui-kitten/eva-icons'
import React, { ReactElement } from 'react'
import { LanguageProvider } from '../context/language/languageContext'
import { translations } from './translation'
import { lightTheme } from '../design/themes'

export const render = (
ui: ReactElement<any, string>,
Expand All @@ -14,7 +15,7 @@ export const render = (
return (
<>
<IconRegistry icons={EvaIconsPack} />
<ApplicationProvider {...eva} theme={eva.light}>
<ApplicationProvider {...eva} theme={lightTheme}>
<LanguageProvider
cache={false}
data={translations}
Expand Down
16 changes: 12 additions & 4 deletions libs/api-hjarntorget/lib/apiHjarntorget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Classmate,
CookieManager,
EtjanstChild,
Fetch,
Fetcher,
FetcherOptions,
LoginStatusChecker,
Expand All @@ -24,7 +25,7 @@ import { decode } from 'he'
import { DateTime, FixedOffsetZone } from 'luxon'
import * as html from 'node-html-parser'
import { fakeFetcher } from './fake/fakeFetcher'
import { checkStatus } from './loginStatus'
import { checkStatus, DummyStatusChecker } from './loginStatus'
import { extractMvghostRequestBody, parseCalendarItem } from './parse/parsers'
import {
beginBankIdUrl,
Expand Down Expand Up @@ -84,7 +85,7 @@ export class ApiHjarntorget extends EventEmitter implements Api {
}

constructor(
fetch: typeof global.fetch,
fetch: Fetch,
cookieManager: CookieManager,
options?: FetcherOptions
) {
Expand Down Expand Up @@ -138,6 +139,13 @@ export class ApiHjarntorget extends EventEmitter implements Api {
return this.personalNumber
}

public async getSessionHeaders(url: string): Promise<{ [index: string]: string }> {
const cookie = await this.cookieManager.getCookieString(url)
return {
cookie,
}
}

async setSessionCookie(sessionCookie: string): Promise<void> {
await this.fetch('login-cookie', hjarntorgetUrl, {
headers: {
Expand Down Expand Up @@ -490,13 +498,13 @@ export class ApiHjarntorget extends EventEmitter implements Api {

if((beginLoginRedirectResponse as any).url.endsWith("startPage.do")) {
// already logged in!
const emitter = new EventEmitter()
const emitter = new DummyStatusChecker()
setTimeout(() => {
this.isLoggedIn = true
emitter.emit('OK')
this.emit('login')
}, 50)
return emitter;
return emitter as LoginStatusChecker;
}

console.log('prepping??? shibboleth')
Expand Down
Loading

0 comments on commit 933a884

Please sign in to comment.