-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: migrate multiple files in libs to full TS
refactor: improve typing for RootNavigation refactor: rename constants to .ts refactor: rename localStore index to .ts refactor: rename multiple files in lib/fn to ts refactor: update files with typings some tests will fail, to be fixed next commit refactor: fix tests after typing
- Loading branch information
Showing
34 changed files
with
298 additions
and
212 deletions.
There are no files selected for viewing
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
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
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useEffect, useMemo, useState } from 'react' | ||
|
||
import { useClient, useCapabilities } from 'cozy-client' | ||
|
||
import { makeSessionAPI, SessionApi } from '/libs/functions/session' | ||
|
||
export const useSession = (): SessionApi => { | ||
const [subdomainType, setSubdomainType] = useState<string>() | ||
const client = useClient() | ||
const { capabilities, fetchStatus } = useCapabilities(client) | ||
|
||
useEffect(() => { | ||
fetchStatus === 'loaded' && | ||
// @ts-expect-error : cozy-client has to be updated | ||
setSubdomainType(capabilities?.flat_subdomains ? 'flat' : 'nested') | ||
}, [capabilities, fetchStatus]) | ||
|
||
return useMemo( | ||
// We have to assume that client and subdomainType are defined | ||
// Still, this is old code and we should probably refactor it | ||
// Adding a @TODO flag for now | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
() => makeSessionAPI(client!, subdomainType!), | ||
[client, subdomainType] | ||
) | ||
} |
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
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { getErrorMessage } from 'cozy-intent' | ||
|
||
import { devlog } from '/core/tools/env' | ||
|
||
export const getHostname = ( | ||
nativeEvent?: { url?: string | unknown } | unknown | ||
): string | undefined => { | ||
if ( | ||
!nativeEvent || | ||
typeof nativeEvent !== 'object' || | ||
!('url' in nativeEvent) || | ||
typeof nativeEvent.url !== 'string' | ||
) | ||
return | ||
|
||
try { | ||
return new URL(nativeEvent.url).hostname | ||
} catch (error) { | ||
devlog('getHostname failed, nativeEvent:', nativeEvent, error) | ||
if (getErrorMessage(error).includes('Invalid URL')) return nativeEvent.url | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type CozyClient from 'cozy-client' | ||
|
||
export const isSecureProtocol = (client: CozyClient): boolean => { | ||
const instanceUrl = new URL(client.getStackClient().uri) | ||
|
||
return instanceUrl.protocol === 'https:' | ||
} |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
type makeHandlersType = ( | ||
handlers?: Record<string, () => void> | ||
) => (event?: { nativeEvent?: { data?: string | unknown } }) => void | ||
|
||
export const makeHandlers: makeHandlersType = handlers => event => | ||
Object.keys(handlers?.constructor === Object ? handlers : {}).forEach( | ||
handlerName => { | ||
const data = event?.nativeEvent?.data | ||
const isString = typeof data === 'string' | ||
|
||
if (!isString) return | ||
|
||
return data.includes(handlerName) && handlers?.[handlerName]?.() | ||
} | ||
) |
36 changes: 17 additions & 19 deletions
36
src/libs/functions/routeHelpers.spec.js → src/libs/functions/routeHelpers.spec.ts
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
Oops, something went wrong.