generated from warmachine028/github-super-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
ae86ff8
commit 53ffd55
Showing
18 changed files
with
1,149 additions
and
8 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 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,5 +1,5 @@ | ||
#root { | ||
max-width: 1280px; | ||
/* max-width: 1280px; */ | ||
margin: 0 auto; | ||
padding: 2rem; | ||
text-align: center; | ||
|
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,2 @@ | ||
export * from './todos' | ||
export * from './posts' |
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,134 @@ | ||
import axios from 'axios' | ||
|
||
interface Post { | ||
id: number | ||
title: string | ||
body: string | ||
userId: number | ||
imageUrl: string | ||
tags: string[] | ||
reactions: { | ||
likes: number | ||
dislikes: number | ||
} | ||
views: number | ||
} | ||
|
||
interface PostsResponse { | ||
posts: Post[] | ||
total: number | ||
skip: number | ||
limit: number | ||
} | ||
|
||
const API_URL = 'https://dummyjson.com' | ||
|
||
export const getPosts = async (skip: number = 0, limit: number = 10): Promise<PostsResponse> => { | ||
try { | ||
const { data } = await axios.get<PostsResponse>(`${API_URL}/posts?limit=${limit}&skip=${skip}`) | ||
|
||
// Add imageUrl and transform reactions to the required format for each post | ||
const postsWithImages = data.posts.map((post) => ({ | ||
...post, | ||
imageUrl: `https://picsum.photos/seed/${post.id}/800/600` | ||
})) | ||
|
||
return { | ||
...data, | ||
posts: postsWithImages | ||
} | ||
} catch (error) { | ||
throw handleApiError(error) | ||
} | ||
} | ||
|
||
// Other API functions remain similar but need to be updated with the new Post interface | ||
export const createPost = async (post: Omit<Post, 'id' | 'imageUrl' | 'views'>): Promise<Post> => { | ||
try { | ||
const { data } = await axios.post(`${API_URL}/posts/add`, post) | ||
return { | ||
...data, | ||
imageUrl: `https://picsum.photos/seed/${data.id}/800/600`, | ||
views: 0, | ||
reactions: { likes: 0, dislikes: 0 } | ||
} | ||
} catch (error) { | ||
throw handleApiError(error) | ||
} | ||
} | ||
|
||
export const updatePost = async (post: Partial<Post> & { id: number }): Promise<Post> => { | ||
try { | ||
const { data } = await axios.put(`${API_URL}/posts/${post.id}`, post) | ||
return { | ||
...data, | ||
imageUrl: `https://picsum.photos/seed/${data.id}/800/600`, | ||
reactions: post.reactions || { likes: 0, dislikes: 0 }, | ||
views: post.views || 0 | ||
} | ||
} catch (error) { | ||
throw handleApiError(error) | ||
} | ||
} | ||
|
||
// Delete a post | ||
export const deletePost = async (id: number): Promise<void> => { | ||
try { | ||
await axios.delete(`${API_URL}/posts/${id}`) | ||
} catch (error) { | ||
throw handleApiError(error) | ||
} | ||
} | ||
|
||
// Search posts | ||
export const searchPosts = async (query: string): Promise<PostsResponse> => { | ||
try { | ||
const { data } = await axios.get<PostsResponse>(`${API_URL}/posts/search?q=${query}`) | ||
|
||
const postsWithImages = data.posts.map((post) => ({ | ||
...post, | ||
imageUrl: `https://picsum.photos/seed/${post.id}/800/600` | ||
})) | ||
|
||
return { | ||
...data, | ||
posts: postsWithImages | ||
} | ||
} catch (error) { | ||
throw handleApiError(error) | ||
} | ||
} | ||
|
||
// Get posts by user | ||
export const getPostsByUser = async (userId: number): Promise<PostsResponse> => { | ||
try { | ||
const { data } = await axios.get<PostsResponse>(`${API_URL}/posts/user/${userId}`) | ||
|
||
const postsWithImages = data.posts.map((post) => ({ | ||
...post, | ||
imageUrl: `https://picsum.photos/seed/${post.id}/800/600` | ||
})) | ||
|
||
return { | ||
...data, | ||
posts: postsWithImages | ||
} | ||
} catch (error) { | ||
throw handleApiError(error) | ||
} | ||
} | ||
|
||
// Error handling helper | ||
const handleApiError = (error: unknown) => { | ||
if (axios.isAxiosError(error)) { | ||
const message = error.response?.data?.message || error.message | ||
console.error('API Error:', { | ||
status: error.response?.status, | ||
message, | ||
details: error.response?.data | ||
}) | ||
throw new Error(`API Error: ${message}`) | ||
} | ||
console.error('Unexpected error:', error) | ||
throw error | ||
} |
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,38 @@ | ||
// src/api/index.ts | ||
|
||
import axios from 'axios' | ||
|
||
// Define Todo type | ||
interface Todo { | ||
id: number | ||
title: string | ||
completed?: boolean | ||
} | ||
|
||
// API base URL - replace with your actual API endpoint | ||
const API_URL = 'https://jsonplaceholder.typicode.com' | ||
|
||
// Get all todos | ||
export const getTodos = async (): Promise<Todo[]> => { | ||
const { data } = await axios.get(`${API_URL}/todos`) | ||
return data | ||
} | ||
|
||
// Add a new todo | ||
export const postTodo = async (todo: Omit<Todo, 'completed'>): Promise<Todo> => { | ||
const { data } = await axios.post(`${API_URL}/todos`, { | ||
...todo, | ||
completed: false | ||
}) | ||
return data | ||
} | ||
|
||
// Optional: You might also want these additional methods | ||
export const updateTodo = async (todo: Todo): Promise<Todo> => { | ||
const { data } = await axios.put(`${API_URL}/todos/${todo.id}`, todo) | ||
return data | ||
} | ||
|
||
export const deleteTodo = async (id: number): Promise<void> => { | ||
await axios.delete(`${API_URL}/todos/${id}`) | ||
} |
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,29 @@ | ||
import * as React from 'react' | ||
import { cva, type VariantProps } from 'class-variance-authority' | ||
|
||
import { cn } from '@/lib/utils' | ||
|
||
const badgeVariants = cva( | ||
'inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2', | ||
{ | ||
variants: { | ||
variant: { | ||
default: 'border-transparent bg-primary text-primary-foreground hover:bg-primary/80', | ||
secondary: 'border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80', | ||
destructive: 'border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80', | ||
outline: 'text-foreground' | ||
} | ||
}, | ||
defaultVariants: { | ||
variant: 'default' | ||
} | ||
} | ||
) | ||
|
||
export interface BadgeProps extends React.HTMLAttributes<HTMLDivElement>, VariantProps<typeof badgeVariants> {} | ||
|
||
const Badge = React.forwardRef<HTMLDivElement, BadgeProps>(({ className, variant, ...props }, ref) => { | ||
return <div className={cn(badgeVariants({ variant }), className)} ref={ref} {...props} /> | ||
}) | ||
Badge.displayName = 'Badge' | ||
export { Badge, badgeVariants } |
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,28 @@ | ||
import * as React from "react" | ||
import * as CheckboxPrimitive from "@radix-ui/react-checkbox" | ||
import { Check } from "lucide-react" | ||
|
||
import { cn } from "@/lib/utils" | ||
|
||
const Checkbox = React.forwardRef< | ||
React.ElementRef<typeof CheckboxPrimitive.Root>, | ||
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root> | ||
>(({ className, ...props }, ref) => ( | ||
<CheckboxPrimitive.Root | ||
ref={ref} | ||
className={cn( | ||
"peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground", | ||
className | ||
)} | ||
{...props} | ||
> | ||
<CheckboxPrimitive.Indicator | ||
className={cn("flex items-center justify-center text-current")} | ||
> | ||
<Check className="h-4 w-4" /> | ||
</CheckboxPrimitive.Indicator> | ||
</CheckboxPrimitive.Root> | ||
)) | ||
Checkbox.displayName = CheckboxPrimitive.Root.displayName | ||
|
||
export { Checkbox } |
Oops, something went wrong.