Skip to content

Commit

Permalink
feat: only render the Onboarding component if aiEnabled is set
Browse files Browse the repository at this point in the history
  • Loading branch information
1egoman committed Oct 24, 2024
1 parent 316afc5 commit 6c090a6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 53 deletions.
8 changes: 3 additions & 5 deletions packages/web/src/components/onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import React from 'react';
import { LayoutGridIcon, FileTextIcon } from 'lucide-react';
import { AiSettings } from '@/routes/settings';

type OnboardingModalProps = {
onComplete: () => void;
};
type OnboardingModalProps = {};

const OnboardingModal: React.FunctionComponent<OnboardingModalProps> = ({ onComplete }) => {
const OnboardingModal: React.FunctionComponent<OnboardingModalProps> = () => {
return (
<div className="flex flex-col gap-6">
<h2 className="text-3xl font-medium">Welcome to Srcbook!</h2>
Expand Down Expand Up @@ -40,7 +38,7 @@ const OnboardingModal: React.FunctionComponent<OnboardingModalProps> = ({ onComp
To get started, select your AI provider and enter your API key:
</label>

<AiSettings saveButtonLabel="Continue" onConfirm={onComplete} />
<AiSettings saveButtonLabel="Continue" />
</div>
</div>
);
Expand Down
31 changes: 3 additions & 28 deletions packages/web/src/routes/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,7 @@ export default function Home() {
const [appToDelete, setAppToDelete] = useState<AppType | null>(null);
const [showCreateAppModal, setShowCreateAppModal] = useState(false);

const { aiProvider, openaiKey, anthropicKey } = useSettings();
const [showOnboarding, setShowOnboarding] = useState(false);
const [isLoading, setIsLoading] = useState(true);

useEffect(() => {
const checkApiKey = () => {
const hasSeenOnboarding = localStorage.getItem('hasSeenOnboarding') === 'true';
const hasApiKey = aiProvider === 'openai' ? !!openaiKey : !!anthropicKey;

if (!hasSeenOnboarding || !hasApiKey) {
setShowOnboarding(true);
}
setIsLoading(false);
};

checkApiKey();
}, [aiProvider, openaiKey, anthropicKey]);

const handleOnboardingComplete = () => {
setShowOnboarding(false);
localStorage.setItem('hasSeenOnboarding', 'true');
};
const { aiEnabled } = useSettings();

function onDeleteSrcbook(srcbook: SessionType) {
setSrcbookToDelete(srcbook);
Expand All @@ -116,12 +95,8 @@ export default function Home() {
openSrcbook(result.dir);
}

if (isLoading) {
return <div>Loading...</div>;
}

if (showOnboarding) {
return <Onboarding onComplete={handleOnboardingComplete} />;
if (!aiEnabled) {
return <Onboarding />;
}

return (
Expand Down
24 changes: 4 additions & 20 deletions packages/web/src/routes/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,9 @@ const TestAiButton = () => {

type AiSettingsProps = {
saveButtonLabel?: string;
onConfirm?: () => void;
};

export function AiSettings({ saveButtonLabel, onConfirm }: AiSettingsProps) {
export function AiSettings({ saveButtonLabel }: AiSettingsProps) {
const {
aiProvider,
aiModel,
Expand Down Expand Up @@ -296,12 +295,7 @@ export function AiSettings({ saveButtonLabel, onConfirm }: AiSettingsProps) {
/>
<Button
className="px-5"
onClick={async () => {
await updateConfigContext({ openaiKey, aiModel: model });
if (onConfirm) {
onConfirm();
}
}}
onClick={() => updateConfigContext({ openaiKey, aiModel: model })}
disabled={!openaiKeySaveEnabled}
>
{saveButtonLabel ?? 'Save'}
Expand All @@ -320,12 +314,7 @@ export function AiSettings({ saveButtonLabel, onConfirm }: AiSettingsProps) {
/>
<Button
className="px-5"
onClick={async () => {
await updateConfigContext({ anthropicKey, aiModel: model });
if (onConfirm) {
onConfirm();
}
}}
onClick={() => updateConfigContext({ anthropicKey, aiModel: model })}
disabled={!anthropicKeySaveEnabled}
>
{saveButtonLabel ?? 'Save'}
Expand All @@ -348,12 +337,7 @@ export function AiSettings({ saveButtonLabel, onConfirm }: AiSettingsProps) {
/>
<Button
className="px-5"
onClick={async () => {
await updateConfigContext({ aiBaseUrl: baseUrl, aiModel: model });
if (onConfirm) {
onConfirm();
}
}}
onClick={() => updateConfigContext({ aiBaseUrl: baseUrl, aiModel: model })}
disabled={!customModelSaveEnabled}
>
{saveButtonLabel ?? 'Save'}
Expand Down

0 comments on commit 6c090a6

Please sign in to comment.