Skip to content

Commit 154fd1e

Browse files
author
Akshara Hegde
committed
feat(app): update the file extension automatically
change the filename extension on language change
1 parent eeefb84 commit 154fd1e

File tree

5 files changed

+131
-23
lines changed

5 files changed

+131
-23
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ logs
1717
.DS_Store
1818
.fleet
1919
.idea
20+
.vscode/
2021

2122
# Local env files
2223
.env

assets/file-extensions.json

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{
2+
"plaintext": ".txt",
3+
"abap": ".abap",
4+
"apex": ".cls",
5+
"azcli": ".azcli",
6+
"bat": ".bat",
7+
"bicep": ".bicep",
8+
"cameligo": ".cameligo",
9+
"clojure": ".clj",
10+
"coffeescript": ".coffee",
11+
"c": ".c",
12+
"cpp": ".cpp",
13+
"csharp": ".cs",
14+
"csp": ".csp",
15+
"css": ".css",
16+
"cypher": ".cyp",
17+
"dart": ".dart",
18+
"dockerfile": ".dockerfile",
19+
"ecl": ".ecl",
20+
"elixir": ".ex",
21+
"flow9": ".flow9",
22+
"freemarker2": ".ftl",
23+
"fsharp": ".fs",
24+
"go": ".go",
25+
"graphql": ".gql",
26+
"handlebars": ".hbs",
27+
"hcl": ".hcl",
28+
"html": ".html",
29+
"ini": ".ini",
30+
"java": ".java",
31+
"javascript": ".js",
32+
"json": ".json",
33+
"julia": ".jl",
34+
"kotlin": ".kt",
35+
"less": ".less",
36+
"lexon": ".lexon",
37+
"liquid": ".liquid",
38+
"lua": ".lua",
39+
"m3": ".m3",
40+
"markdown": ".md",
41+
"mdx": ".mdx",
42+
"mips": ".mips",
43+
"msdax": ".msdax",
44+
"mysql": ".sql",
45+
"objective-c": ".m",
46+
"pascal": ".pas",
47+
"pascaligo": ".pascaligo",
48+
"perl": ".pl",
49+
"pgsql": ".pgsql",
50+
"php": ".php",
51+
"pla": ".pla",
52+
"postiats": ".dats",
53+
"powerquery": ".pq",
54+
"powershell": ".ps1",
55+
"proto": ".proto",
56+
"pug": ".pug",
57+
"python": ".py",
58+
"qsharp": ".qs",
59+
"r": ".r",
60+
"razor": ".cshtml",
61+
"redis": ".redis",
62+
"redshift": ".sql",
63+
"restructuredtext": ".rst",
64+
"ruby": ".rb",
65+
"rust": ".rs",
66+
"sb": ".sb",
67+
"scala": ".scala",
68+
"scheme": ".scm",
69+
"scss": ".scss",
70+
"shell": ".sh",
71+
"sol": ".sol",
72+
"aes": ".aes",
73+
"sparql": ".rq",
74+
"sql": ".sql",
75+
"st": ".st",
76+
"swift": ".swift",
77+
"systemverilog": ".sv",
78+
"verilog": ".v",
79+
"tcl": ".tcl",
80+
"twig": ".twig",
81+
"typescript": ".ts",
82+
"vb": ".vb",
83+
"wgsl": ".wgsl",
84+
"xml": ".xml",
85+
"yaml": ".yaml",
86+
"ada": ".ada",
87+
"cobol": ".cob",
88+
"d": ".d",
89+
"erlang": ".erl",
90+
"fortran": ".f",
91+
"groovy": ".groovy",
92+
"haskell": ".hs",
93+
"ocaml": ".ml",
94+
"octave": ".m",
95+
"racket": ".rkt",
96+
"sbcl": ".sbcl"
97+
}

components/App/Navbar/index.vue

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<template>
22
<header
3-
class="border-b bg-gray-900 border-white/10 flex items-center justify-between gap-3"
3+
class="flex gap-3 justify-between items-center bg-gray-900 border-b border-white/10"
44
>
5-
<h1 class="font-bold tracking-wide flex items-center gap-2 px-4">
6-
<Icon class="h-5 w-5" name="i-lucide-chevron-right-square" /><span
5+
<h1 class="flex gap-2 items-center px-4 font-bold tracking-wide">
6+
<Icon class="w-5 h-5" name="i-lucide-chevron-right-square" /><span
77
>CODESHARE</span
88
>
99
</h1>
@@ -15,27 +15,27 @@
1515
/>
1616
<span v-else class="text-xs">{{ title }}</span>
1717
<div
18-
class="border-l divide-x divide-white/10 border-white/10 flex items-center"
18+
class="flex items-center border-l divide-x divide-white/10 border-white/10"
1919
>
2020
<UTooltip text="Download file" @click="$emit('download')">
21-
<button class="border-white/10 h-9 px-3 text-sm hover:bg-gray-950">
22-
<Icon name="i-lucide-download" class="h-4 w-4" />
21+
<button class="px-3 h-9 text-sm border-white/10 hover:bg-gray-950">
22+
<Icon name="i-lucide-download" class="w-4 h-4" />
2323
</button>
2424
</UTooltip>
2525
<UTooltip text="Copy code">
2626
<button
2727
@click="$emit('copy')"
28-
class="border-white/10 h-9 px-3 text-sm hover:bg-gray-950"
28+
class="px-3 h-9 text-sm border-white/10 hover:bg-gray-950"
2929
>
30-
<Icon name="i-lucide-copy" class="h-4 w-4" />
30+
<Icon name="i-lucide-copy" class="w-4 h-4" />
3131
</button>
3232
</UTooltip>
3333
<UTooltip v-if="publishEnabled" text="Publish">
3434
<button
3535
@click="$emit('publish')"
36-
class="border-white/10 h-9 px-3 text-sm hover:bg-gray-950"
36+
class="px-3 h-9 text-sm border-white/10 hover:bg-gray-950"
3737
>
38-
<Icon name="i-lucide-external-link" class="h-4 w-4" />
38+
<Icon name="i-lucide-external-link" class="w-4 h-4" />
3939
</button>
4040
</UTooltip>
4141
</div>

