forked from stackblitz/bolt.new
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ed McConnell
committed
Dec 22, 2024
1 parent
099b003
commit 820f6bb
Showing
8 changed files
with
336 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/lib/github/GitHubAuth.tsx → app/components/github/GitHubAuth.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export function GitHubPushOverlay() { | ||
return ( | ||
<div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50"> | ||
<div className="bg-[#0F0F0F] rounded-xl p-6 flex flex-col items-center gap-4 border border-purple-500/30"> | ||
<div className="w-12 h-12 border-4 border-t-purple-500 border-purple-200/20 rounded-full animate-spin" /> | ||
<p className="text-bolt-elements-textPrimary">Pushing your project to GitHub...</p> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { useState } from 'react'; | ||
import { toast } from 'react-toastify'; | ||
import { getGitHubUser } from '~/lib/github/github.client'; | ||
|
||
export function useGitHubPush() { | ||
const [isAuthModalOpen, setIsAuthModalOpen] = useState(false); | ||
const [isPushingToGitHub, setIsPushingToGitHub] = useState(false); | ||
|
||
const handlePushToGitHub = async () => { | ||
try { | ||
// Check for existing GitHub token | ||
const existingToken = localStorage.getItem('github_token'); | ||
|
||
if (existingToken) { | ||
// Get the GitHub user info directly to validate token | ||
await getGitHubUser(existingToken); | ||
} | ||
|
||
// Show auth modal, passing the existing token if we have one | ||
setIsAuthModalOpen(true); | ||
} catch (error) { | ||
console.error('Failed to use existing GitHub token:', error); | ||
|
||
// If token is invalid, remove it | ||
localStorage.removeItem('github_token'); | ||
setIsAuthModalOpen(true); | ||
} | ||
}; | ||
|
||
const handleAuthComplete = async () => { | ||
setIsAuthModalOpen(false); | ||
setIsPushingToGitHub(true); | ||
}; | ||
|
||
const handlePushComplete = (success: boolean, repoUrl?: string) => { | ||
setIsPushingToGitHub(false); | ||
|
||
if (success) { | ||
toast.success( | ||
<div className="flex flex-col gap-1"> | ||
<span>Successfully pushed to GitHub!</span> | ||
{repoUrl && ( | ||
<a | ||
href={repoUrl} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
className="text-sm text-blue-500 hover:text-blue-600" | ||
> | ||
View Repository → | ||
</a> | ||
)} | ||
</div>, | ||
{ autoClose: 5000 }, | ||
); | ||
} else { | ||
toast.error('Failed to push to GitHub. Please try again.'); | ||
} | ||
}; | ||
|
||
return { | ||
isAuthModalOpen, | ||
isPushingToGitHub, | ||
setIsAuthModalOpen, | ||
handlePushToGitHub, | ||
handleAuthComplete, | ||
handlePushComplete, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.