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';
* @typedef {import('../../types/api').Profile} Profile
* @typedef {import('../../types/config').MergedConfig} MergedConfig
* @typedef {import('../../shared/bridge').default} Bridge
* @typedef {import('./UserMenu').AuthState} AuthState
*/
/**
* Return the user's authentication status from their profile.
*
* @param {Profile} profile - The profile object from the API.
* @return {AuthState}
*/
function authStateFromProfile(profile) {
const parsed = parseAccountID(profile.userid);
if (parsed) {
if (parsed && profile.userid) {
let displayName = parsed.username;
if (profile.user_info && profile.user_info.display_name) {
displayName = profile.user_info.display_name;
......@@ -43,7 +45,6 @@ function authStateFromProfile(profile) {
displayName,
userid: profile.userid,
username: parsed.username,
provider: parsed.provider,
};
} else {
return { status: 'logged-out' };
......@@ -73,6 +74,7 @@ function HypothesisApp({ auth, bridge, settings, session, toastMessenger }) {
const profile = store.profile();
const route = store.route();
/** @type {AuthState} */
const authState = useMemo(() => {
if (!hasFetchedProfile) {
return { status: 'unknown' };
......@@ -172,7 +174,6 @@ function HypothesisApp({ auth, bridge, settings, session, toastMessenger }) {
>
{route !== 'notebook' && (
<TopBar
// @ts-expect-error - This type mismatch needs to be fixed or the prop removed.
auth={authState}
onLogin={login}
onSignUp={signUp}
......@@ -182,7 +183,7 @@ function HypothesisApp({ auth, bridge, settings, session, toastMessenger }) {
)}
<div className="HypothesisApp__content">
<ToastMessages />
<HelpPanel auth={authState} />
<HelpPanel auth={authState.status === 'logged-in' ? authState : {}} />
<ShareAnnotationsPanel />
{route && (
......
......@@ -16,16 +16,17 @@ import MenuSection from './MenuSection';
* /
/**
* @typedef AuthState
* @prop {'logged-in'|'logged-out'|'unknown'} status
* @typedef AuthStateLoggedIn
* @prop {'logged-in'} status
* @prop {string} displayName
* @prop {string} userid
* @prop {string} username
* @typedef {{status: 'logged-out'|'unknown'} | AuthStateLoggedIn} AuthState
*/
/**
* @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 {Object} bridge
* @prop {MergedConfig} settings
......
......@@ -182,7 +182,6 @@ describe('HypothesisApp', () => {
status: 'logged-in',
userid: 'acct:jim@hypothes.is',
username: 'jim',
provider: 'hypothes.is',
displayName: 'Jim Smith',
},
},
......@@ -198,7 +197,6 @@ describe('HypothesisApp', () => {
status: 'logged-in',
userid: 'acct:jim@hypothes.is',
username: 'jim',
provider: 'hypothes.is',
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