rating-control-fix

This commit is contained in:
Untone 2024-01-23 01:12:25 +03:00
parent 30e143e081
commit 40ea97c463
2 changed files with 9 additions and 10 deletions

View File

@ -26,7 +26,7 @@ export const ShoutRatingControl = (props: ShoutRatingControlProps) => {
const {
reactionEntities,
actions: { createReaction, deleteReaction, loadReactionsBy },
actions: { createReaction, loadReactionsBy },
} = useReactions()
const checkReaction = (reactionKind: ReactionKind) =>

View File

@ -47,7 +47,6 @@ export type SessionContextType = {
authError: Accessor<string>
isSessionLoaded: Accessor<boolean>
subscriptions: Accessor<Result>
isAuthWithCallback: Accessor<() => void>
isAuthenticated: Accessor<boolean>
actions: {
loadSession: () => AuthToken | Promise<AuthToken>
@ -70,6 +69,8 @@ export type SessionContextType = {
}
}
const noop = () => {}
const SessionContext = createContext<SessionContextType>()
export function useSession() {
@ -250,11 +251,9 @@ export const SessionProvider = (props: {
),
)
// require auth wrapper
const [isAuthWithCallback, setIsAuthWithCallback] = createSignal<() => void>()
const [authCallback, setAuthCallback] = createSignal<() => void>(() => {})
const requireAuthentication = async (callback: () => void, modalSource: AuthModalSource) => {
setIsAuthWithCallback(() => callback)
setAuthCallback((_cb) => callback)
if (!session()) {
await loadSession()
if (!session()) {
@ -264,9 +263,10 @@ export const SessionProvider = (props: {
}
createEffect(() => {
if (isAuthWithCallback()) {
isAuthWithCallback()()
setIsAuthWithCallback(null)
const handler = authCallback()
if (handler !== noop) {
handler()
setAuthCallback((_cb) => noop)
}
})
@ -345,7 +345,6 @@ export const SessionProvider = (props: {
isSessionLoaded,
author,
actions,
isAuthWithCallback,
isAuthenticated,
}