Skip to content

Commit a3e621b

Browse files
committed
First Public Release
1 parent 271d5af commit a3e621b

File tree

10 files changed

+112
-352
lines changed

10 files changed

+112
-352
lines changed

package-lock.json

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"@types/node": "^20.11.30",
4343
"@types/react": "^18.2.15",
4444
"@types/react-dom": "^18.2.7",
45+
"@types/react-syntax-highlighter": "^15.5.13",
4546
"@vitejs/plugin-react": "^4.2.1",
4647
"autoprefixer": "^10.4.19",
4748
"postcss": "^8.4.38",

src-tauri/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
22
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
33

4-
use tauri::Manager;
54
use std::path::PathBuf;
65
use open;
76

src-tauri/tauri.conf.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
"beforeDevCommand": "npm run dev",
44
"beforeBuildCommand": "npm run build",
55
"devPath": "http://localhost:1420",
6-
"distDir": "../dist"
6+
"distDir": "../dist",
7+
"withGlobalTauri": true
78
},
89
"package": {
910
"productName": "SnipIt",
10-
"version": "0.0.0"
11+
"version": "1.0.0"
1112
},
1213
"tauri": {
1314
"allowlist": {

src/Settings.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@ export default function Settings() {
3232
}
3333
});
3434

35-
// Fetch the App Directory
3635
tauriPath.appDataDir().then((dir) => {
3736
setAppDirectory(dir);
3837
});
3938
}, []);
4039

