Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 107 additions & 79 deletions components/home-page-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } f
import { Button } from '@/components/ui/button'
import { redirectToSignIn } from '@/lib/session/redirect-to-sign-in'
import { GitHubIcon } from '@/components/icons/github-icon'
import { getEnabledAuthProviders } from '@/lib/auth/providers'
import { useSetAtom } from 'jotai'
import { taskPromptAtom } from '@/lib/atoms/task'

interface HomePageContentProps {
initialSelectedOwner?: string
Expand Down Expand Up @@ -43,6 +46,10 @@ export function HomePageContent({
const router = useRouter()
const searchParams = useSearchParams()
const { refreshTasks, addTaskOptimistically } = useTasks()
const setTaskPrompt = useSetAtom(taskPromptAtom)

// Check which auth providers are enabled
const { github: hasGitHub, vercel: hasVercel } = getEnabledAuthProviders()

// Show toast if GitHub was connected (user was already logged in)
useEffect(() => {
Expand Down Expand Up @@ -86,6 +93,17 @@ export function HomePageContent({
return
}

// Check if user has selected a repository
if (!data.repoUrl) {
toast.error('Please select a repository', {
description: 'Choose a GitHub repository to work with from the header.',
})
return
}

// Clear the saved prompt since we're actually submitting it now
setTaskPrompt('')

setIsSubmitting(true)

// Add task optimistically to sidebar immediately
Expand Down Expand Up @@ -165,89 +183,99 @@ export function HomePageContent({
<DialogContent className="sm:max-w-md">
<DialogHeader>
<DialogTitle>Sign in to continue</DialogTitle>
<DialogDescription>You need to sign in to create tasks. Choose how you want to sign in.</DialogDescription>
<DialogDescription>
{hasGitHub && hasVercel
? 'You need to sign in to create tasks. Choose how you want to sign in.'
: hasVercel
? 'You need to sign in with Vercel to create tasks.'
: 'You need to sign in with GitHub to create tasks.'}
</DialogDescription>
</DialogHeader>

<div className="flex flex-col gap-3 py-4">
<Button
onClick={handleVercelSignIn}
disabled={loadingVercel || loadingGitHub}
variant="outline"
size="lg"
className="w-full"
>
{loadingVercel ? (
<>
<svg
className="animate-spin -ml-1 mr-2 h-4 w-4"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
>
<circle
className="opacity-25"
cx="12"
cy="12"
r="10"
stroke="currentColor"
strokeWidth="4"
></circle>
<path
className="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
></path>
</svg>
Loading...
</>
) : (
<>
<svg viewBox="0 0 76 65" className="h-3 w-3 mr-2" fill="currentColor">
<path d="M37.5274 0L75.0548 65H0L37.5274 0Z" />
</svg>
Sign in with Vercel
</>
)}
</Button>
{hasVercel && (
<Button
onClick={handleVercelSignIn}
disabled={loadingVercel || loadingGitHub}
variant="outline"
size="lg"
className="w-full"
>
{loadingVercel ? (
<>
<svg
className="animate-spin -ml-1 mr-2 h-4 w-4"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
>
<circle
className="opacity-25"
cx="12"
cy="12"
r="10"
stroke="currentColor"
strokeWidth="4"
></circle>
<path
className="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
></path>
</svg>
Loading...
</>
) : (
<>
<svg viewBox="0 0 76 65" className="h-3 w-3 mr-2" fill="currentColor">
<path d="M37.5274 0L75.0548 65H0L37.5274 0Z" />
</svg>
Sign in with Vercel
</>
)}
</Button>
)}

<Button
onClick={handleGitHubSignIn}
disabled={loadingVercel || loadingGitHub}
variant="outline"
size="lg"
className="w-full"
>
{loadingGitHub ? (
<>
<svg
className="animate-spin -ml-1 mr-2 h-4 w-4"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
>
<circle
className="opacity-25"
cx="12"
cy="12"
r="10"
stroke="currentColor"
strokeWidth="4"
></circle>
<path
className="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
></path>
</svg>
Loading...
</>
) : (
<>
<GitHubIcon className="h-4 w-4 mr-2" />
Sign in with GitHub
</>
)}
</Button>
{hasGitHub && (
<Button
onClick={handleGitHubSignIn}
disabled={loadingVercel || loadingGitHub}
variant="outline"
size="lg"
className="w-full"
>
{loadingGitHub ? (
<>
<svg
className="animate-spin -ml-1 mr-2 h-4 w-4"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
>
<circle
className="opacity-25"
cx="12"
cy="12"
r="10"
stroke="currentColor"
strokeWidth="4"
></circle>
<path
className="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
></path>
</svg>
Loading...
</>
) : (
<>
<GitHubIcon className="h-4 w-4 mr-2" />
Sign in with GitHub
</>
)}
</Button>
)}
</div>
</DialogContent>
</Dialog>
Expand Down
11 changes: 8 additions & 3 deletions components/task-chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { Textarea } from '@/components/ui/textarea'
import { ArrowUp, Loader2, Copy, Check, RotateCcw, Square } from 'lucide-react'
import { toast } from 'sonner'
import { Streamdown } from 'streamdown'
import { useAtom } from 'jotai'
import { taskChatInputAtomFamily } from '@/lib/atoms/task'

interface TaskChatProps {
taskId: string
Expand All @@ -18,7 +20,7 @@ export function TaskChat({ taskId, task }: TaskChatProps) {
const [messages, setMessages] = useState<TaskMessage[]>([])
const [isLoading, setIsLoading] = useState(true)
const [error, setError] = useState<string | null>(null)
const [newMessage, setNewMessage] = useState('')
const [newMessage, setNewMessage] = useAtom(taskChatInputAtomFamily(taskId))
const [isSending, setIsSending] = useState(false)
const [currentTime, setCurrentTime] = useState(Date.now())
const [copiedMessageId, setCopiedMessageId] = useState<string | null>(null)
Expand Down Expand Up @@ -170,6 +172,8 @@ export function TaskChat({ taskId, task }: TaskChatProps) {

setIsSending(true)
const messageToSend = newMessage.trim()

// Clear the message immediately (optimistic)
setNewMessage('')

try {
Expand All @@ -188,14 +192,15 @@ export function TaskChat({ taskId, task }: TaskChatProps) {
if (response.ok) {
// Refresh messages to show the new user message without loading state
await fetchMessages(false)
// Message was sent successfully, keep it cleared
} else {
toast.error(data.error || 'Failed to send message')
setNewMessage(messageToSend) // Restore the message
setNewMessage(messageToSend) // Restore the message on error
}
} catch (err) {
console.error('Error sending message:', err)
toast.error('Failed to send message')
setNewMessage(messageToSend) // Restore the message
setNewMessage(messageToSend) // Restore the message on error
} finally {
setIsSending(false)
}
Expand Down
Loading
Loading