Skip to content

Commit b983f3b

Browse files
committed
update readme; fix project after supabase resume
1 parent c1794cb commit b983f3b

File tree

12 files changed

+85
-25
lines changed

12 files changed

+85
-25
lines changed

config/const.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ export const SUPABASE_KEY: string = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY ||
55
// - storage
66
export const SUPABASE_DEFAULT_BUCKET = 'assets';
77
export const SUPABASE_BUCKET_URL = `${SUPABASE_URL}/storage/v1/object/public/${SUPABASE_DEFAULT_BUCKET}`;
8-
export const MAX_FILE_SIZE = 2 * 1024 * 1024; // 2MB
8+
export const MAX_FILE_SIZE_MB = 5;
9+
export const MAX_FILE_SIZE_BYTES = MAX_FILE_SIZE_MB * 1024 * 1024; // 2MB
910

1011
// Other
1112
export const DEFAULT_URL = process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : 'http://localhost:3000';

features/post/components/PostTagsList.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const PostTagsList: RC<IProps> = ({ post, interactive, wrapperClassName,
2121

2222
return (
2323
<div className={cn('stack flex-wrap items-center gap-2', wrapperClassName)}>
24-
{tags.length === 0 && interactive && <span className="stack text-muted-foreground">Add Tag</span>}
24+
{!tags.length && interactive && <span className="stack text-muted-foreground">Add Tag</span>}
2525
{tags.map((tag) => (
2626
// TODO: Tags could be non-interactive
2727
<Link key={tag.id} className="stack" href={`/tags/${tag.name}`}>

features/storage/actions/validators/uploadFileSchema.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { z } from 'zod';
22

3-
import { MAX_FILE_SIZE } from '@/config/const';
3+
import { MAX_FILE_SIZE_BYTES } from '@/config/const';
44

55
/**
66
* NOTE: We can't pass `File` directly to the server-actions, so we need to wrap it to `FormData`
@@ -13,5 +13,5 @@ export const UploadFileSchema = z.object({
1313
.refine((formData) => formData.has('file'), 'Expected FormData to contain a file')
1414
.transform((formData) => formData.get('file') as File)
1515
.refine((f) => f instanceof File, 'Expected FormData `file` to be an instance of File')
16-
.refine(({ size }) => size <= MAX_FILE_SIZE, 'File size exceeds max size'),
16+
.refine(({ size }) => size <= MAX_FILE_SIZE_BYTES, 'File size exceeds max size'),
1717
});

features/storage/hooks/useUploadImage.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useState, useEffect } from 'react';
44
import { toast } from 'sonner';
55
import { useServerAction } from 'zsa-react';
66

7+
import { MAX_FILE_SIZE_MB } from '@/config/const';
78
import { uploadImage } from '@/features/storage/actions/uploadImage';
89
import { checkFileSize, wrapFileWithFormData } from '@/features/storage/lib/file';
910
import { getImageUrl } from '@/lib/supabase/storage';
@@ -41,7 +42,7 @@ export const useUploadImage = (initialValue?: string | null) => {
4142

4243
// Check if the file size exceeds 2MB
4344
if (!checkFileSize(file)) {
44-
toast.error('File size exceeds 2MB.');
45+
toast.error(`File size exceeds ${MAX_FILE_SIZE_MB}MB.`);
4546

4647
return;
4748
}
@@ -58,7 +59,8 @@ export const useUploadImage = (initialValue?: string | null) => {
5859
setImgUrl(getImageUrl(result.path));
5960
toast.success('File uploaded successfully.');
6061
} catch (e) {
61-
toast.error('Error uploading file:', e.message);
62+
toast.error(`Error uploading file: ${e.message}`);
63+
console.log(e);
6264
}
6365
};
6466

features/storage/lib/file.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MAX_FILE_SIZE } from '@/config/const';
1+
import { MAX_FILE_SIZE_BYTES } from '@/config/const';
22

33
/**
44
* Get a file from a request by input name (key)
@@ -43,7 +43,7 @@ const safeFileName = (filename: string): string => {
4343
* @param file
4444
* @param maxSize - Maximum file size in bytes (default: 2MB / const.ts)
4545
*/
46-
export const checkFileSize = (file: File, maxSize: number = MAX_FILE_SIZE): boolean => {
46+
export const checkFileSize = (file: File, maxSize: number = MAX_FILE_SIZE_BYTES): boolean => {
4747
return file.size <= maxSize;
4848
};
4949

lib/supabase/readme.md

+51
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,54 @@ with check (
5050
true
5151
);
5252
```
53+
54+
### Tables
55+
```sql
56+
CREATE TABLE public.posts (
57+
id integer NOT NULL,
58+
title text DEFAULT ''::text NOT NULL,
59+
content text DEFAULT ''::text NOT NULL,
60+
slug text DEFAULT ''::text NOT NULL,
61+
id_author uuid DEFAULT auth.uid() NOT NULL,
62+
published_at timestamp without time zone,
63+
created_at timestamp without time zone DEFAULT (now() AT TIME ZONE 'utc'::text) NOT NULL,
64+
updated_at timestamp without time zone DEFAULT (now() AT TIME ZONE 'utc'::text) NOT NULL,
65+
is_published boolean DEFAULT false NOT NULL,
66+
seo_title text,
67+
seo_description text,
68+
thumbnail text
69+
);
70+
71+
CREATE TABLE public.notes (
72+
id bigint NOT NULL,
73+
title text,
74+
id_author uuid DEFAULT auth.uid(),
75+
is_done boolean,
76+
id_status smallint DEFAULT '1'::smallint
77+
);
78+
79+
CREATE TABLE public.post_tags (
80+
post_id integer NOT NULL,
81+
tag_id integer NOT NULL
82+
);
83+
84+
CREATE TABLE public.profiles (
85+
id uuid NOT NULL,
86+
id_role smallint DEFAULT '1'::smallint NOT NULL,
87+
username text DEFAULT ''::text NOT NULL,
88+
email character varying DEFAULT ''::character varying NOT NULL,
89+
avatar text DEFAULT ''::text NOT NULL,
90+
updated_at timestamp with time zone,
91+
created_at timestamp with time zone DEFAULT (now() AT TIME ZONE 'utc'::text) NOT NULL
92+
);
93+
94+
CREATE TABLE public.roles (
95+
id smallint NOT NULL,
96+
name character varying(255) NOT NULL
97+
);
98+
99+
CREATE TABLE public.statuses (
100+
id smallint NOT NULL,
101+
name text
102+
);
103+
```

readme.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Next.js, NextUI with Supabase
22

3+
## Screenshots
4+
5+
![Screenshot 1](screenshots/scr-login.png)
6+
![Screenshot 2](screenshots/scr-1.png)
7+
![Screenshot 2](screenshots/scr-2.png)
8+
![Screenshot 2](screenshots/scr-editor.png)
9+
310
## Technologies Used
411

512
- [Next.js 14](https://nextjs.org/docs/getting-started)

screenshots/scr-1.png

839 KB
Loading

screenshots/scr-2.png

944 KB
Loading

screenshots/scr-editor.png

227 KB
Loading

screenshots/scr-login.png

185 KB
Loading

types/supabase.ts

+16-17
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export type Database = {
3030
foreignKeyName: 'notes_id_author_fkey';
3131
columns: ['id_author'];
3232
isOneToOne: false;
33-
referencedRelation: 'users';
33+
referencedRelation: 'profiles';
3434
referencedColumns: ['id'];
3535
},
3636
{
@@ -117,7 +117,7 @@ export type Database = {
117117
};
118118
Relationships: [
119119
{
120-
foreignKeyName: 'posts_id_author_fkey1';
120+
foreignKeyName: 'posts_id_author_fkey';
121121
columns: ['id_author'];
122122
isOneToOne: false;
123123
referencedRelation: 'profiles';
@@ -139,7 +139,7 @@ export type Database = {
139139
avatar?: string;
140140
created_at?: string;
141141
email?: string;
142-
id: string;
142+
id?: string;
143143
id_role?: number;
144144
updated_at?: string | null;
145145
username?: string;
@@ -154,20 +154,6 @@ export type Database = {
154154
username?: string;
155155
};
156156
Relationships: [
157-
{
158-
foreignKeyName: 'profiles_auth_users_id_fkey';
159-
columns: ['id'];
160-
isOneToOne: true;
161-
referencedRelation: 'users';
162-
referencedColumns: ['id'];
163-
},
164-
{
165-
foreignKeyName: 'profiles_email_fkey';
166-
columns: ['email'];
167-
isOneToOne: true;
168-
referencedRelation: 'users';
169-
referencedColumns: ['email'];
170-
},
171157
{
172158
foreignKeyName: 'profiles_id_role_fkey';
173159
columns: ['id_role'];
@@ -309,3 +295,16 @@ export type Enums<
309295
: PublicEnumNameOrOptions extends keyof PublicSchema['Enums']
310296
? PublicSchema['Enums'][PublicEnumNameOrOptions]
311297
: never;
298+
299+
export type CompositeTypes<
300+
PublicCompositeTypeNameOrOptions extends keyof PublicSchema['CompositeTypes'] | { schema: keyof Database },
301+
CompositeTypeName extends PublicCompositeTypeNameOrOptions extends {
302+
schema: keyof Database;
303+
}
304+
? keyof Database[PublicCompositeTypeNameOrOptions['schema']]['CompositeTypes']
305+
: never = never,
306+
> = PublicCompositeTypeNameOrOptions extends { schema: keyof Database }
307+
? Database[PublicCompositeTypeNameOrOptions['schema']]['CompositeTypes'][CompositeTypeName]
308+
: PublicCompositeTypeNameOrOptions extends keyof PublicSchema['CompositeTypes']
309+
? PublicSchema['CompositeTypes'][PublicCompositeTypeNameOrOptions]
310+
: never;

0 commit comments

Comments
 (0)