From 121becd9cf52c735e2d33032873fca8fc6e3db54 Mon Sep 17 00:00:00 2001 From: omagdy7 Date: Sun, 5 Nov 2023 22:22:37 +0200 Subject: Added all the main features of the plugin and also added setting and made the plugin respect themeing --- src/App.tsx | 51 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 15 deletions(-) (limited to 'src/App.tsx') diff --git a/src/App.tsx b/src/App.tsx index 5b5fca0..c88108d 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,30 +1,51 @@ +import { AppUserInfo } from "@logseq/libs/dist/LSPlugin"; import React, { useEffect, useRef, useState } from "react"; -import CommandPalette from "./components/CommandPallete"; +import { OllamaCommandPallete } from "./components/OllamaCommandPallete"; +import { convertToFlashCardFromEvent, DivideTaskIntoSubTasksFromEvent, ollamaUI } from "./ollama"; import { useAppVisible } from "./utils"; const options = [ - { label: 'Ask Ai' }, - { label: 'Define' }, - { label: 'Divide into subtasks' }, - { label: 'Summarize' }, + 'Ask ai', + 'Ask with context', + 'Define', + 'Divide into subtasks', + 'Summarize', + 'Convert to flash card', ]; - -async function ollamaUI() { - console.log("Hello") - logseq.showMainUI({ autoFocus: true }) - setTimeout(() => { - document.getElementById("ai-input")?.focus() - console.log(document.getElementById("ai-input")) - }, 300) +async function getTheme() { + const theme = await logseq.App.getUserInfo() + if (!theme) { + return "dark" + } + return theme.preferredThemeMode } function App() { const innerRef = useRef(null); const visible = useAppVisible(); + const [theme, setTheme] = useState('') useEffect(() => { + const getTheme = async () => { + const theme = await logseq.App.getUserConfigs() + if (!theme) { + setTheme('dark') + } else { + setTheme(theme.preferredThemeMode) + } + } + getTheme(); + if (!logseq.settings) { + return + } logseq.Editor.registerSlashCommand("ollama", ollamaUI) + logseq.Editor.registerBlockContextMenuItem("Create a flash card", convertToFlashCardFromEvent) + logseq.Editor.registerBlockContextMenuItem("Make task into subtasks", DivideTaskIntoSubTasksFromEvent) + logseq.App.registerCommandShortcut( + { "binding": logseq.settings.shortcut }, + ollamaUI + ); }, []) if (visible) { @@ -37,8 +58,8 @@ function App() { } }} > -
- +
+
); -- cgit v1.2.3