Skip to content

Commit 1e305ac

Browse files
authored
fix: resolve global auth state reactivity and quote search rtl layouts (@byseif21) (monkeytypegame#7735)
1 parent 051da1e commit 1e305ac

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

frontend/src/ts/components/modals/QuoteSearchModal.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { Config } from "../../config/store";
1515
import { isCaptchaAvailable } from "../../controllers/captcha-controller";
1616
import QuotesController, { Quote } from "../../controllers/quotes-controller";
1717
import * as DB from "../../db";
18-
import { isAuthenticated } from "../../firebase";
18+
import { isLoggedIn } from "../../states/core";
1919
import { hideLoaderBar, showLoaderBar } from "../../states/loader-bar";
2020
import {
2121
hideModalAndClearChain,
@@ -100,12 +100,12 @@ function getLengthDesc(quote: Quote): string {
100100
function Item(props: {
101101
quote: Quote;
102102
matchedTerms: string[];
103-
dataBalloonDirection: string;
103+
isRtl: boolean;
104104
onSelect: () => void;
105105
onReport: () => void;
106106
onToggleFavorite: () => Promise<boolean>;
107107
}): JSXElement {
108-
const loggedOut = (): boolean => !isAuthenticated();
108+
const loggedOut = (): boolean => !isLoggedIn();
109109
const [isFav, setIsFav] = createSignal(
110110
// oxlint-disable-next-line solid/reactivity -- intentionally reading once as initial value
111111
!loggedOut() && QuotesController.isQuoteFavorite(props.quote),
@@ -169,7 +169,7 @@ function Item(props: {
169169
}}
170170
balloon={{
171171
text: "Report quote",
172-
position: props.dataBalloonDirection as "left" | "right",
172+
position: props.isRtl ? "right" : "left",
173173
}}
174174
/>
175175
<Button
@@ -184,7 +184,7 @@ function Item(props: {
184184
}}
185185
balloon={{
186186
text: "Favorite quote",
187-
position: props.dataBalloonDirection as "left" | "right",
187+
position: props.isRtl ? "right" : "left",
188188
}}
189189
/>
190190
</div>
@@ -213,7 +213,7 @@ export function QuoteSearchModal(): JSXElement {
213213
quotes: Quote[];
214214
matchedTerms: string[];
215215
}>({ quotes: [], matchedTerms: [] });
216-
const [dataBalloonDirection, setDataBalloonDirection] = createSignal("left");
216+
const [isRtl, setIsRtl] = createSignal(false);
217217
const [favVersion, setFavVersion] = createSignal(0);
218218

219219
const debouncedSearch = debounce(250, (text: string) => {
@@ -374,7 +374,7 @@ export function QuoteSearchModal(): JSXElement {
374374

375375
const handleAfterShow = async (): Promise<void> => {
376376
const quotesLanguage = await getLanguage(Config.language);
377-
setDataBalloonDirection(quotesLanguage?.rightToLeft ? "right" : "left");
377+
setIsRtl(quotesLanguage?.rightToLeft ?? false);
378378
const { quotes: fetchedQuotes } = await QuotesController.getQuotes(
379379
Config.language,
380380
);
@@ -455,7 +455,7 @@ export function QuoteSearchModal(): JSXElement {
455455
<div class="flex flex-col justify-between gap-2 sm:flex-row">
456456
<div class="text-2xl text-sub">Quote search</div>
457457
<div class="grid gap-2">
458-
<Show when={isAuthenticated()}>
458+
<Show when={isLoggedIn()}>
459459
<Button
460460
fa={{ icon: "fa-plus" }}
461461
text="Submit a quote"
@@ -509,7 +509,7 @@ export function QuoteSearchModal(): JSXElement {
509509
}}
510510
/>
511511
</div>
512-
<Show when={isAuthenticated()}>
512+
<Show when={isLoggedIn()}>
513513
<Button
514514
variant="button"
515515
fa={{ icon: "fa-heart", fixedWidth: true }}
@@ -518,13 +518,16 @@ export function QuoteSearchModal(): JSXElement {
518518
/>
519519
</Show>
520520
</div>
521-
<div class="grid content-baseline gap-2 overflow-y-auto" dir="auto">
521+
<div
522+
class="grid content-baseline gap-2 overflow-y-auto"
523+
dir={isRtl() ? "rtl" : undefined}
524+
>
522525
<For each={pageQuotes()}>
523526
{(quote) => (
524527
<Item
525528
quote={quote}
526529
matchedTerms={searchResults().matchedTerms}
527-
dataBalloonDirection={dataBalloonDirection()}
530+
isRtl={isRtl()}
528531
onSelect={() => applyQuote(quote.id)}
529532
onReport={() => showQuoteReportModal(quote.id)}
530533
// oxlint-disable-next-line solid/reactivity, typescript-eslint/promise-function-async -- fire-and-forget, no reactive tracking needed

frontend/src/ts/firebase.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ export async function init(callback: ReadyCallback): Promise<void> {
6969

7070
onAuthStateChanged(Auth, async (user) => {
7171
if (!ignoreAuthCallback) {
72-
await callback(true, user);
7372
setUserId(user?.uid ?? null);
73+
await callback(true, user);
7474
}
7575
});
7676
} catch (e) {
@@ -159,6 +159,7 @@ export async function signInWithPopup(
159159
googleSignUpEvent.dispatch({ signedInUser, isNewUser: true });
160160
} else {
161161
ignoreAuthCallback = false;
162+
setUserId(signedInUser.user.uid);
162163
await readyCallback?.(true, signedInUser.user);
163164
}
164165
}

0 commit comments

Comments
 (0)