Shinhati2023 commited on
Commit
be4b09c
·
verified ·
1 Parent(s): d6b706b

Update client/src/App.jsx

Browse files
Files changed (1) hide show
  1. client/src/App.jsx +83 -57
client/src/App.jsx CHANGED
@@ -1,57 +1,53 @@
1
  import React, { useState, useEffect } from 'react';
2
  import { createClient } from '@supabase/supabase-js';
3
 
4
- // --- HARDCODED CONFIG (Fixes Black Screen) ---
5
- const SUPABASE_URL = "https://whpciwshxecjvalksicw.supabase.co";
6
- // PASTE YOUR KEY BELOW (The one starting with sb_publishable... or ey...)
7
  const SUPABASE_ANON_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6IndocGNpd3NoeGVjanZhbGtzaWN3Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzAxNDQyNjYsImV4cCI6MjA4NTcyMDI2Nn0.TwWAlQCUstvGykPhaDhPAVpTyg2MV7eltG7JFvjZ-zU";
8
 
9
  const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY);
10
 
11
  function App() {
12
- // ... (Keep the rest of the code exactly the same) ...
13
-
14
  const [session, setSession] = useState(null);
15
- const [driveConnected, setDriveConnected] = useState(false);
16
  const [prompt, setPrompt] = useState("");
17
  const [generating, setGenerating] = useState(false);
 
18
 
19
  useEffect(() => {
 
20
  supabase.auth.getSession().then(({ data: { session } }) => {
21
  setSession(session);
22
- if (session) checkDrive(session.user.id);
23
  });
 
 
 
 
 
 
24
  }, []);
25
 
26
- const checkDrive = async (userId) => {
27
- const { data } = await supabase.from('drive_accounts').select('id').eq('user_id', userId).single();
28
- if (data) setDriveConnected(true);
 
29
  };
30
 
31
  const handleGenerate = async () => {
 
32
  setGenerating(true);
33
  try {
34
- if (!window.puter.auth.isSignedIn()) await window.puter.auth.signIn();
 
 
 
 
 
35
  const imgElement = await window.puter.ai.txt2img(prompt);
 
 
 
36
 
37
- const res = await fetch(imgElement.src);
38
- const blob = await res.blob();
39
-
40
- if (driveConnected) {
41
- const formData = new FormData();
42
- formData.append('image', blob);
43
- formData.append('prompt', prompt);
44
- const { data: { session } } = await supabase.auth.getSession();
45
-
46
- await fetch('/api/drive/upload', {
47
- method: 'POST',
48
- headers: { 'Authorization': `Bearer ${session.access_token}` },
49
- body: formData
50
- });
51
- alert("Saved to Google Drive!");
52
- } else {
53
- alert("Generated! (Not saved - connect Drive first)");
54
- }
55
  } catch (e) {
56
  alert("Error: " + e.message);
57
  } finally {
@@ -59,40 +55,70 @@ function App() {
59
  }
60
  };
61
 
62
- if (!session) return (
63
- <div style={{height:'100vh', display:'flex', alignItems:'center', justifyContent:'center', background:'#111', color:'white'}}>
64
- <button onClick={() => supabase.auth.signInWithOAuth({ provider: 'google' })} style={{padding:'15px', fontSize:'18px', cursor:'pointer'}}>
65
- Log in with Google
66
- </button>
67
- </div>
68
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
 
70
  return (
71
- <div style={{padding: '20px', background: '#111', color: '#fff', minHeight: '100vh', fontFamily: 'sans-serif'}}>
72
- <h1>FluxGen + Drive</h1>
73
- {!driveConnected && (
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  <button
75
- onClick={() => window.location.href=`/api/drive/connect?user_id=${session.user.id}`}
76
- style={{width:'100%', padding:'10px', background:'#d97706', color:'white', border:'none', borderRadius:'5px', cursor:'pointer', marginBottom:'20px'}}
 
 
 
 
 
 
77
  >
78
- Connect Google Drive
79
  </button>
 
 
 
 
 
 
 
80
  )}
81
-
82
- <textarea
83
- value={prompt}
84
- onChange={e => setPrompt(e.target.value)}
85
- placeholder="Describe your image..."
86
- style={{width:'100%', padding: '10px', height:'100px', borderRadius:'5px', border:'1px solid #333', background:'#222', color:'white'}}
87
- />
88
-
89
- <button
90
- onClick={handleGenerate}
91
- disabled={generating}
92
- style={{width:'100%', padding:'15px', marginTop:'20px', background: generating ? '#555' : '#7c3aed', color:'white', border:'none', borderRadius:'5px', cursor:'pointer', fontSize:'16px'}}
93
- >
94
- {generating ? "Generating..." : "Generate Image"}
95
- </button>
96
  </div>
97
  );
98
  }
 
1
  import React, { useState, useEffect } from 'react';
2
  import { createClient } from '@supabase/supabase-js';
3
 
4
+ // --- CONFIG ---
5
+ // Replace these with your actual URL and Key if they aren't loading from env
6
+ const SUPABASE_URL = "https://whpciwshxecjvalksicw.supabase.co";
7
  const SUPABASE_ANON_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6IndocGNpd3NoeGVjanZhbGtzaWN3Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzAxNDQyNjYsImV4cCI6MjA4NTcyMDI2Nn0.TwWAlQCUstvGykPhaDhPAVpTyg2MV7eltG7JFvjZ-zU";
8
 
9
  const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY);
10
 
11
  function App() {
 
 
12
  const [session, setSession] = useState(null);
 
13
  const [prompt, setPrompt] = useState("");
14
  const [generating, setGenerating] = useState(false);
15
+ const [imageSrc, setImageSrc] = useState(null);
16
 
17
  useEffect(() => {
18
+ // Check if we are already logged in
19
  supabase.auth.getSession().then(({ data: { session } }) => {
20
  setSession(session);
 
21
  });
22
+
23
+ const { data: { subscription } } = supabase.auth.onAuthStateChange((_event, session) => {
24
+ setSession(session);
25
+ });
26
+
27
+ return () => subscription.unsubscribe();
28
  }, []);
29
 
30
+ const handleLogin = async () => {
31
+ // SIMPLE ANONYMOUS LOGIN (No Google required)
32
+ const { error } = await supabase.auth.signInAnonymously();
33
+ if (error) alert("Login failed: " + error.message);
34
  };
35
 
36
  const handleGenerate = async () => {
37
+ if (!prompt) return;
38
  setGenerating(true);
39
  try {
40
+ // 1. Connect Puter (No keys needed)
41
+ if (!window.puter.auth.isSignedIn()) {
42
+ await window.puter.auth.signIn();
43
+ }
44
+
45
+ // 2. Generate Image
46
  const imgElement = await window.puter.ai.txt2img(prompt);
47
+ setImageSrc(imgElement.src); // Display immediately
48
+
49
+ // (Optional) Save metadata to Supabase here if you want
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  } catch (e) {
52
  alert("Error: " + e.message);
53
  } finally {
 
55
  }
56
  };
57
 
58
+ // --- LOGIN SCREEN ---
59
+ if (!session) {
60
+ return (
61
+ <div style={{
62
+ height: '100vh', display: 'flex', flexDirection: 'column',
63
+ alignItems: 'center', justifyContent: 'center',
64
+ background: '#111', color: 'white', fontFamily: 'sans-serif'
65
+ }}>
66
+ <h1 style={{marginBottom: '2rem'}}>FluxGen</h1>
67
+ <button
68
+ onClick={handleLogin}
69
+ style={{
70
+ padding: '15px 30px', fontSize: '18px', cursor: 'pointer',
71
+ background: '#2563eb', color: 'white', border: 'none', borderRadius: '8px'
72
+ }}
73
+ >
74
+ Start App (Guest Mode)
75
+ </button>
76
+ </div>
77
+ );
78
+ }
79
 
80
+ // --- MAIN APP SCREEN ---
81
  return (
82
+ <div style={{
83
+ padding: '20px', background: '#111', color: '#fff',
84
+ minHeight: '100vh', fontFamily: 'sans-serif', maxWidth: '600px', margin: '0 auto'
85
+ }}>
86
+ <div style={{display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '20px'}}>
87
+ <h1 style={{fontSize: '1.5rem', margin: 0}}>FluxGen</h1>
88
+ <button onClick={() => supabase.auth.signOut()} style={{background: 'transparent', border: '1px solid #555', color: '#aaa', padding: '5px 10px', borderRadius: '4px', cursor:'pointer'}}>Exit</button>
89
+ </div>
90
+
91
+ <div style={{display: 'flex', flexDirection: 'column', gap: '15px'}}>
92
+ <textarea
93
+ value={prompt}
94
+ onChange={e => setPrompt(e.target.value)}
95
+ placeholder="Describe your image... (e.g. A cyberpunk cat)"
96
+ style={{
97
+ width: '100%', padding: '15px', height: '100px', borderRadius: '8px',
98
+ border: '1px solid #333', background: '#222', color: 'white', fontSize: '16px', resize: 'none'
99
+ }}
100
+ />
101
+
102
  <button
103
+ onClick={handleGenerate}
104
+ disabled={generating}
105
+ style={{
106
+ width: '100%', padding: '15px',
107
+ background: generating ? '#555' : '#7c3aed',
108
+ color: 'white', border: 'none', borderRadius: '8px',
109
+ cursor: generating ? 'not-allowed' : 'pointer', fontSize: '16px', fontWeight: 'bold'
110
+ }}
111
  >
112
+ {generating ? "Dreaming..." : "Generate Image"}
113
  </button>
114
+ </div>
115
+
116
+ {imageSrc && (
117
+ <div style={{marginTop: '30px', textAlign: 'center'}}>
118
+ <img src={imageSrc} alt="Generated" style={{width: '100%', borderRadius: '8px', boxShadow: '0 4px 20px rgba(0,0,0,0.5)'}} />
119
+ <p style={{color: '#888', marginTop: '10px', fontSize: '14px'}}>Long-press image to save</p>
120
+ </div>
121
  )}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  </div>
123
  );
124
  }