-
-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only allow users to stop streaming response to >their< last message
- Loading branch information
1 parent
01d1c8c
commit 8a94b19
Showing
9 changed files
with
150 additions
and
79 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React, { useContext, useEffect, useState } from 'react'; | ||
import type { User } from '@jupyterlab/services'; | ||
import { PartialJSONObject } from '@lumino/coreutils'; | ||
|
||
const UserContext = React.createContext< | ||
User.IUser | null | ||
>(null); | ||
|
||
|
||
export function useUserContext(): User.IUser | null { | ||
return useContext(UserContext); | ||
} | ||
|
||
type UserContextProviderProps = { | ||
userManager: User.IManager; | ||
children: React.ReactNode; | ||
}; | ||
|
||
export function UserContextProvider({ | ||
userManager, | ||
children | ||
}: UserContextProviderProps): JSX.Element { | ||
const [user, setUser] = useState<User.IUser | null>(null); | ||
|
||
useEffect(() => { | ||
userManager.ready.then(() => { | ||
setUser({identity: userManager.identity!, permissions: userManager.permissions as PartialJSONObject}); | ||
}); | ||
userManager.userChanged.connect((sender, newUser) => { | ||
setUser(newUser); | ||
}); | ||
}, []); | ||
|
||
return ( | ||
<UserContext.Provider value={user}> | ||
{children} | ||
</UserContext.Provider> | ||
); | ||
} |
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
Oops, something went wrong.