composables/editor.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import githubTheme from "@/assets/github-dark.json";
22
import languages from "@/assets/languages";
3+
import fileExtensions from "@/assets/file-extensions";
34

45
export const useEditor = () => {
56
const { copy } = useClipboard();
@@ -22,7 +23,7 @@ export const useEditor = () => {
2223
},
2324
inlineSuggest: {
2425
enabled: true,
25-
showToolbar: 'always'
26+
showToolbar: "always",
2627
},
2728
});
2829
const snippet = useState("snippet", () => {
@@ -32,13 +33,22 @@ export const useEditor = () => {
3233
language: "plaintext",
3334
};
3435
});
36+
3537
const confirmationModal = ref(false);
3638
const loading = ref(false);
3739
const toast = useToast();
3840
const selectedLanguage = ref("plaintext");
3941
const lineCount = ref(0);
4042
const editorRef = shallowRef();
4143

44+
watchEffect(() => {
45+
const language = snippet.value.language;
46+
if (fileExtensions[language]) {
47+
const originalFilename = snippet.value.title.split('.')[0];
48+
snippet.value.title = `${originalFilename}${fileExtensions[language]}`;
49+
}
50+
});
51+
4252
const handleMount = (editor, monaco) => {
4353
editorRef.value = editor;
4454
monaco.editor.defineTheme("github-dark", githubTheme);
@@ -89,7 +99,7 @@ export const useEditor = () => {
8999
const confirmPublish = async () => {
90100
try {
91101
loading.value = true;
92-
102+
93103
const data = await $fetch("/api/codebin", {
94104
method: "POST",
95105
body: snippet.value,
@@ -108,7 +118,7 @@ export const useEditor = () => {
108118
navigateTo(`/${data.uid}`);
109119
} catch (error) {
110120
loading.value = false;
111-
console.log(error.statusMessage)
121+
console.log(error.statusMessage);
112122
toast.add({
113123
title: "Error",
114124
description: error.statusMessage || error.message,
@@ -123,7 +133,7 @@ export const useEditor = () => {
123133
type: "text/plain;charset=utf-8",
124134
});
125135
saveAs(blob, snippet.value.title || "untitled.txt");
126-
}
136+
};
127137

128138
function saveAs(blob, fileName) {
129139
const link = document.createElement("a");
@@ -151,6 +161,6 @@ export const useEditor = () => {
151161
publishSnippet,
152162
confirmPublish,
153163
copySnippet,
154-
downloadSnippet
164+
downloadSnippet,
155165
};
156166
};

pages/[id].vue

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<template>
2-
<main class="h-screen flex flex-col text-white">
2+
<main class="flex flex-col h-screen text-white">
33
<AppNavbar
44
@publish="publishSnippet"
55
@copy="copySnippet"
66
@download="downloadSnippet"
77
:publish-enabled="false"
88
:title="snippet.title"
99
/>
10-
<div class="flex-1 flex">
10+
<div class="flex flex-1">
1111
<AppSidebar />
1212
<ClientOnly>
1313
<vue-monaco-editor
@@ -20,15 +20,15 @@
2020
@change="onChange"
2121
>
2222
<template #default>
23-
<div class="flex items-center justify-center">
23+
<div class="flex justify-center items-center">
2424
<div class="text-gray-500">Loading editor...</div>
2525
</div>
2626
</template>
2727
</vue-monaco-editor>
2828
</ClientOnly>
2929
</div>
3030
<footer
31-
class="border-t bg-gray-900 border-white/10 flex items-center justify-between"
31+
class="flex justify-between items-center bg-gray-900 border-t border-white/10"
3232
>
3333
<div
3434
class="flex items-center divide-x divide-white/10 text-xs [&>div]:p-2 border-r border-white/10"
@@ -47,7 +47,7 @@
4747
</div>
4848
</div>
4949
<div
50-
class="flex items-center divide-x divide-white/10 text-xs border-l border-white/10"
50+
class="flex items-center text-xs border-l divide-x divide-white/10 border-white/10"
5151
>
5252
<UTooltip
5353
:text="`Toggle minimap (${
@@ -61,7 +61,7 @@
6161
@click="toggleMinimap"
6262
:disabled="!editorRef"
6363
>
64-
<Icon name="i-heroicons-map" class="h-4 w-4" />
64+
<Icon name="i-heroicons-map" class="w-4 h-4" />
6565
</button>
6666
</UTooltip>
6767
<UTooltip
@@ -74,7 +74,7 @@
7474
@click="formatCode"
7575
:disabled="!editorRef"
7676
>
77-
<Icon name="i-lucide-sparkles" class="h-4 w-4" />
77+
<Icon name="i-lucide-sparkles" class="w-4 h-4" />
7878
</button>
7979
</UTooltip>
8080
<USelectMenu
@@ -91,7 +91,7 @@
9191
<UModal v-model="confirmationModal">
9292
<div class="p-4 space-y-4">
9393
<p>Publish code</p>
94-
<UFormGroup label="Email">
94+
<UFormGroup label="File name">
9595
<UInput size="lg" placeholder="File name" v-model="snippet.title" />
9696
</UFormGroup>
9797
<UAlert

0 commit comments

Comments
 (0)