Skip to content

Commit 75a0bad

Browse files
Logo component
app version as hook
1 parent 9b7f814 commit 75a0bad

6 files changed

Lines changed: 64 additions & 1 deletion

File tree

src/app/clientApp/App/AppRest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,4 @@ export const getParentAppWellKnownConfiguration = (wellKnowConfigUrl: string) =>
6666
export const getTheme = (url: string) =>
6767
fetchApi(`${url}/theme/theme.json`, {
6868
useToken: false,
69-
})
69+
})

src/common/hooks/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export * from './use-is-mounted'
55
export * from './use-emitter-data'
66
export * from './use-emitter'
77
export * from './useWellKnownConfiguration'
8+
export * from './use-app-version'
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { useCallback, useEffect, useState } from 'react'
2+
import { getMinutesBetweenDates } from '../utils'
3+
import { GITHUB_VERSION_REQUEST_INTERVAL } from '../../app/clientApp/constants'
4+
import { getVersionNumberFromGithub } from '../../app/clientApp/App/AppRest'
5+
6+
type SettingsType = {
7+
requestedDatetime?: string
8+
}
9+
10+
type VersionObject = {
11+
requestedDatetime: Date
12+
latest: string
13+
latest_url: string
14+
}
15+
16+
export function useAppVersion(settings: SettingsType) {
17+
const { requestedDatetime } = settings
18+
const [version, setVersion] = useState<VersionObject | null>(null)
19+
20+
const requestVersion = useCallback((now: Date) => {
21+
getVersionNumberFromGithub().then((ret) => {
22+
setVersion({
23+
requestedDatetime: now,
24+
latest: ret.data.tag_name.replace('v', ''),
25+
latest_url: ret.data.html_url,
26+
})
27+
})
28+
}, [])
29+
30+
useEffect(() => {
31+
const now: Date = new Date()
32+
33+
if (!requestedDatetime || getMinutesBetweenDates(new Date(requestedDatetime), now) > GITHUB_VERSION_REQUEST_INTERVAL) {
34+
requestVersion(now)
35+
}
36+
37+
// eslint-disable-next-line react-hooks/exhaustive-deps
38+
}, [])
39+
40+
return [version]
41+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { FC } from 'react'
2+
3+
import { Props } from './Logo.types'
4+
5+
const Logo: FC<Props> = (props) => {
6+
const { css, logo, className, onClick, title } = props
7+
return <img alt={title || ''} className={className} css={css} height={logo.height} onClick={onClick} src={logo.source} width={logo.width} />
8+
}
9+
10+
Logo.displayName = 'Logo'
11+
12+
export default Logo
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export type Props = {
2+
css?: string
3+
logo: { height: string; width: string; source: string }
4+
className?: string
5+
onClick?: () => void
6+
title?: string
7+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { default } from './Logo'
2+
export * from './Logo'

0 commit comments

Comments
 (0)