Commit 785e1397 authored by Eduardo Sanz García's avatar Eduardo Sanz García Committed by Eduardo

Remove ts-expect-error and improve types

I removed a @ts-expect-error and tight some types.

I remove the returned `provider` property from the
`authStateFromProfile` function as it was not used.
parent 10371345
...@@ -24,16 +24,18 @@ import TopBar from './TopBar'; ...@@ -24,16 +24,18 @@ import TopBar from './TopBar';
* @typedef {import('../../types/api').Profile} Profile * @typedef {import('../../types/api').Profile} Profile
* @typedef {import('../../types/config').MergedConfig} MergedConfig * @typedef {import('../../types/config').MergedConfig} MergedConfig
* @typedef {import('../../shared/bridge').default} Bridge * @typedef {import('../../shared/bridge').default} Bridge
* @typedef {import('./UserMenu').AuthState} AuthState
*/ */
/** /**
* Return the user's authentication status from their profile. * Return the user's authentication status from their profile.
* *
* @param {Profile} profile - The profile object from the API. * @param {Profile} profile - The profile object from the API.
* @return {AuthState}
*/ */
function authStateFromProfile(profile) { function authStateFromProfile(profile) {
const parsed = parseAccountID(profile.userid); const parsed = parseAccountID(profile.userid);
if (parsed) { if (parsed && profile.userid) {
let displayName = parsed.username; let displayName = parsed.username;
if (profile.user_info && profile.user_info.display_name) { if (profile.user_info && profile.user_info.display_name) {
displayName = profile.user_info.display_name; displayName = profile.user_info.display_name;
...@@ -43,7 +45,6 @@ function authStateFromProfile(profile) { ...@@ -43,7 +45,6 @@ function authStateFromProfile(profile) {
displayName, displayName,
userid: profile.userid, userid: profile.userid,
username: parsed.username, username: parsed.username,
provider: parsed.provider,
}; };
} else { } else {
return { status: 'logged-out' }; return { status: 'logged-out' };
...@@ -73,6 +74,7 @@ function HypothesisApp({ auth, bridge, settings, session, toastMessenger }) { ...@@ -73,6 +74,7 @@ function HypothesisApp({ auth, bridge, settings, session, toastMessenger }) {
const profile = store.profile(); const profile = store.profile();
const route = store.route(); const route = store.route();
/** @type {AuthState} */
const authState = useMemo(() => { const authState = useMemo(() => {
if (!hasFetchedProfile) { if (!hasFetchedProfile) {
return { status: 'unknown' }; return { status: 'unknown' };
...@@ -172,7 +174,6 @@ function HypothesisApp({ auth, bridge, settings, session, toastMessenger }) { ...@@ -172,7 +174,6 @@ function HypothesisApp({ auth, bridge, settings, session, toastMessenger }) {
> >
{route !== 'notebook' && ( {route !== 'notebook' && (
<TopBar <TopBar
// @ts-expect-error - This type mismatch needs to be fixed or the prop removed.
auth={authState} auth={authState}
onLogin={login} onLogin={login}
onSignUp={signUp} onSignUp={signUp}
...@@ -182,7 +183,7 @@ function HypothesisApp({ auth, bridge, settings, session, toastMessenger }) { ...@@ -182,7 +183,7 @@ function HypothesisApp({ auth, bridge, settings, session, toastMessenger }) {
)} )}
<div className="HypothesisApp__content"> <div className="HypothesisApp__content">
<ToastMessages /> <ToastMessages />
<HelpPanel auth={authState} /> <HelpPanel auth={authState.status === 'logged-in' ? authState : {}} />
<ShareAnnotationsPanel /> <ShareAnnotationsPanel />
{route && ( {route && (
......
...@@ -16,16 +16,17 @@ import MenuSection from './MenuSection'; ...@@ -16,16 +16,17 @@ import MenuSection from './MenuSection';
* / * /
/** /**
* @typedef AuthState * @typedef AuthStateLoggedIn
* @prop {'logged-in'|'logged-out'|'unknown'} status * @prop {'logged-in'} status
* @prop {string} displayName * @prop {string} displayName
* @prop {string} userid * @prop {string} userid
* @prop {string} username * @prop {string} username
* @typedef {{status: 'logged-out'|'unknown'} | AuthStateLoggedIn} AuthState
*/ */
/** /**
* @typedef UserMenuProps * @typedef UserMenuProps
* @prop {AuthState} auth - object representing authenticated user and auth status * @prop {AuthStateLoggedIn} auth - object representing authenticated user and auth status
* @prop {() => any} onLogout - onClick callback for the "log out" button * @prop {() => any} onLogout - onClick callback for the "log out" button
* @prop {Object} bridge * @prop {Object} bridge
* @prop {MergedConfig} settings * @prop {MergedConfig} settings
......
...@@ -182,7 +182,6 @@ describe('HypothesisApp', () => { ...@@ -182,7 +182,6 @@ describe('HypothesisApp', () => {
status: 'logged-in', status: 'logged-in',
userid: 'acct:jim@hypothes.is', userid: 'acct:jim@hypothes.is',
username: 'jim', username: 'jim',
provider: 'hypothes.is',
displayName: 'Jim Smith', displayName: 'Jim Smith',
}, },
}, },
...@@ -198,7 +197,6 @@ describe('HypothesisApp', () => { ...@@ -198,7 +197,6 @@ describe('HypothesisApp', () => {
status: 'logged-in', status: 'logged-in',
userid: 'acct:jim@hypothes.is', userid: 'acct:jim@hypothes.is',
username: 'jim', username: 'jim',
provider: 'hypothes.is',
displayName: 'jim', displayName: 'jim',
}, },
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment