mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Add login/signup call to action below index prompt. Re-use index prompt if user began typing before logging in.
This commit is contained in:
1 parent
f8ff2583aa
commit
0f17aa8c7c
4 files changed
+91
-43
No files matched your search
@@ -13,6 +13,7 @@ interface OnboardingDialogProps {
|
||||
currentStep: number;
|
||||
onNextStep: () => void;
|
||||
onPreviousStep: () => void;
|
||||
initialPrompt?: string;
|
||||
}
|
||||
|
||||
const STEPS = [
|
||||
@@ -28,7 +29,8 @@ export function OnboardingDialog({
|
||||
onComplete,
|
||||
currentStep: propCurrentStep,
|
||||
onNextStep,
|
||||
onPreviousStep
|
||||
onPreviousStep,
|
||||
initialPrompt = ''
|
||||
}: OnboardingDialogProps) {
|
||||
const [localStep, setLocalStep] = useState(propCurrentStep);
|
||||
|
||||
@@ -88,6 +90,7 @@ export function OnboardingDialog({
|
||||
onPrevious={handlePrevious}
|
||||
onComplete={handleComplete}
|
||||
onProjectCreated={onProjectCreated}
|
||||
initialPrompt={initialPrompt}
|
||||
/>
|
||||
);
|
||||
default:
|
||||
|
||||
@@ -11,10 +11,11 @@ interface ProjectStepProps {
|
||||
onPrevious: () => void;
|
||||
onComplete: () => void;
|
||||
onProjectCreated?: (projectId: string) => void;
|
||||
initialPrompt?: string;
|
||||
}
|
||||
|
||||
export function ProjectStep({ onPrevious, onComplete, onProjectCreated }: ProjectStepProps) {
|
||||
const [prompt, setPrompt] = useState('');
|
||||
export function ProjectStep({ onPrevious, onComplete, onProjectCreated, initialPrompt = '' }: ProjectStepProps) {
|
||||
const [prompt, setPrompt] = useState(initialPrompt);
|
||||
const [isCreating, setIsCreating] = useState(false);
|
||||
const projectsManager = useProjectsManager();
|
||||
const navigate = useNavigate();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useLocalStorage } from './useLocalStorage';
|
||||
import { useCurrentUser } from './useCurrentUser';
|
||||
|
||||
export function useOnboarding() {
|
||||
const [hasCompletedOnboarding, setHasCompletedOnboarding] = useLocalStorage(
|
||||
@@ -8,13 +9,14 @@ export function useOnboarding() {
|
||||
);
|
||||
const [currentStep, setCurrentStep] = useState(0);
|
||||
const [isOnboardingOpen, setIsOnboardingOpen] = useState(false);
|
||||
const { user } = useCurrentUser();
|
||||
|
||||
// Check if onboarding should be shown on first load
|
||||
useEffect(() => {
|
||||
if (!hasCompletedOnboarding) {
|
||||
if (!hasCompletedOnboarding && user) {
|
||||
setIsOnboardingOpen(true);
|
||||
}
|
||||
}, [hasCompletedOnboarding]);
|
||||
}, [hasCompletedOnboarding, user]);
|
||||
|
||||
const handleNextStep = () => {
|
||||
setCurrentStep(prev => Math.min(prev + 1, 2));
|
||||
|
||||
+80
-38
@@ -3,8 +3,11 @@ import { useNavigate } from 'react-router-dom';
|
||||
import { type Project } from '@/lib/ProjectsManager';
|
||||
import { useProjectsManager } from '@/hooks/useProjectsManager';
|
||||
import { useOnboarding } from '@/hooks/useOnboarding';
|
||||
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||
import { useLocalStorage } from '@/hooks/useLocalStorage';
|
||||
import { ProjectSidebar } from '@/components/ProjectSidebar';
|
||||
import { OnboardingDialog } from '@/components/onboarding';
|
||||
import { LoginArea } from '@/components/auth/LoginArea';
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
@@ -20,6 +23,7 @@ export default function Index() {
|
||||
const [projects, setProjects] = useState<Project[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [isCreating, setIsCreating] = useState(false);
|
||||
const [storedPrompt, setStoredPrompt] = useLocalStorage('shakespeare-draft-prompt', '');
|
||||
const navigate = useNavigate();
|
||||
const projectsManager = useProjectsManager();
|
||||
const isMobile = useIsMobile();
|
||||
@@ -32,6 +36,7 @@ export default function Index() {
|
||||
handlePreviousStep,
|
||||
handleCompleteOnboarding,
|
||||
} = useOnboarding();
|
||||
const { user } = useCurrentUser();
|
||||
const [isSidebarVisible, setIsSidebarVisible] = useState(() => {
|
||||
// Check if we're on mobile immediately to set correct initial state
|
||||
if (typeof window !== 'undefined') {
|
||||
@@ -61,9 +66,26 @@ export default function Index() {
|
||||
loadProjects();
|
||||
}, [loadProjects]);
|
||||
|
||||
// Restore prompt from storage when user logs in
|
||||
useEffect(() => {
|
||||
if (user && storedPrompt && !prompt) {
|
||||
setPrompt(storedPrompt);
|
||||
}
|
||||
}, [user, storedPrompt, prompt]);
|
||||
|
||||
// Sync prompt with local storage
|
||||
const handlePromptChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||
const newPrompt = e.target.value;
|
||||
setPrompt(newPrompt);
|
||||
setStoredPrompt(newPrompt);
|
||||
};
|
||||
|
||||
const handleCreateProject = async () => {
|
||||
if (!prompt.trim()) return;
|
||||
|
||||
// Clear stored prompt when creating project
|
||||
setStoredPrompt('');
|
||||
|
||||
setIsCreating(true);
|
||||
try {
|
||||
const project = await projectsManager.createProject(prompt.trim());
|
||||
@@ -172,28 +194,37 @@ export default function Index() {
|
||||
<Textarea
|
||||
placeholder="e.g., Create a farming equipment marketplace for local farmers to buy and sell tractors, tools, and supplies..."
|
||||
value={prompt}
|
||||
onChange={(e) => setPrompt(e.target.value)}
|
||||
onChange={handlePromptChange}
|
||||
className="min-h-[120px] touch-action-manipulation overscroll-contain text-base leading-relaxed"
|
||||
disabled={isCreating}
|
||||
/>
|
||||
<Button
|
||||
onClick={handleCreateProject}
|
||||
disabled={!prompt.trim() || isCreating}
|
||||
className="w-full focus-ring bg-gradient-to-r from-primary to-primary/90 hover:from-primary/90 hover:to-primary/80 shadow-lg"
|
||||
size="lg"
|
||||
>
|
||||
{isCreating ? (
|
||||
<>
|
||||
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white mr-2"></div>
|
||||
Creating Project...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
Create Project
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
{user ? (
|
||||
<Button
|
||||
onClick={handleCreateProject}
|
||||
disabled={!prompt.trim() || isCreating}
|
||||
className="w-full focus-ring bg-gradient-to-r from-primary to-primary/90 hover:from-primary/90 hover:to-primary/80 shadow-lg"
|
||||
size="lg"
|
||||
>
|
||||
{isCreating ? (
|
||||
<>
|
||||
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white mr-2"></div>
|
||||
Creating Project...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
Create Project
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
) : (
|
||||
<div className="text-center space-y-4">
|
||||
<p className="text-muted-foreground">
|
||||
Log in or sign up to create your first project
|
||||
</p>
|
||||
<LoginArea className="max-w-xs mx-auto" />
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
@@ -267,9 +298,11 @@ export default function Index() {
|
||||
onNextStep={handleNextStep}
|
||||
onPreviousStep={handlePreviousStep}
|
||||
onComplete={handleCompleteOnboarding}
|
||||
initialPrompt={storedPrompt}
|
||||
onProjectCreated={(projectId) => {
|
||||
// Handle project creation during onboarding
|
||||
console.log('Project created during onboarding:', projectId);
|
||||
setStoredPrompt(''); // Clear stored prompt after project creation
|
||||
}}
|
||||
/>
|
||||
<div className="h-screen flex bg-background">
|
||||
@@ -339,28 +372,37 @@ export default function Index() {
|
||||
<Textarea
|
||||
placeholder="e.g., Create a farming equipment marketplace for local farmers to buy and sell tractors, tools, and supplies..."
|
||||
value={prompt}
|
||||
onChange={(e) => setPrompt(e.target.value)}
|
||||
onChange={handlePromptChange}
|
||||
className="min-h-[120px] touch-action-manipulation overscroll-contain text-base leading-relaxed"
|
||||
disabled={isCreating}
|
||||
/>
|
||||
<Button
|
||||
onClick={handleCreateProject}
|
||||
disabled={!prompt.trim() || isCreating}
|
||||
className="w-full focus-ring bg-gradient-to-r from-primary to-primary/90 hover:from-primary/90 hover:to-primary/80 shadow-lg"
|
||||
size="lg"
|
||||
>
|
||||
{isCreating ? (
|
||||
<>
|
||||
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white mr-2"></div>
|
||||
Creating Project...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
Create Project
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
{user ? (
|
||||
<Button
|
||||
onClick={handleCreateProject}
|
||||
disabled={!prompt.trim() || isCreating}
|
||||
className="w-full focus-ring bg-gradient-to-r from-primary to-primary/90 hover:from-primary/90 hover:to-primary/80 shadow-lg"
|
||||
size="lg"
|
||||
>
|
||||
{isCreating ? (
|
||||
<>
|
||||
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white mr-2"></div>
|
||||
Creating Project...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
Create Project
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
) : (
|
||||
<div className="text-center space-y-4">
|
||||
<p className="text-muted-foreground">
|
||||
Log in or sign up to create your first project
|
||||
</p>
|
||||
<LoginArea className="max-w-xs mx-auto" />
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user