4140
const handleFolderOpen = async (path: string) => {
4241
try {
43-
await invoke("open_folder", { path }); // Calling the Rust command
42+
await invoke("open_folder", { path });
4443
} catch (error) {
4544
console.error("Failed to open folder:", error);
4645
}
@@ -50,8 +49,12 @@ export default function Settings() {
5049
const handleChangeCollectionPath = async () => {
5150
try {
5251
const selected = await dialog.open({ directory: true });
53-
if (selected && typeof selected === "string") {
54-
const updatedSettings = { ...settings, collectionPath: selected };
52+
if (selected && typeof selected === "string" && settings) {
53+
const updatedSettings = {
54+
os: settings.os || "Unknown OS",
55+
firstStartup: settings.firstStartup || new Date().toISOString(),
56+
collectionPath: selected,
57+
};
5558
await saveSettings(updatedSettings);
5659
setSettings(updatedSettings);
5760
setCollectionPath(selected);
@@ -60,6 +63,7 @@ export default function Settings() {
6063
console.error("Failed to change collection path:", error);
6164
}
6265
};
66+
6367

6468
const renderSection = () => {
6569
switch (activeSection) {

src/SnipItsView.tsx

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { useState, useEffect } from "react";
2-
import * as DevIcons from "react-icons/di";
3-
import { languageIconMap } from "@/lib/languageIconMap";
42
import { Button } from "@/components/ui/button";
5-
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
3+
import { Card, CardContent, CardTitle } from "@/components/ui/card";
64
import { Copy, FileText, X, Search, Pencil, Trash, Sparkles, Folders, Star } from "lucide-react";
75
import { toast } from "sonner";
86
import { Input } from "@/components/ui/input";
@@ -13,7 +11,8 @@ import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
1311
import { tomorrow } from "react-syntax-highlighter/dist/esm/styles/prism";
1412
import { EditSnippet } from "./EditSnippet";
1513

16-
export const SnipItsView = ({ setActivePage }: { setActivePage: (page: string) => void }) => {
14+
type Page = "home" | "snipits" | "settings" | "newsnippet";
15+
export const SnipItsView = ({ setActivePage }: { setActivePage: React.Dispatch<React.SetStateAction<Page>> }) => {
1716
const [searchQuery, setSearchQuery] = useState("");
1817
const [filters, setFilters] = useState<string[]>([]);
1918
const [snippets, setSnippets] = useState<any[]>([]);
@@ -81,10 +80,10 @@ export const SnipItsView = ({ setActivePage }: { setActivePage: (page: string) =
8180
};
8281

8382
const toggleStar = async (snippet: any) => {
84-
snippet.starred = !snippet.starred; // Toggle the star status
83+
snippet.starred = !snippet.starred;
8584
try {
8685
await fs.writeTextFile(`${collectionPath}/${snippet.id}.json`, JSON.stringify(snippet, null, 2));
87-
await fetchSnippets(collectionPath); // Refresh snippets
86+
await fetchSnippets(collectionPath);
8887
toast.success(snippet.starred ? "Snippet starred." : "Snippet unstarred.");
8988
} catch (error) {
9089
console.error("Failed to update snippet:", error);
@@ -115,8 +114,6 @@ export const SnipItsView = ({ setActivePage }: { setActivePage: (page: string) =
115114

116115
return matchesSearch && matchesFilters;
117116
});
118-
119-
120117

121118
const handleDelete = async (id: string) => {
122119
try {
@@ -129,29 +126,18 @@ export const SnipItsView = ({ setActivePage }: { setActivePage: (page: string) =
129126
}
130127
};
131128

132-
const handleEdit = async (snippet: any) => {
133-
try {
134-
await fs.writeTextFile(`${collectionPath}/${snippet.id}.json`, JSON.stringify(snippet, null, 2));
135-
await fetchSnippets(collectionPath);
136-
toast.success("Snippet updated.");
137-
} catch (error) {
138-
console.error("Failed to update snippet:", error);
139-
toast.error("Failed to update snippet.");
140-
}
141-
};
142-
143129

144130
const handleEditClick = (id: string) => {
145-
setEditingSnippetId(id); // Set the snippet to be edited
131+
setEditingSnippetId(id);
146132
};
147133

148134
const handleSave = async () => {
149-
await fetchSnippets(collectionPath); // Refresh snippets after saving
150-
setEditingSnippetId(null); // Exit edit mode
135+
await fetchSnippets(collectionPath);
136+
setEditingSnippetId(null);
151137
};
152138

153139
const handleCancel = () => {
154-
setEditingSnippetId(null); // Exit edit mode without saving
140+
setEditingSnippetId(null);
155141
};
156142

157143
if (editingSnippetId) {
@@ -186,7 +172,7 @@ export const SnipItsView = ({ setActivePage }: { setActivePage: (page: string) =
186172
<div className="space-y-2">
187173
{availableLanguages.map((language) => {
188174
const normalizedLanguage = language.toLowerCase();
189-
const IconComponent = DevIcons[languageIconMap[normalizedLanguage]] || FileText;
175+
const IconComponent = FileText;
190176

191177
return (
192178
<Button

src/db/db.ts

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { join, appDataDir } from "@tauri-apps/api/path";
44
const SETTINGS_FILE = "settings.json";
55
const SNIPPET_FILE = `snippets/snippets.json`;
66

7+
78
async function getSettingsFilePath() {
89
const appDir = await appDataDir();
910
const settingsPath = await join(appDir, SETTINGS_FILE);
@@ -17,10 +18,9 @@ async function getSettingsFilePath() {
1718
}
1819

1920
async function getDbFilePath() {
20-
const appDir = await appDataDir(); // Get the system AppData path
21+
const appDir = await appDataDir();
2122
const dbPath = await join(appDir, SNIPPET_FILE);
2223

23-
// ✅ Ensure directory exists before writing
2424
const dirExists = await exists(appDir);
2525
if (!dirExists) {
2626
console.log(`Creating AppData directory: ${appDir}`);
@@ -30,15 +30,6 @@ async function getDbFilePath() {
3030
return dbPath;
3131
}
3232

33-
// ✅ Ensure `src/db/` directory exists
34-
async function ensureDbExists() {
35-
const path = await join(await appDataDir(), SNIPPET_FILE);
36-
if (!(await exists(path))) {
37-
await writeTextFile(path, "[]"); // Create empty JSON array
38-
}
39-
return path;
40-
}
41-
4233
export async function loadSettings() {
4334
try {
4435
const path = await getSettingsFilePath();
@@ -50,7 +41,6 @@ async function ensureDbExists() {
5041
}
5142
}
5243

53-
// ✅ Save Settings
5444
export async function saveSettings(settings: any) {
5545
try {
5646
const path = await getSettingsFilePath();
@@ -61,15 +51,14 @@ async function ensureDbExists() {
6151
}
6252
}
6353

64-
// ✅ Load Snippets from JSON File
6554
export async function loadSnippets() {
6655
try {
6756
const path = await getDbFilePath();
6857
console.log("Checking for snippets file at:", path);
6958

7059
if (!(await exists(path))) {
7160
console.log("No snippets file found, creating an empty one...");
72-
await writeTextFile(path, "[]"); // Create an empty JSON array
61+
await writeTextFile(path, "[]");
7362
return [];
7463
}
7564

@@ -82,7 +71,6 @@ export async function loadSnippets() {
8271
}
8372
}
8473

85-
// ✅ Save Snippets to JSON File
8674
export async function saveSnippets(snippets: any[]) {
8775
try {
8876
const path = await getDbFilePath();
@@ -92,29 +80,4 @@ export async function saveSnippets(snippets: any[]) {
9280
} catch (error) {
9381
console.error("❌ Error saving snippets:", error);
9482
}
95-
}
96-
97-
// ✅ Delete a Snippet
98-
export async function deleteSnippet(id: number) {
99-
const snippets = await loadSnippets();
100-
const updatedSnippets = snippets.filter((s) => s.id !== id);
101-
await saveSnippets(updatedSnippets);
102-
}
103-
104-
// ✅ Update (Edit) a Snippet
105-
export async function updateSnippet(updatedSnippet: any) {
106-
const snippets = await loadSnippets();
107-
const index = snippets.findIndex((s) => s.id === updatedSnippet.id);
108-
if (index !== -1) {
109-
snippets[index] = updatedSnippet;
110-
await saveSnippets(snippets);
111-
}
112-
}
113-
114-
// ✅ Add a New Snippet
115-
export async function addSnippet(newSnippet: any) {
116-
const snippets = await loadSnippets();
117-
newSnippet.id = snippets.length ? Math.max(...snippets.map((s) => s.id)) + 1 : 1;
118-
snippets.push(newSnippet);
119-
await saveSnippets(snippets);
120-
}
83+
}

src/lib/languageIconMap.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/modules.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// src/react-syntax-highlighter.d.ts
2+
declare module "react-syntax-highlighter/dist/esm/styles/prism";
3+
declare module "react-syntax-highlighter";
4+
declare module "lang-detector";

0 commit comments

Comments
 (0)