All checks were successful
continuous-integration/drone/push Build is passing
33 lines
929 B
TypeScript
33 lines
929 B
TypeScript
import { useState } from 'react'
|
|
import { USER_COOKIE_NAME } from '../background/constants'
|
|
import { getCookie, setCookie } from '../background/cookies'
|
|
import { UserInfo } from '../components/jitsi/types'
|
|
|
|
function useLocalUser() {
|
|
const [userInfo, setUserInfoLocal] = useState<UserInfo>(() => getUserInfoFromCookie())
|
|
|
|
const setUserInfo = (newData: UserInfo) => {
|
|
storeUserInfoInCookie(newData)
|
|
setUserInfoLocal(newData)
|
|
}
|
|
|
|
return { userInfo, setUserInfo }
|
|
}
|
|
|
|
function getUserInfoFromCookie(): UserInfo {
|
|
let cookie = getCookie(USER_COOKIE_NAME)
|
|
console.log('[Rooms] getUserNameFromCookie', cookie)
|
|
if (cookie) return JSON.parse(cookie)
|
|
return {
|
|
displayName: 'Unknown traveller',
|
|
email: '',
|
|
}
|
|
}
|
|
|
|
function storeUserInfoInCookie(userInfo: UserInfo) {
|
|
console.log('[Rooms] storeUserInfoInCookie', userInfo)
|
|
setCookie(USER_COOKIE_NAME, JSON.stringify(userInfo))
|
|
}
|
|
|
|
export default useLocalUser
|