Skip to content

Commit eddf560

Browse files
Merge pull request #607 from oTToDev-CE/ui/add-tab-connections
feat: Connections Tabs
2 parents a6756f8 + 182e1d2 commit eddf560

File tree

3 files changed

+65
-24
lines changed

3 files changed

+65
-24
lines changed

app/components/settings/SettingsWindow.tsx

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface SettingsProps {
1818
onClose: () => void;
1919
}
2020

21-
type TabType = 'chat-history' | 'providers' | 'features' | 'debug';
21+
type TabType = 'chat-history' | 'providers' | 'features' | 'debug' | 'connection';
2222

2323
// Providers that support base URL configuration
2424
const URL_CONFIGURABLE_PROVIDERS = ['Ollama', 'LMStudio', 'OpenAILike'];
@@ -32,13 +32,12 @@ export const SettingsWindow = ({ open, onClose }: SettingsProps) => {
3232
});
3333
const [searchTerm, setSearchTerm] = useState('');
3434
const [isDeleting, setIsDeleting] = useState(false);
35-
const [isJustSayEnabled, setIsJustSayEnabled] = useState(false);
35+
const [githubUsername, setGithubUsername] = useState(Cookies.get('githubUsername') || '');
36+
const [githubToken, setGithubToken] = useState(Cookies.get('githubToken') || '');
3637
const [isLocalModelsEnabled, setIsLocalModelsEnabled] = useState(() => {
3738
const savedLocalModelsState = Cookies.get('isLocalModelsEnabled');
3839
return savedLocalModelsState === 'true';
3940
});
40-
const [isExperimentalFeature1Enabled, setIsExperimentalFeature1Enabled] = useState(false);
41-
const [isExperimentalFeature2Enabled, setIsExperimentalFeature2Enabled] = useState(false);
4241

