Skip to content

Commit 51b9e06

Browse files
committed
Add loading state to editor and publish button & refactor code
1 parent 3ea9274 commit 51b9e06

File tree

11 files changed

+91
-235
lines changed

11 files changed

+91
-235
lines changed

README.md

+24-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,29 @@
1-
# Nuxt 3 Minimal Starter
1+
# Codeshare.app
22

3-
Look at the [Nuxt 3 documentation](https://nuxt.com/docs/getting-started/introduction) to learn more.
3+
[Codeshare.app](https://codeshare.app) A mininal code bin sharing app, I wanted a simple but powerful for devs pastebin so, I created this small tool to share code snippets
44

5-
## Setup
5+
## Stack
6+
7+
- Nuxt 3
8+
- Tailwindcss
9+
- Nuxt UI
10+
- Turso Database
11+
- Monaco editor
12+
13+
## Pending tasks
14+
15+
1. Keyboard shortcuts
16+
2. Diff editor
17+
3. Refactor (lot of code repeated, didn't think it through) - make common and reuse components and composables
18+
4. Sharable diff editor
19+
20+
## ENV Vars
21+
22+
TURSO_DB_TOKEN - Database token
23+
24+
TURSO_DB_URL - Database url
25+
26+
## Local setup
627

728
Make sure to install the dependencies:
829

@@ -71,5 +92,3 @@ yarn preview
7192
# bun
7293
bun run preview
7394
```
74-
75-
Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information.

app.config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default defineAppConfig({
1212
button: {
1313
rounded:
1414
"rounded-lg transition-transform active:scale-x-[0.98] active:scale-y-[0.99]",
15+
default: { loadingIcon: "i-lucide-loader-2" },
1516
},
1617
modal: {
1718
overlay: {
@@ -25,4 +26,4 @@ export default defineAppConfig({
2526
},
2627
},
2728
},
28-
});
29+
});

components/App/Navbar/index.vue

+13-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
>CODESHARE</span
88
>
99
</h1>
10-
<UInput v-model="snippet.title" placeholder="file.txt" size="2xs" />
10+
<UInput
11+
v-if="publishEnabled"
12+
v-model="snippet.title"
13+
placeholder="file.txt"
14+
size="2xs"
15+
/>
1116
<div
1217
class="border-l divide-x divide-white/10 border-white/10 flex items-center"
1318
>
@@ -24,7 +29,7 @@
2429
<Icon name="i-lucide-copy" class="h-4 w-4" />
2530
</button>
2631
</UTooltip>
27-
<UTooltip text="Publish">
32+
<UTooltip v-if="publishEnabled" text="Publish">
2833
<button
2934
@click="$emit('publish')"
3035
class="border-white/10 h-9 px-3 text-sm hover:bg-gray-950"
@@ -37,6 +42,12 @@
3742
</template>
3843

3944
<script setup>
45+
defineProps({
46+
publishEnabled: {
47+
type: Boolean,
48+
required: true,
49+
},
50+
});
4051
const { snippet } = useEditor();
4152
</script>
4253

components/App/Sidebar/index.vue

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
:popper="{ placement: 'right' }"
99
>
1010
<UButton
11+
to="/"
1112
icon="i-lucide-file-code-2"
1213
square
1314
variant="ghost"

composables/editor.js

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export const useEditor = () => {
126126
letterCount,
127127
editorRef,
128128
snippet,
129+
loading,
129130
confirmationModal,
130131
toggleMinimap,
131132
handleMount,

nuxt.config.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@ export default defineNuxtConfig({
77
"@nuxtjs/google-fonts",
88
"@nuxtjs/fontaine",
99
"@vueuse/nuxt",
10-
"@formkit/auto-animate/nuxt"
1110
],
1211
ui: {
1312
icons: ["heroicons", "lucide"],
1413
},
1514
colorMode: {
16-
preference: 'dark'
15+
preference: "dark",
1716
},
1817
googleFonts: {
1918
display: "swap",
2019
families: {
2120
Inter: [400, 500, 600, 700, 800, 900],
2221
},
2322
},
24-
});
23+
});

package.json

-3
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,13 @@
2323
"vue-router": "^4.2.5"
2424
},
2525
"dependencies": {
26-
"@formkit/auto-animate": "^0.8.1",
2726
"@guolao/vue-monaco-editor": "^1.4.1",
2827
"@iconify-json/lucide": "^1.1.154",
2928
"@libsql/client": "0.4.0-pre.7",
3029
"@nuxt/ui": "^2.12.0",
31-
"better-sqlite3": "^9.2.2",
3230
"drizzle-orm": "^0.29.3",
3331
"h3-zod": "^0.5.3",
3432
"nanoid": "^5.0.4",
35-
"utf-8-validate": "^6.0.3",
3633
"zod": "^3.22.4"
3734
}
3835
}

pages/[id].vue

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<template>
22
<main class="h-screen flex flex-col text-white">
3-
<AppNavbar @publish="publishSnippet" @copy="copySnippet" />
3+
<AppNavbar
4+
@publish="publishSnippet"
5+
@copy="copySnippet"
6+
:publish-enabled="false"
7+
/>
48
<div class="flex-1 flex">
59
<AppSidebar />
610
<ClientOnly>
@@ -105,11 +109,9 @@
105109
const {
106110
MONACO_EDITOR_OPTIONS,
107111
languages,
108-
lineCount,
109-
wordCount,
110-
letterCount,
111112
editorRef,
112113
confirmationModal,
114+
lineCount,
113115
toggleMinimap,
114116
handleMount,
115117
onChange,
@@ -121,13 +123,24 @@ const {
121123
const route = useRoute();
122124
const { data: snippet } = await useFetch(`/api/codebin/${route.params.id}`);
123125
126+
const wordCount = computed(() => {
127+
const text = snippet.value.body;
128+
const words = text.match(/\w+/g);
129+
return words ? words.length : 0;
130+
});
131+
132+
const letterCount = computed(() => {
133+
const text = snippet.value.body;
134+
return text.length;
135+
});
136+
124137
useHead({
125-
title: `${snippet.title} - Codeshare.app`,
138+
title: `${snippet.value.title} - Codeshare.app`,
126139
meta: [
127140
{
128141
hid: "description",
129142
name: "description",
130-
content: `Codeshare.app - ${snippet.title}`,
143+
content: `Codeshare.app - ${snippet.value.title}`,
131144
},
132145
],
133146
});

pages/index.vue

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<main class="h-screen flex flex-col text-white">
3-
<AppNavbar @publish="publishSnippet" @copy="copySnippet" />
3+
<AppNavbar @publish="publishSnippet" @copy="copySnippet" publishEnabled />
44
<div class="flex-1 flex">
55
<AppSidebar />
66
<ClientOnly>
@@ -93,7 +93,13 @@
9393
title="Heads up!"
9494
description="This snippet will be public and anyone will be able to see it. Make sure you don't include any sensitive information."
9595
/>
96-
<UButton @click="confirmPublish" size="lg" block color="black"
96+
<UButton
97+
@click="confirmPublish"
98+
size="lg"
99+
block
100+
color="black"
101+
:loading="loading"
102+
:disabled="loading"
97103
>Publish</UButton
98104
>
99105
</div>
@@ -111,6 +117,7 @@ const {
111117
editorRef,
112118
snippet,
113119
confirmationModal,
120+
loading,
114121
toggleMinimap,
115122
handleMount,
116123
onChange,

0 commit comments

Comments
 (0)