From b1c4e02d675976b4be78aeb2b9b9a5241d767fe0 Mon Sep 17 00:00:00 2001 From: samlhuillier Date: Thu, 30 Nov 2023 15:45:23 -0600 Subject: [PATCH] beautify considerably the directory picker component --- electron/main/index.ts | 26 +----- src/components/File/DirectoryPicker.tsx | 111 +++++++++++++++++++++--- src/components/Generic/Modal.tsx | 26 ++++-- 3 files changed, 117 insertions(+), 46 deletions(-) diff --git a/electron/main/index.ts b/electron/main/index.ts index 92d53250..45827f8e 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -6,39 +6,17 @@ import Store from "electron-store"; import * as path from "path"; import * as fs from "fs"; import { StoreKeys, StoreSchema } from "./Config/storeConfig"; -import { - LlamaCPPModelLoader, - LlamaCPPSessionService, -} from "./llm/models/LlamaCpp"; + import * as lancedb from "vectordb"; + import { - Field, - type FixedSizeListBuilder, - Float32, - makeBuilder, - RecordBatchFileWriter, - Utf8, - Int32, - type Vector, - FixedSizeList, - vectorFromArray, - Schema, - Table as ArrowTable, - RecordBatchStreamWriter, - Float64, -} from "apache-arrow"; -import { DatabaseFields } from "./database/Schema"; -import { - RagnoteDBEntry, RagnoteTable, maybeRePopulateTable, updateNoteInTable, } from "./database/Table"; import { FSWatcher } from "fs"; -import chokidar from "chokidar"; import { GetFilesInfoTree, - moveFileOrDirectoryInFileSystem, orchestrateEntryMove, startWatchingDirectory, updateFileListForRenderer, diff --git a/src/components/File/DirectoryPicker.tsx b/src/components/File/DirectoryPicker.tsx index 1016c42c..3acdc6da 100644 --- a/src/components/File/DirectoryPicker.tsx +++ b/src/components/File/DirectoryPicker.tsx @@ -1,30 +1,115 @@ // import React from "react"; +import { useEffect, useState } from "react"; +import Modal from "../Generic/Modal"; +import { Button } from "@material-tailwind/react"; + interface Props { onDirectorySelected: (path: string) => void; } const DirectoryPicker: React.FC = ({ onDirectorySelected }) => { + const [isModalOpen, setIsModalOpen] = useState(true); + const [openAIKey, setOpenAIKey] = useState(""); + const [userDirectory, setUserDirectory] = useState(""); + + useEffect(() => { + const key = window.electronStore.getOpenAIAPIKey() || ""; // Fallback to empty string if undefined + setOpenAIKey(key); + }, []); + + const handleNext = () => { + window.electronStore.setOpenAIAPIKey(openAIKey); + if (userDirectory) { + window.electronStore.setUserDirectory(userDirectory); + onDirectorySelected(userDirectory); + } + }; + const handleDirectorySelection = async () => { const path = await window.files.openDirectoryDialog(); if (path) { - window.electronStore.setUserDirectory(path); - onDirectorySelected(path); + setUserDirectory(path); + // window.electronStore.setUserDirectory(path); + // onDirectorySelected(path); + } + }; + const handleKeyPress = (e: React.KeyboardEvent) => { + if (e.key === "Enter") { + handleNext(); } }; return ( -
- - After you select a directory, files currently in the directory will be - indexed. This may take a while and we currently haven't implemented a - progress bar :) -
+ console.log("Not allowing a close for now")} + hideCloseButton={true} + > +
+
+

+ Welcome to the Reor Project. +

+

+ At its heart, this is a markdown editor with embedded AI. Everything + is written to a directory on your filesystem. Please choose that + directory here: +

+ + {userDirectory && ( +

+ Selected: {userDirectory} +

+ )} + +

Embedding Model

+ +

LLM

+ +

+ *Models are currently hardcoded (custom models are coming soon). +

+

Open AI Key

+ setOpenAIKey(e.target.value)} + onKeyDown={handleKeyPress} + placeholder="Note Name" + /> + + + {/*

+ *Models are currently hardcoded. Custom models are coming very soon + :) +

*/} +
+
+
); }; diff --git a/src/components/Generic/Modal.tsx b/src/components/Generic/Modal.tsx index 67becc42..dff85eba 100644 --- a/src/components/Generic/Modal.tsx +++ b/src/components/Generic/Modal.tsx @@ -4,9 +4,15 @@ interface ModalProps { isOpen: boolean; onClose: () => void; children: React.ReactNode; + hideCloseButton?: boolean; } -const Modal: React.FC = ({ isOpen, onClose, children }) => { +const Modal: React.FC = ({ + isOpen, + onClose, + children, + hideCloseButton, +}) => { const modalRef = useRef(null); const handleOffClick = (event: MouseEvent) => { @@ -33,14 +39,16 @@ const Modal: React.FC = ({ isOpen, onClose, children }) => { className="flex bg-gray-800 rounded-lg shadow-xl max-w-lg p-2" > {children} -
- -
+ {!hideCloseButton && ( +
+ +
+ )} );