Skip to content

Commit 8cd4591

Browse files
committed
updated solution page
1 parent 983c379 commit 8cd4591

4 files changed

Lines changed: 127 additions & 17 deletions

File tree

electron/main.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ async function createWindow(): Promise<void> {
298298
// Configure window behavior
299299
state.mainWindow.webContents.setZoomFactor(1)
300300
if (isDev) {
301-
// state.mainWindow.webContents.openDevTools()
301+
state.mainWindow.webContents.openDevTools()
302302
}
303303
state.mainWindow.webContents.setWindowOpenHandler(({ url }) => {
304304
console.log("Attempting to open URL:", url)
@@ -471,10 +471,21 @@ function setWindowDimensions(width: number, height: number): void {
471471
// Environment setup
472472
function loadEnvVariables() {
473473
if (isDev) {
474+
console.log("Loading env variables from:", path.join(process.cwd(), ".env"))
474475
dotenv.config({ path: path.join(process.cwd(), ".env") })
475476
} else {
477+
console.log(
478+
"Loading env variables from:",
479+
path.join(process.resourcesPath, ".env")
480+
)
476481
dotenv.config({ path: path.join(process.resourcesPath, ".env") })
477482
}
483+
console.log("Loaded environment variables:", {
484+
VITE_SUPABASE_URL: process.env.VITE_SUPABASE_URL ? "exists" : "missing",
485+
VITE_SUPABASE_ANON_KEY: process.env.VITE_SUPABASE_ANON_KEY
486+
? "exists"
487+
: "missing"
488+
})
478489
}
479490

480491
// Initialize application

src/_pages/Solutions.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ProblemStatementData } from "../types/solutions"
1010
import SolutionCommands from "../components/Solutions/SolutionCommands"
1111
import Debug from "./Debug"
1212
import { useToast } from "../contexts/toast"
13+
import { COMMAND_KEY } from "../utils/platform"
1314

1415
export const ContentSection = ({
1516
title,
@@ -483,7 +484,7 @@ const Solutions: React.FC<SolutionsProps> = ({
483484
{solutionData && (
484485
<>
485486
<ContentSection
486-
title="My Thoughts"
487+
title={`My Thoughts (${COMMAND_KEY} + Arrow keys to scroll)`}
487488
content={
488489
thoughtsData && (
489490
<div className="space-y-3">

src/components/Solutions/SolutionCommands.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useToast } from "../../contexts/toast"
33
import { Screenshot } from "../../types/screenshots"
44
import { supabase } from "../../lib/supabase"
55
import { LanguageSelector } from "../shared/LanguageSelector"
6-
import { COMMAND_KEY } from '../../utils/platform'
6+
import { COMMAND_KEY } from "../../utils/platform"
77

88
export interface SolutionCommandsProps {
99
onTooltipVisibilityChange: (visible: boolean, height: number) => void
@@ -41,19 +41,6 @@ const SolutionCommands: React.FC<SolutionCommandsProps> = ({
4141
const tooltipRef = useRef<HTMLDivElement>(null)
4242
const { showToast } = useToast()
4343

44-
const handleResetApiKey = async () => {
45-
try {
46-
const result = await window.electronAPI.clearStore()
47-
if (result.success) {
48-
window.location.reload()
49-
} else {
50-
showToast("Error", "Failed to reset API key", "error")
51-
}
52-
} catch (error) {
53-
showToast("Error", "Failed to reset API key", "error")
54-
}
55-
}
56-
5744
useEffect(() => {
5845
if (onTooltipVisibilityChange) {
5946
let tooltipHeight = 0

src/lib/supabase.ts

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,122 @@
11
import { createClient } from "@supabase/supabase-js"
22

3+
console.log("Supabase URL:", import.meta.env.VITE_SUPABASE_URL)
4+
console.log(
5+
"Supabase Anon Key:",
6+
import.meta.env.VITE_SUPABASE_ANON_KEY?.slice(0, 10) + "..."
7+
)
8+
39
const supabaseUrl = import.meta.env.VITE_SUPABASE_URL
410
const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY
511

12+
if (!supabaseUrl || !supabaseAnonKey) {
13+
throw new Error("Missing Supabase environment variables")
14+
}
15+
616
export const supabase = createClient(supabaseUrl, supabaseAnonKey, {
717
auth: {
818
flowType: "pkce",
9-
detectSessionInUrl: true
19+
detectSessionInUrl: true,
20+
persistSession: true,
21+
autoRefreshToken: true,
22+
debug: true,
23+
storage: {
24+
getItem: (key) => {
25+
const item = localStorage.getItem(key)
26+
console.log("Auth storage - Getting key:", key, "Value exists:", !!item)
27+
return item
28+
},
29+
setItem: (key, value) => {
30+
console.log("Auth storage - Setting key:", key)
31+
localStorage.setItem(key, value)
32+
},
33+
removeItem: (key) => {
34+
console.log("Auth storage - Removing key:", key)
35+
localStorage.removeItem(key)
36+
}
37+
}
38+
},
39+
realtime: {
40+
params: {
41+
eventsPerSecond: 10
42+
},
43+
headers: {
44+
apikey: supabaseAnonKey
45+
}
46+
}
47+
})
48+
49+
export const signInWithGoogle = async () => {
50+
try {
51+
console.log("Initiating Google sign in...")
52+
const { data, error } = await supabase.auth.signInWithOAuth({
53+
provider: "google",
54+
options: {
55+
redirectTo: window.location.origin
56+
}
57+
})
58+
59+
if (error) {
60+
console.error("Google sign in error:", error)
61+
throw error
62+
}
63+
64+
console.log("Google sign in response:", data)
65+
return data
66+
} catch (error) {
67+
console.error("Unexpected error during Google sign in:", error)
68+
throw error
69+
}
70+
}
71+
72+
let channel: ReturnType<typeof supabase.channel> | null = null
73+
74+
// Monitor auth state changes and manage realtime connection
75+
supabase.auth.onAuthStateChange((event, session) => {
76+
console.log("Auth state changed:", event, session?.user?.id)
77+
console.log("Full session data:", session)
78+
79+
if (event === "SIGNED_IN" && session) {
80+
// Only establish realtime connection after successful sign in
81+
console.log("Establishing realtime connection...")
82+
83+
// Clean up existing channel if any
84+
if (channel) {
85+
channel.unsubscribe()
86+
}
87+
88+
channel = supabase.channel("system", {
89+
config: {
90+
presence: {
91+
key: session.user.id
92+
}
93+
}
94+
})
95+
96+
channel
97+
.on("system", { event: "*" }, (payload) => {
98+
console.log("System event:", payload)
99+
})
100+
.subscribe((status) => {
101+
console.log("Realtime subscription status:", status)
102+
if (status === "SUBSCRIBED") {
103+
console.log("Successfully connected to realtime system")
104+
}
105+
if (status === "CHANNEL_ERROR") {
106+
console.error("Realtime connection error - will retry in 5s")
107+
setTimeout(() => {
108+
channel?.subscribe()
109+
}, 5000)
110+
}
111+
})
112+
}
113+
114+
if (event === "SIGNED_OUT") {
115+
// Clean up realtime connection on sign out
116+
if (channel) {
117+
console.log("Cleaning up realtime connection")
118+
channel.unsubscribe()
119+
channel = null
120+
}
10121
}
11122
})

0 commit comments

Comments
 (0)