Skip to content

Commit

Permalink
removed window scoped vars
Browse files Browse the repository at this point in the history
  • Loading branch information
jgentes committed Dec 16, 2023
1 parent 1ab4bcb commit 48d7445
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
4 changes: 2 additions & 2 deletions app/api/db/appState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const {
stemsAnalyzing: Track['id'][]
syncTimer: ReturnType<typeof requestAnimationFrame> | undefined
audioContext?: AudioContext
loggedIn: boolean
loggedIn: string // email address
}>({
search: '',
selected: [],
Expand All @@ -78,7 +78,7 @@ const {
analyzing: [],
stemsAnalyzing: [],
syncTimer: undefined,
loggedIn: false
loggedIn: ''
})

// ModalState is a generic handler for various modals, usually when doing something significant like deleting tracks
Expand Down
16 changes: 8 additions & 8 deletions app/api/fileHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ const getStemsDirHandle = async (): Promise<
'granted'
) {
return stemsDirHandle
} else {
// no permission, so ask for it
if (
(await stemsDirHandle.requestPermission({ mode: 'readwrite' })) ===
'granted'
) {
return stemsDirHandle
}
}

// no permission, so ask for it
if (
(await stemsDirHandle.requestPermission({ mode: 'readwrite' })) ===
'granted'
) {
return stemsDirHandle
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/components/layout/LoginButton.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const LoginButton = () => {
sx={{ px: 1 }}
variant="outlined"
color="primary"
aria-label={buttonText}
title={loggedIn || buttonText}
onClick={async () => {
loggedIn ? await supabase.auth.signOut() : setOpenAuth(true)
}}
Expand Down
21 changes: 8 additions & 13 deletions app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,24 +121,26 @@ const ThemeLoader = ({ error }: { error?: string }) => {

// create a single instance of the supabase client
const supabaseClient = createBrowserClient(
window.ENV.SUPABASE_URL,
window.ENV.SUPABASE_ANON_KEY
data.ENV.SUPABASE_URL,
data.ENV.SUPABASE_ANON_KEY
)
setSupabase(supabaseClient)

// update login status in appState upon auth state change
supabaseClient.auth.onAuthStateChange((event, session) => {
const email = session?.user?.email
if (event === 'SIGNED_IN') {
setAppState.loggedIn(true)
posthog.identify(session?.user?.id, { email: session?.user?.email })
Sentry.setUser({ id: session?.user?.id, email: session?.user?.email })
setAppState.loggedIn(email)
posthog.identify(session?.user?.id, { email })
Sentry.setUser({ id: session?.user?.id, email })
posthog.capture('user logged in')
}
if (event === 'SIGNED_OUT') {
setAppState.loggedIn(false)
setAppState.loggedIn('')
posthog.capture('user logged out')
Sentry.setUser(null)
posthog.reset()
notify({ detail: { message: 'Logged out', color: 'success' } })
}
})

Expand Down Expand Up @@ -180,7 +182,6 @@ const ThemeLoader = ({ error }: { error?: string }) => {
}

const App = ({ error }: { error?: string }) => {
const data = error ? {} : useLoaderData<typeof loader>()
const location = useLocation()

// biome-ignore lint/correctness/useExhaustiveDependencies: location is used to trigger new pageview capture
Expand All @@ -190,12 +191,6 @@ const App = ({ error }: { error?: string }) => {

return (
<HtmlDoc>
<script
// biome-ignore lint/security/noDangerouslySetInnerHtml: see https://remix.run/docs/en/main/guides/envvars
dangerouslySetInnerHTML={{
__html: `window.ENV = ${JSON.stringify(data.ENV)}`
}}
/>
<ThemeLoader error={error} />
<Scripts />
</HtmlDoc>
Expand Down

0 comments on commit 48d7445

Please sign in to comment.