File tree Expand file tree Collapse file tree 6 files changed +44
-23
lines changed Expand file tree Collapse file tree 6 files changed +44
-23
lines changed Original file line number Diff line number Diff line change 1
1
"use server" ;
2
2
3
+ import type { Resource } from "@/types" ;
4
+
3
5
import { createClient } from "@/lib/supabase/server" ;
4
6
5
7
export const getResources = async ( ) => {
6
8
const supabase = await createClient ( ) ;
7
9
const { data, error } = await supabase . from ( "resources" ) . select ( `
8
- *,
10
+ id,
11
+ name,
12
+ slug,
13
+ image,
14
+ tags,
9
15
category:categories (id, name)
10
16
` ) ;
11
17
12
18
if ( error ) throw error ;
13
19
return data ;
14
20
} ;
15
21
16
- export const getResourceBySlug = async ( slug : string ) => {
22
+ export const getResourceBySlug = async (
23
+ slug : string ,
24
+ ) : Promise < Resource | null > => {
17
25
const supabase = await createClient ( ) ;
18
26
const { data, error } = await supabase
19
27
. from ( "resources" )
20
28
. select ( "*" )
21
29
. eq ( "slug" , slug )
22
30
. single ( ) ;
23
- if ( error ) throw error ;
31
+
32
+ if ( error ) throw new Error ( error . message ) ;
24
33
return data ;
25
34
} ;
Original file line number Diff line number Diff line change 1
1
import { NextResponse } from "next/server" ;
2
2
import { createClient } from "@/lib/supabase/server" ;
3
+ import { HOME_PATH } from "@/config/constants" ;
3
4
4
5
export async function GET ( request : Request ) {
5
6
const { searchParams, origin } = new URL ( request . url ) ;
6
7
const code = searchParams . get ( "code" ) ;
7
- const next = searchParams . get ( "next" ) ?? "/" ;
8
+ const next = searchParams . get ( "next" ) ?? HOME_PATH ;
8
9
9
10
if ( code ) {
10
11
const supabase = await createClient ( ) ;
Original file line number Diff line number Diff line change 3
3
import { useEffect } from "react" ;
4
4
import { useRouter } from "next/navigation" ;
5
5
import { motion } from "framer-motion" ;
6
+ import { HOME_PATH } from "@/config/constants" ;
6
7
7
8
export default function NotFoundPage ( ) {
8
9
const router = useRouter ( ) ;
9
10
10
11
useEffect ( ( ) => {
11
12
const timer = setTimeout ( ( ) => {
12
- router . push ( "/" ) ;
13
+ router . push ( HOME_PATH ) ;
13
14
} , 5000 ) ;
14
15
15
16
return ( ) => clearTimeout ( timer ) ;
Original file line number Diff line number Diff line change 1
1
"use client" ;
2
2
3
- import type { ResourceResponse } from "@/types" ;
3
+ import type { Resource } from "@/types" ;
4
4
5
5
import { ResourceCard } from "@/components/resources" ;
6
6
7
7
type Props = {
8
- resources : ResourceResponse [ ] ;
8
+ resources : Resource [ ] ;
9
9
} ;
10
10
11
11
export default function ResourceList ( { resources } : Props ) {
Original file line number Diff line number Diff line change
1
+ export function capitalize ( str : string ) {
2
+ return str . charAt ( 0 ) . toUpperCase ( ) + str . slice ( 1 ) ;
3
+ }
Original file line number Diff line number Diff line change 1
- // Api Responses
2
- export type ResourceResponse = {
3
- id : string ;
4
- title : string ;
5
- slug : string ;
6
- description : string ;
7
- image : string ;
8
- category : string ;
9
- tags : string [ ] ;
10
- author : {
11
- id : string ;
12
- name : string ;
13
- } ;
14
- created_at : string ;
15
- } ;
1
+ // Supabase Types
16
2
17
- export type UserResponse = {
3
+ export type User = {
18
4
id : string ;
19
5
email ?: string ;
20
6
user_metadata : {
@@ -23,3 +9,24 @@ export type UserResponse = {
23
9
avatar_url : string ;
24
10
} ;
25
11
} ;
12
+
13
+ export type Category = {
14
+ id : string ;
15
+ name : string ;
16
+ slug : string ;
17
+ created_at : string ;
18
+ } ;
19
+
20
+ export type Resource = {
21
+ id : string ;
22
+ name : string ;
23
+ slug : string ;
24
+ url : string ;
25
+ description : string ;
26
+ image : string ;
27
+ tags : string [ ] ;
28
+ author : string ;
29
+ category : Omit < Category , "id" | "created_at" > ;
30
+ status : "pending" | "approved" | "rejected" ;
31
+ created_at : string ;
32
+ } ;
You can’t perform that action at this time.
0 commit comments