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 { const {
reactionEntities, reactionEntities,
actions: { createReaction, deleteReaction, loadReactionsBy }, actions: { createReaction, loadReactionsBy },
} = useReactions() } = useReactions()
const checkReaction = (reactionKind: ReactionKind) => const checkReaction = (reactionKind: ReactionKind) =>

View File

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