Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: toast and disable buttons issue in search pipe #1157

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified pipes/search/bun.lockb
Binary file not shown.
3 changes: 3 additions & 0 deletions pipes/search/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import "./globals.css";
import { Toaster } from "@/components/ui/toaster";

const geistSans = Geist({
variable: "--font-geist-sans",
Expand Down Expand Up @@ -29,6 +30,8 @@ export default function RootLayout({
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
{children}

<Toaster />
</body>
</html>
);
Expand Down
2 changes: 1 addition & 1 deletion pipes/search/src/components/example-search-cards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function ExampleSearchCards({ onSelect }: ExampleSearchCardsProps) {
}
};

const isHealthError = health?.status === "error";
const isHealthError = !health || health === null || health?.status === "error";

return (
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 mt-4">
Expand Down
31 changes: 26 additions & 5 deletions pipes/search/src/components/search-chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
SpeechIcon,
ChevronsUpDown,
} from "lucide-react";
import { useToast } from "@/components/ui/use-toast";
import { useToast } from "@/lib/use-toast";
import { AnimatePresence, motion } from "framer-motion";
import { generateId, Message } from "ai";
import { OpenAI } from "openai";
Expand Down Expand Up @@ -423,7 +423,18 @@ export function SearchChat() {
};
}, []);

const isAiDisabled =
!settings.user?.token && settings.aiProviderType === "screenpipe-cloud";

const handleExampleSelect = async (example: ExampleSearch) => {
if (isAiDisabled){
toast({
title: "error",
description: "your selected ai provider is screenpipe-cloud. consider login in app to use screenpipe-cloud",
variant: "destructive",
});
return;
}
const newWindowName = example.windowName || "";
const newAppName = example.appName || "";
const newLimit = example.limit || limit;
Expand Down Expand Up @@ -736,6 +747,15 @@ export function SearchChat() {
};

const handleSearch = async (newOffset = 0, overrides: any = {}) => {
if (isAiDisabled){
toast({
title: "error",
description: "your ai provider is screenpipe-cloud. consider login in app to use screenpipe-cloud",
duration: 3000,
variant: "destructive",
});
return;
}
await pipe.captureMainFeatureEvent("search", {
contentType: overrides.contentType || contentType,
limit: overrides.limit || limit,
Expand Down Expand Up @@ -1109,8 +1129,6 @@ export function SearchChat() {
// Add any other reset logic you need
};

const isAiDisabled =
!settings.user?.token && settings.aiProviderType === "screenpipe-cloud";

return (
<div className="w-full max-w-4xl mx-auto p-4 mt-12">
Expand Down Expand Up @@ -1269,7 +1287,9 @@ export function SearchChat() {
<span>
<Button
onClick={() => handleSearch(0)}
disabled={isLoading || !health || health?.status === "error"}
disabled={isLoading || !health ||
health === null || health?.status === "error"}
className="disabled:cursor-not-allowed"
>
{isLoading ? (
<>
Expand All @@ -1285,7 +1305,8 @@ export function SearchChat() {
</Button>
</span>
</TooltipTrigger>
{health?.status === "error" && (
{!health || health === null
|| health?.status === "error" && (
<TooltipContent>
<p>screenpipe is not running...</p>
</TooltipContent>
Expand Down
2 changes: 1 addition & 1 deletion pipes/search/src/components/ui/toaster.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client"

import { useToast } from "@/components/ui/use-toast"
import { useToast } from "@/lib/use-toast"
import {
Toast,
ToastClose,
Expand Down
Loading