4342
// Load base URLs from cookies
4443
const [baseUrls, setBaseUrls] = useState(() => {
@@ -77,6 +76,7 @@ export const SettingsWindow = ({ open, onClose }: SettingsProps) => {
7776
{ id: 'chat-history', label: 'Chat History', icon: 'i-ph:book' },
7877
{ id: 'providers', label: 'Providers', icon: 'i-ph:key' },
7978
{ id: 'features', label: 'Features', icon: 'i-ph:star' },
79+
{ id: 'connection', label: 'Connection', icon: 'i-ph:link' },
8080
...(isDebugEnabled ? [{ id: 'debug' as TabType, label: 'Debug Tab', icon: 'i-ph:bug' }] : []),
8181
];
8282

@@ -205,7 +205,12 @@ export const SettingsWindow = ({ open, onClose }: SettingsProps) => {
205205

206206
const versionHash = commit.commit; // Get the version hash from commit.json
207207

208-
// Update the toggle handlers to save to cookies
208+
const handleSaveConnection = () => {
209+
Cookies.set('githubUsername', githubUsername);
210+
Cookies.set('githubToken', githubToken);
211+
toast.success('GitHub credentials saved successfully!');
212+
};
213+
209214
const handleToggleDebug = (enabled: boolean) => {
210215
setIsDebugEnabled(enabled);
211216
Cookies.set('isDebugEnabled', String(enabled));
@@ -429,6 +434,39 @@ export const SettingsWindow = ({ open, onClose }: SettingsProps) => {
429434
<p className="text-bolt-elements-textSecondary">Version Hash: {versionHash}</p>
430435
</div>
431436
)}
437+
{activeTab === 'connection' && (
438+
<div className="p-4 mb-4 border border-bolt-elements-borderColor rounded-lg bg-bolt-elements-background-depth-3">
439+
<h3 className="text-lg font-medium text-bolt-elements-textPrimary mb-4">GitHub Connection</h3>
440+
<div className="flex mb-4">
441+
<div className="flex-1 mr-2">
442+
<label className="block text-sm text-bolt-elements-textSecondary mb-1">GitHub Username:</label>
443+
<input
444+
type="text"
445+
value={githubUsername}
446+
onChange={(e) => setGithubUsername(e.target.value)}
447+
className="w-full bg-white dark:bg-bolt-elements-background-depth-4 relative px-2 py-1.5 rounded-md focus:outline-none placeholder-bolt-elements-textTertiary text-bolt-elements-textPrimary dark:text-bolt-elements-textPrimary border border-bolt-elements-borderColor"
448+
/>
449+
</div>
450+
<div className="flex-1">
451+
<label className="block text-sm text-bolt-elements-textSecondary mb-1">Personal Access Token:</label>
452+
<input
453+
type="password"
454+
value={githubToken}
455+
onChange={(e) => setGithubToken(e.target.value)}
456+
className="w-full bg-white dark:bg-bolt-elements-background-depth-4 relative px-2 py-1.5 rounded-md focus:outline-none placeholder-bolt-elements-textTertiary text-bolt-elements-textPrimary dark:text-bolt-elements-textPrimary border border-bolt-elements-borderColor"
457+
/>
458+
</div>
459+
</div>
460+
<div className="flex mb-4">
461+
<button
462+
onClick={handleSaveConnection}
463+
className="bg-bolt-elements-button-primary-background rounded-lg px-4 py-2 mr-2 transition-colors duration-200 hover:bg-bolt-elements-button-primary-backgroundHover text-bolt-elements-button-primary-text"
464+
>
465+
Save Connection
466+
</button>
467+
</div>
468+
</div>
469+
)}
432470
</div>
433471
</div>
434472
</div>

app/components/workbench/Workbench.client.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { renderLogger } from '~/utils/logger';
1717
import { EditorPanel } from './EditorPanel';
1818
import { Preview } from './Preview';
1919
import useViewport from '~/lib/hooks';
20+
import Cookies from 'js-cookie';
2021

2122
interface WorkspaceProps {
2223
chatStarted?: boolean;
@@ -180,21 +181,22 @@ export const Workbench = memo(({ chatStarted, isStreaming }: WorkspaceProps) =>
180181
return;
181182
}
182183

183-
const githubUsername = prompt('Please enter your GitHub username:');
184+
const githubUsername = Cookies.get('githubUsername');
185+
const githubToken = Cookies.get('githubToken');
184186

185-
if (!githubUsername) {
186-
alert('GitHub username is required. Push to GitHub cancelled.');
187-
return;
188-
}
187+
if (!githubUsername || !githubToken) {
188+
const usernameInput = prompt('Please enter your GitHub username:');
189+
const tokenInput = prompt('Please enter your GitHub personal access token:');
189190

190-
const githubToken = prompt('Please enter your GitHub personal access token:');
191+
if (!usernameInput || !tokenInput) {
192+
alert('GitHub username and token are required. Push to GitHub cancelled.');
193+
return;
194+
}
191195

192-
if (!githubToken) {
193-
alert('GitHub token is required. Push to GitHub cancelled.');
194-
return;
196+
workbenchStore.pushToGitHub(repoName, usernameInput, tokenInput);
197+
} else {
198+
workbenchStore.pushToGitHub(repoName, githubUsername, githubToken);
195199
}
196-
197-
workbenchStore.pushToGitHub(repoName, githubUsername, githubToken);
198200
}}
199201
>
200202
<div className="i-ph:github-logo" />

app/lib/stores/workbench.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { Octokit, type RestEndpointMethodTypes } from '@octokit/rest';
1515
import * as nodePath from 'node:path';
1616
import { extractRelativePath } from '~/utils/diff';
1717
import { description } from '~/lib/persistence';
18+
import Cookies from 'js-cookie';
1819

1920
export interface ArtifactState {
2021
id: string;
@@ -396,15 +397,14 @@ export class WorkbenchStore {
396397
return syncedFiles;
397398
}
398399

399-
async pushToGitHub(repoName: string, githubUsername: string, ghToken: string) {
400+
async pushToGitHub(repoName: string, githubUsername?: string, ghToken?: string) {
400401
try {
401-
// Get the GitHub auth token from environment variables
402-
const githubToken = ghToken;
402+
// Use cookies if username and token are not provided
403+
const githubToken = ghToken || Cookies.get('githubToken');
404+
const owner = githubUsername || Cookies.get('githubUsername');
403405

404-
const owner = githubUsername;
405-
406-
if (!githubToken) {
407-
throw new Error('GitHub token is not set in environment variables');
406+
if (!githubToken || !owner) {
407+
throw new Error('GitHub token or username is not set in cookies or provided.');
408408
}
409409

410410
// Initialize Octokit with the auth token
@@ -501,7 +501,8 @@ export class WorkbenchStore {
501501

502502
alert(`Repository created and code pushed: ${repo.html_url}`);
503503
} catch (error) {
504-
console.error('Error pushing to GitHub:', error instanceof Error ? error.message : String(error));
504+
console.error('Error pushing to GitHub:', error);
505+
throw error; // Rethrow the error for further handling
505506
}
506507
}
507508
}

0 commit comments

Comments
 (0)