You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: projects/create-a-doodle-gallery/create-a-doodle-gallery.mdx
+31-18Lines changed: 31 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,13 +21,20 @@ courses:
21
21
22
22
# # Introduction
23
23
24
-
I miss the days of the internet when people built cool stuff for the sake of making fun things. There were a lot of random sites that were heavily in circulation during my younger years, like [Google Doodles](https://doodles.google/search/?form_tags=interactive%20game), that embraced creativity and play. [insert an image of some examples here] Here’s a project tutorial that might help bring us back to these days — you’ll be building a website where anyone can draw a doodle for a public virtual museum exhibit!
24
+
I miss the days of the internet when people built cool stuff for the sake of making fun things. There were a lot of random sites that were heavily in circulation during my younger years, like [Google Doodles](https://doodles.google/search/?form_tags=interactive%20game), that embraced creativity and play.
To make this project, we’ll be using the classic web dev tools HTML, CSS, and JavaScript, and will be storing our drawings in [Supabase](http://supabase.com/). We’ll also be using [Vite](https://vite.dev/) to get a local server running our website, that way you can run local servers with Node.js. I picked Vite because it handles imports cleanly, refreshes your website automatically with any changes, and is structured to better handle a project with a realtime database!
27
+
Here’s a project tutorial that might help bring us back to these days — you’ll be building a website where anyone can draw a doodle for a public virtual museum exhibit!
28
+
29
+

30
+
31
+
To make this project, we’ll be using the classic web dev tools HTML, CSS, and JavaScript, and will be storing our drawings in [Supabase](http://supabase.com/).
32
+
33
+
We’ll also be using [Vite](https://vite.dev/) to get a local server running our website, that way you can run local servers with Node.js. I picked Vite because it handles imports cleanly, refreshes your website automatically with any changes, and is structured to better handle a project with a realtime database!
27
34
28
35
# # About Supabase
29
36
30
-
[Supabase](https://supabase.com/) is a PostgreSQL development platform. In other words, it’s a database system that takes care of everything from setup, deployment, and application scaling, perfect for what we'll be creating today! Whenever a user draws a picture or types out text, we’re going to use Supabase to store all that information in real time, and fetch them from a bucket (aka a type of storage container) of our image-text pairs to display drawings in a public gallery!
37
+
[Supabase](https://supabase.com/) is a PostgreSQL (Post-Ingres Structured Query Language) development platform. In other words, it’s a database system that takes care of everything from setup, deployment, and application scaling, perfect for what we'll be creating today! Whenever a user draws a picture or types out text, we’re going to use Supabase to store all that information in real time, and fetch them from a bucket (aka a type of storage container) of our image-text pairs to display drawings in a public gallery!
31
38
32
39
# # **Setting Up**
33
40
@@ -49,32 +56,31 @@ create table if not exists public.drawings (
49
56
created_at timestamptz not null default now()
50
57
);
51
58
```
52
-
The interface should look like this:
53
-
54
59
## ## **Adding your API Keys**
55
60
We need to add API keys to our project for it to connect to our storage bucket - API keys authenticate the usage of coding tools like Supabase.
56
61
57
-
1. Go to the API menu under Project Settings. Find your Project URL and API key. They should look something like this:
62
+
Go to the API menu under Project Settings. Find your Project URL and API key. They should look something like this:
63
+

58
64
59
65
## ## **Clone Template**
60
66
61
67
Head over to [this GitHub link](https://github.com/gbanaag/codedex-doodle-project-template#) and clone the repository. The repository takes care of all the visual and front-end work, so you can put your full focus on working with your database.
62
68
63
69
You can clone the template in 3 different ways:
64
70
65
-
- Downloading the folder and adding it to your local workspace
66
-
- GitHub Desktop app
67
-
-`git clone` with command line
71
+
1. Downloading the folder and adding it to your local workspace
72
+
2. GitHub Desktop app
73
+
3.`git clone` with command line
68
74
69
-
If you’re curious to know what’s been coded for you already, here’s what’s already set up:The canvas interface where users can create their drawings (JavaScript)
75
+
If you’re curious to know what’s been coded for you already, here’s what’s already set up:The canvas interface where users can create their drawings (JavaScript)
70
76
71
-
- An input box to collect captions (HTML)
72
-
- Fonts, colors, the frame images, measurements (for the frames), animations, and layout choices (CSS)
73
-
- Picking random frames for each drawing (JavaScript)
77
+
- An input box to collect captions (HTML, `index.html`)
78
+
- Fonts, colors, the frame images, measurements (for the frames), animations, and layout choices (CSS, `style.css`)
79
+
- Picking random frames for each drawing (JavaScript, `main.js`)
74
80
75
81
You’ll be focusing on:
76
82
- Creating a storage container
77
-
-Setting up your website so that it can collect data
83
+
-Setting up your website so that it can collect data
78
84
- Displaying the data (user-created drawings and text) that’s been collected in a scrolling gallery
79
85
80
86
Let’s get into it! ⚡
@@ -85,28 +91,33 @@ Make sure you have the latest version of [Node.js](https://nodejs.org/en/downloa
85
91
86
92
Run this command in the terminal: `npm create vite@latest`, and then answer the prompts as follows. You can name your project however you like. When prompted, pick `Vanilla` as your framework and `JavaScript` as your variant. Your terminal should look like this at the end of completing the steps:
87
93
94
+

95
+
88
96
This might look different depending on what kind of computer you’re using — in my case, I’m on a Macbook.
89
97
90
98
## ## Running your server
91
99
92
100
To start up a server with your webpage running, type `npm run dev` in the Terminal. It’ll give you a url that looks something like: `http://localhost:3000/` — but the numbers in the URL can vary. Copy the link and paste it in your browser, and you should see something like this:
93
101
102
+

103
+
94
104
## ## **.env File and API Keys**
95
105
96
-
In your root folder, create a new file called `.env`. An `.env` file is used to keep sensitive information like API keys and credentials secret, and use substitute names in your code instead of the actual keys or data. This is helpful if your code is publicly shared, like on GitHub for example, since it hides the API keys automatically!
106
+
In your root folder, create a new file called `.env`. An `.env` file is used to keep sensitive information like API keys and credentials secret, and uses substitute names in your code instead of the actual keys or data. This is helpful if your code is publicly shared, like on GitHub for example, since it hides the API keys automatically!
97
107
98
108
Create two variables, `VITE_SUPABASE_URL` and `VITE_SUPABASE_ANON_KEY` and set their values to the URL and API values you found in your Supabase Project Settings.
99
109
100
110
```
101
-
VITE_SUPABASE_URL=https://[string of characters].supabase.co
(These are just examples of what API keys and URLs can look like - the ones above don't actually work!)
104
115
105
116
# # Submitting Drawings
106
117
107
118
Right now, you can draw on the canvas of the website, but you can't save or send the drawings anywhere. Once the page refreshes, the drawing disappears. We'll be coding a `submitDrawing()` function that packages up the canvas image and caption text, sends them to Supabase, and then immediately adds them to the gallery so the user can see their doodle appear in real time.
108
119
109
-
Start by creating the function. We’re making an `async` function — a special type of function that handles tasks external to the code we already have. In our case, we’re submitting data to container outside of the codebase.
120
+
We'll start by creating the function. We’re making an `async` function — a special type of function that handles tasks external to the code we already have. In our case, we’re submitting data to container outside of the codebase.
110
121
111
122
```jsx
112
123
asyncfunctionsubmitDrawing() {
@@ -350,6 +361,8 @@ We want our big gallery to load random drawings, so everyone’s drawings have a
350
361
351
362
Then we’re going to add our batch of drawings to our marquee. If you don’t know what a marquee is, it’s a scrolling gallery, or set of text that seems to scroll infinitely!
352
363
364
+

365
+
353
366
We’ll write out our function header for `repeatMarquee()`, limiting the number of drawings picked to 200. Our marquee has two rows, and if neither of them render, it’ll stop the function through the `if` statement.
0 commit comments