-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add fetchGitHubFileContent, add hide code block, error handling CopyB…
…utton
- Loading branch information
1 parent
3744c43
commit 9152721
Showing
10 changed files
with
121 additions
and
86 deletions.
There are no files selected for viewing
Binary file not shown.
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 was deleted.
Oops, something went wrong.
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,48 @@ | ||
import { cache } from 'react'; | ||
|
||
interface GitHubFileContent { | ||
owner?: string; | ||
repo?: string; | ||
path: string; | ||
} | ||
|
||
export const fetchGitHubFileContent = cache( | ||
async ({ | ||
owner = 'MarkMelior', | ||
repo = 'simple-app', | ||
path, | ||
}: GitHubFileContent): Promise<string> => { | ||
const url = `https://api.github.com/repos/${owner}/${repo}/contents/${path}`; | ||
|
||
try { | ||
const response = await fetch(url); | ||
|
||
if (!response.ok) { | ||
throw new Error( | ||
`Error fetching from GitHub: ${response.status} - ${response.statusText}`, | ||
); | ||
} | ||
|
||
const data = await response.json(); | ||
|
||
if (!data || !data.content) { | ||
throw new Error('Invalid data format from GitHub API'); | ||
} | ||
|
||
const content = atob(data.content); | ||
|
||
// Remove last empty line | ||
const contentSplit = content.split('\n'); | ||
if (contentSplit[contentSplit.length - 1] === '') { | ||
contentSplit.pop(); | ||
} | ||
|
||
return contentSplit.join('\n'); | ||
} catch (error) { | ||
console.error('Error receiving a file from GitHub:', error); | ||
return error?.toString() || 'An unknown error has occurred'; | ||
|
||
throw error; // Forward the error further for processing at the call level | ||
} | ||
}, | ||
); |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { fetchGitHubFileContent } from './fetch-github-file/fetch-github-file'; | ||
import { cn } from './tailwind-merge/tailwind-merge'; | ||
|
||
export { cn }; | ||
export { cn, fetchGitHubFileContent }; |
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,21 @@ | ||
.showWrapper { | ||
position: relative; | ||
} | ||
|
||
.gradient { | ||
@apply absolute pointer-events-none w-full -top-32 h-32 bg-gradient-to-t from-default-100; | ||
} | ||
|
||
.showButton { | ||
@apply bg-default-100 text-default-600 py-2 px-3 w-full text-left data-[pressed=true]:scale-100; | ||
|
||
&:hover { | ||
@apply bg-default-200; | ||
} | ||
} | ||
|
||
.showButton:hover .gradient { | ||
background: red !important; | ||
background-color: red !important; | ||
@apply from-default-200; | ||
} |
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