Skip to content

Commit

Permalink
fixed build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Strahinja2112 committed May 27, 2024
1 parent 8643da2 commit 14a050c
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 51 deletions.
10 changes: 5 additions & 5 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function createWindow(): void {
}
}

app.whenReady().then((): void => {
app.whenReady().then(() => {
electronApp.setAppUserModelId("com.electron");

app.on("browser-window-created", (_, window) => {
Expand All @@ -55,18 +55,18 @@ app.whenReady().then((): void => {
handleWindowEvents();
createWindow();

app.on("activate", (): void => {
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
});

app.on("window-all-closed", (): void => {
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});

function handleNoteEvents(): void {
function handleNoteEvents() {
ipcMain.handle("getNotes", (_, ...args: Parameters<TGetNotes>) => getNotes(...args));
ipcMain.handle("readNoteData", (_, ...args: Parameters<TReadNoteData>) => readNoteData(...args));
ipcMain.handle("saveNote", (_, ...args: Parameters<TSaveNote>) => saveNote(...args));
Expand All @@ -76,7 +76,7 @@ function handleNoteEvents(): void {
ipcMain.handle("openInShell", (_, path) => shell.openPath(path + "\\"));
}

function handleWindowEvents(): void {
function handleWindowEvents() {
ipcMain.handle("closeWindow", () => app.quit());
ipcMain.handle("minimizeWindow", () => mainWindow?.minimize());
ipcMain.handle("maximizeWindow", () => {
Expand Down
6 changes: 3 additions & 3 deletions src/main/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { appDirectoryName, fileEncoding, startingNoteData } from "@shared/constants";
import { FileData, FileOrFolderData, NoteInfo } from "@shared/types";
import { dialog } from "electron";
import { ensureDir, readFile, readdir, remove, stat, writeFile } from "fs-extra";
import { homedir } from "os";
import { appDirectoryName, fileEncoding, startingNoteData } from "../../shared/constants";
import { FileData, FileOrFolderData, TNoteInfo } from "../../shared/types";

type FileOrFolder =
| string
Expand Down Expand Up @@ -48,7 +48,7 @@ async function readAllFilesAndFolders(path: string, extension?: string): Promise
}
}

async function getNoteInfo(filePath: string): Promise<TNoteInfo> {
async function getNoteInfo(filePath: string): Promise<NoteInfo> {
const fileStats = await stat(filePath);

const filePathParts = filePath.split("\\");
Expand Down
4 changes: 2 additions & 2 deletions src/preload/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { TGetNotes, TReadNoteData, TSaveNote } from "@shared/types";
import { IWindowContextAPI } from "../shared/types";
import { WindowContextAPI } from "../shared/types";

declare global {
interface Window {
context: IWindowContextAPI;
context: WindowContextAPI;
}
}
5 changes: 1 addition & 4 deletions src/renderer/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { mainComponents } from "@shared/constants";
import { useRef } from "react";
import { Toaster } from "react-hot-toast";
import Editor from "./components/Editor";
Expand All @@ -14,8 +13,6 @@ export default function App() {
const { filesAndFolders } = useNotes();
const { location } = useLocation();

const MainComp = mainComponents[location];

return (
<RootLayout>
<Toaster
Expand All @@ -28,7 +25,7 @@ export default function App() {
position: "bottom-left"
}}
/>
{MainComp ? <MainComp /> : <>NO FOUND</>}
{location === "main" ? <Editor /> : <Settings />}
{filesAndFolders.length > 0 ? (
<Sidebar
onSelect={() => {
Expand Down
8 changes: 2 additions & 6 deletions src/renderer/src/assets/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
@tailwind components;
@tailwind utilities;

.glass {
}

@layer base {
:root {
--background: 240 10% 3.9%;
Expand Down Expand Up @@ -40,10 +37,9 @@
#root {
@apply h-screen;
background-color: transparent !important;
opacity: 0.99;
/* opacity: 0.99; */
border-radius: 10px;
overflow: hidden;
backdrop-filter: blur(11px);
-webkit-backdrop-filter: blur(11px);
}

::-webkit-scrollbar {
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/src/components/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const links = [
{
icon: Book,
title: "Learn more about the project",
href: "https://strahinja.vercel.app/projects/notemanager",
href: "https://strahinja.vercel.app/project/notemanager",
hidden: true
}
];
Expand All @@ -32,7 +32,7 @@ export default function Settings({}: Props) {
const { setLocation } = useLocation();
return (
<main className="flex-1 relative bg-zinc-900/40 p-4 md:p-6 flex flex-col items-center justify-center rounded-none">
<X className="absolute top-2 right-2 cursor-pointer" onClick={() => setLocation("editor")} />
<X className="absolute top-2 right-2 cursor-pointer" onClick={() => setLocation("main")} />
<div className="flex flex-col items-center justify-center h-screen space-y-10">
<div className="space-y-2 flex border-b items-center pb-2 justify-center flex-col">
<h1 className="text-3xl font-bold">Note Manager</h1>
Expand All @@ -52,7 +52,7 @@ export default function Settings({}: Props) {
<link.icon className="text-muted-foreground" />
<div className="flex flex-col">
<h2 className="text-xl">{link.title}</h2>
{link.hidden ? null : <p className="text-zinc-600 text-sm">{link.href}</p>}
{!link.hidden ? <p className="text-zinc-600">{link.href}</p> : null}
</div>
</div>
<ArrowRightIcon className="h-6 w-6 text-gray-500 dark:text-gray-400 hover:translate-x-2 transform transition-all duration-200 ease-in-out" />
Expand Down
14 changes: 8 additions & 6 deletions src/renderer/src/hooks/useLocation.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { TRoute } from "@shared/types";
import { PossibleLocations } from "@shared/types";
import { create } from "zustand";

export const useLocation = create<{
location: TRoute;
setLocation(newLocation: TRoute): void;
}>((set) => ({
location: "editor",
type TLocation = {
location: PossibleLocations;
setLocation(newLocation: PossibleLocations): void;
};

export const useLocation = create<TLocation>((set) => ({
location: "main",
setLocation(newLocation) {
set({
location: newLocation
Expand Down
8 changes: 0 additions & 8 deletions src/shared/constants.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import Settings from "@renderer/components/Settings";
import Editor from "../renderer/src/components/Editor";
import { TRoute } from "./types";

export const appDirectoryName = "notemark_data";
export const fileEncoding = "utf8";
export const startingNoteData = `## Welcome to NoteManager!
- You can edit this note now!
- You can click on the title in the header to change it's name!`;
export const myRepoLink = `https://github.com/strahinja2112/`;
export const projectRepoLink = myRepoLink + "note-manager/";
export const mainComponents: Record<TRoute, (params: any) => JSX.Element> = {
editor: Editor,
settings: Settings
};
30 changes: 18 additions & 12 deletions src/shared/types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { deleteNote, getNotes, readNoteData, renameNote, saveNote } from "src/main/lib";

export type TNoteInfo = {
export type NoteInfo = {
title: string;
lastEditTime: number;
};

export type TRoute = "editor" | "settings";
export type PossibleLocations = "main" | "settings";

export interface IWindowContextAPI {
export type TGetNotes = typeof getNotes;
export type TReadNoteData = typeof readNoteData;
export type TSaveNote = typeof saveNote;
export type TRenameNote = typeof renameNote;
export type TDeleteNote = typeof deleteNote;

export type WindowContextAPI = {
locale: string;
windowActions: {
close(): void;
Expand All @@ -16,20 +22,20 @@ export interface IWindowContextAPI {
};
getRootDir: () => Promise<string>;
openInShell: (path: string) => void;
getNotes: typeof getNotes;
readNoteData: typeof readNoteData;
saveNote: typeof saveNote;
renameNote: typeof renameNote;
deleteNote: typeof deleteNote;
}

export type FileData = TNoteInfo & {
getNotes: TGetNotes;
readNoteData: TReadNoteData;
saveNote: TSaveNote;
renameNote: TRenameNote;
deleteNote: TDeleteNote;
};

export type FileData = NoteInfo & {
type: "file";
fullPath: string;
content?: string;
};

export type FolderData = TNoteInfo & {
export type FolderData = NoteInfo & {
type: "folder";
title: string;
fullPath: string;
Expand Down
56 changes: 56 additions & 0 deletions test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[
{
"type": "file",
"title": "Note2",
"lastEditTime": 1706050090392.7107
},
{
"type": "file",
"title": "Test2",
"lastEditTime": 1706195432988.4136
},
{
"type": "folder",
"title": "folder",
"data": [
{
"type": "folder",
"title": "another_folder",
"data": [
{
"type": "file",
"title": "ope",
"lastEditTime": 1706196478539.8796
}
]
},
{
"type": "file",
"title": "open",
"lastEditTime": 1706196478539.8796
}
]
},
{
"type": "folder",
"title": "folder - Copy",
"data": [
{
"type": "folder",
"title": "another_folder",
"data": [
{
"type": "file",
"title": "ope",
"lastEditTime": 1706196478539.8796
}
]
},
{
"type": "file",
"title": "open",
"lastEditTime": 1706196478539.8796
}
]
}
]
2 changes: 1 addition & 1 deletion tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"src/main/**/*",
"src/preload/*",
"src/shared/**/*"
, "src/shared/types.ts", "src/shared/constants.ts" ],
],
"compilerOptions": {
"composite": true,
"types": [
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.web.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"src/renderer/src/**/*.tsx",
"src/preload/*.d.ts",
"src/shared/**/*",
"src/main/**/*", "src/shared/types.ts", "src/shared/constants.ts",
"src/main/**/*",
],
"compilerOptions": {
"composite": true,
Expand Down

0 comments on commit 14a050c

Please sign in to comment.