aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/App.tsx5
-rw-r--r--src/components/OllamaCommandPallete.tsx14
-rw-r--r--src/components/PromptAI.tsx8
-rw-r--r--src/index.css62
-rw-r--r--src/ollama.tsx25
5 files changed, 78 insertions, 36 deletions
diff --git a/src/App.tsx b/src/App.tsx
index 230bc80..6ec660a 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -10,10 +10,11 @@ import { useAppVisible } from "./utils";
const options = [
'Ask ai',
- 'Ask with context',
+ 'Ask with page context',
+ 'Ask with block context',
'Define',
'Divide into subtasks',
- 'Summarize',
+ 'Summarize Page',
'Summarize Block',
'Convert to flash card',
];
diff --git a/src/components/OllamaCommandPallete.tsx b/src/components/OllamaCommandPallete.tsx
index e8e9c42..dabdc9b 100644
--- a/src/components/OllamaCommandPallete.tsx
+++ b/src/components/OllamaCommandPallete.tsx
@@ -6,7 +6,7 @@ import {
CommandItem,
CommandList,
} from "@/components/ui/command"
-import { convertToFlashCardCurrentBlock, DivideTaskIntoSubTasksCurrentBlock, summarize, summarizeBlock } from "@/ollama";
+import { convertToFlashCardCurrentBlock, DivideTaskIntoSubTasksCurrentBlock, summarizePage, summarizeBlock } from "@/ollama";
import { PromptAI } from "./PromptAI";
export function OllamaCommandPallete({ options, theme }: { options: string[], theme: string }) {
@@ -20,9 +20,9 @@ export function OllamaCommandPallete({ options, theme }: { options: string[], th
logseq.hideMainUI()
DivideTaskIntoSubTasksCurrentBlock()
break;
- case "summarize":
+ case "summarize page":
logseq.hideMainUI()
- summarize()
+ summarizePage()
break;
case "summarize block":
logseq.hideMainUI()
@@ -51,12 +51,14 @@ export function OllamaCommandPallete({ options, theme }: { options: string[], th
};
}, []);
- if (isEnterPressed && (selection !== 'ask ai' && selection !== 'define' && selection !== 'ask with context')) {
- return null
+ const validSelections = ['ask with page context', 'ask with block context', 'ask ai', 'define', 'ask with context'];
+
+ if (isEnterPressed && !validSelections.includes(selection)) {
+ return null;
}
return (
- selection === 'ask with context' || selection === 'ask ai' || selection === 'define' ? (<PromptAI theme={theme} type={selection} />) : (
+ validSelections.includes(selection) ? (<PromptAI theme={theme} type={selection} />) : (
<Command className={(theme === 'dark' ? "dark dark:bg-gray-900" : "bg-gray-200") + " rounded-lg border shadow-md w-1/2"}>
<CommandInput className="ai-input" placeholder="Type a command or search..." />
<CommandList>
diff --git a/src/components/PromptAI.tsx b/src/components/PromptAI.tsx
index 5fb9942..6b4616d 100644
--- a/src/components/PromptAI.tsx
+++ b/src/components/PromptAI.tsx
@@ -4,7 +4,7 @@ import { Input } from '@/components/ui/input';
export const PromptAI = ({ type, theme }: { type: string, theme: string }) => {
- const placeholder = type === 'ask ai' ? "Prompt..." : "Define..."
+ const placeholder = type.startsWith('ask') ? "Prompt..." : "Define..."
const [inputValue, setInputValue] = useState('');
const [hitEnter, setHitEnter] = useState(false)
@@ -15,8 +15,10 @@ export const PromptAI = ({ type, theme }: { type: string, theme: string }) => {
askAI(inputValue, "")
} else if (type === 'define') {
defineWord(inputValue)
- } else if (type === 'ask with context') {
- askWithContext(inputValue)
+ } else if (type === 'ask with page context') {
+ askWithContext(inputValue, 'page')
+ } else if (type === 'ask with block context') {
+ askWithContext(inputValue, 'block')
}
}
}, [hitEnter])
diff --git a/src/index.css b/src/index.css
index a20f5ca..68c8203 100644
--- a/src/index.css
+++ b/src/index.css
@@ -1,7 +1,7 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
-
+
@layer base {
:root {
--background: 0 0% 100%;
@@ -9,68 +9,94 @@
--card: 0 0% 100%;
--card-foreground: 222.2 84% 4.9%;
-
+
--popover: 0 0% 100%;
--popover-foreground: 222.2 84% 4.9%;
-
+
--primary: 222.2 47.4% 11.2%;
--primary-foreground: 210 40% 98%;
-
+
--secondary: 210 40% 96.1%;
--secondary-foreground: 222.2 47.4% 11.2%;
-
+
--muted: 210 40% 96.1%;
--muted-foreground: 215.4 16.3% 46.9%;
-
+
--accent: 210 40% 96.1%;
--accent-foreground: 222.2 47.4% 11.2%;
-
+
--destructive: 0 84.2% 60.2%;
--destructive-foreground: 210 40% 98%;
--border: 214.3 31.8% 91.4%;
--input: 214.3 31.8% 91.4%;
--ring: 222.2 84% 4.9%;
-
+
--radius: 0.5rem;
}
-
+
.dark {
--background: 222.2 84% 4.9%;
--foreground: 210 40% 98%;
-
+
--card: 222.2 84% 4.9%;
--card-foreground: 210 40% 98%;
-
+
--popover: 222.2 84% 4.9%;
--popover-foreground: 210 40% 98%;
-
+
--primary: 210 40% 98%;
--primary-foreground: 222.2 47.4% 11.2%;
-
+
--secondary: 217.2 32.6% 17.5%;
--secondary-foreground: 210 40% 98%;
-
+
--muted: 217.2 32.6% 17.5%;
--muted-foreground: 215 20.2% 65.1%;
-
+
--accent: 217.2 32.6% 17.5%;
--accent-foreground: 210 40% 98%;
-
+
--destructive: 0 62.8% 30.6%;
--destructive-foreground: 210 40% 98%;
-
+
--border: 217.2 32.6% 17.5%;
--input: 217.2 32.6% 17.5%;
--ring: 212.7 26.8% 83.9%;
}
}
-
+
@layer base {
* {
@apply border-border;
}
+
/* body { */
/* @apply bg-background text-foreground; */
/* } */
}
+
+
+/* Custom scrollbar styles */
+/* Works in Firefox, Chrome, Edge, Safari */
+
+/* Track */
+::-webkit-scrollbar {
+ width: 10px;
+ border-radius: 5px;
+ /* Adjust to make scrollbar rounded */
+ background-color: #000000;
+ /* Gray background color */
+}
+
+/* Handle */
+::-webkit-scrollbar-thumb {
+ background: #808080;
+ border-radius: 5px;
+ /* Adjust to make scrollbar thumb rounded */
+}
+
+/* Handle on hover */
+::-webkit-scrollbar-thumb:hover {
+ background: #555;
+}
diff --git a/src/ollama.tsx b/src/ollama.tsx
index e59c633..c0c27e2 100644
--- a/src/ollama.tsx
+++ b/src/ollama.tsx
@@ -134,16 +134,22 @@ async function promptLLM(prompt: string) {
}
export async function defineWord(word: string) {
- askAI(`What's the defintion of ${word}`, "")
+ askAI(`What's the defintion of ${word}?`, "")
}
+type ContextType = 'block' | 'page'
-export async function askWithContext(prompt: string) {
+export async function askWithContext(prompt: string, contextType: ContextType) {
try {
- const currentBlocksTree = await logseq.Editor.getCurrentPageBlocksTree()
let blocksContent = ""
- for (const block of currentBlocksTree) {
- blocksContent += await getTreeContent(block)
+ if (contextType === 'page') {
+ const currentBlocksTree = await logseq.Editor.getCurrentPageBlocksTree()
+ for (const block of currentBlocksTree) {
+ blocksContent += await getTreeContent(block)
+ }
+ } else {
+ const currentBlock = await logseq.Editor.getCurrentBlock()
+ blocksContent += await getTreeContent(currentBlock!)
}
askAI(prompt, `Context: ${blocksContent}`)
} catch (e: any) {
@@ -152,7 +158,7 @@ export async function askWithContext(prompt: string) {
}
}
-export async function summarize() {
+export async function summarizePage() {
await delay(300)
try {
const currentSelectedBlocks = await logseq.Editor.getCurrentPageBlocksTree()
@@ -247,7 +253,12 @@ export async function askAI(prompt: string, context: string) {
await delay(300)
try {
const currentBlock = await logseq.Editor.getCurrentBlock()
- const block = await logseq.Editor.insertBlock(currentBlock!.uuid, '⌛Generating....', { before: true })
+ let block = null;
+ if (currentBlock?.content.trim() === '') {
+ block = await logseq.Editor.insertBlock(currentBlock!.uuid, '⌛Generating....', { before: true })
+ } else {
+ block = await logseq.Editor.insertBlock(currentBlock!.uuid, '⌛Generating....', { before: false })
+ }
let response = "";
if (context == "") {
response = await promptLLM(prompt)