Skip to content

A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.

feat: useInvestigationStore

dextmorgn5d1513f36edf
diff --git a/package.json b/package.json
index 88885155..fedab9e3 100644
--- a/package.json
+++ b/package.json
@@ -67,6 +67,7 @@
"next": "15.1.6",
"next-themes": "^0.4.4",
"nextjs-toploader": "^3.7.15",
+ "nuqs": "^2.4.0",
"popover": "^2.4.1",
"postcss": "^8.5.1",
"react": "^19.0.0",
diff --git a/src/app/investigations/[investigation_id]/layout.tsx b/src/app/investigations/[investigation_id]/layout.tsx
index c7d0bb74..772f124e 100644
--- a/src/app/investigations/[investigation_id]/layout.tsx
+++ b/src/app/investigations/[investigation_id]/layout.tsx
@@ -6,9 +6,6 @@ import { createClient } from "@/lib/supabase/server";
import { notFound, redirect } from "next/navigation";
import { ChatProvider } from '@/components/contexts/chatbot-context';
import { getInvestigation } from '@/lib/actions/investigations';
-import { SidebarProvider } from '@/components/ui/sidebar';
-import { AppSidebar } from '@/components/app-sidebar';
-
const DashboardLayout = async ({
children,
params,
diff --git a/src/app/investigations/[investigation_id]/left.tsx b/src/app/investigations/[investigation_id]/left.tsx
index 39c3640f..3b59329c 100644
--- a/src/app/investigations/[investigation_id]/left.tsx
+++ b/src/app/investigations/[investigation_id]/left.tsx
@@ -1,138 +1,166 @@
"use client"
-import React from 'react'
-import { Skeleton } from '@/components/ui/skeleton';
-import { useIndividuals } from '@/lib/hooks/investigation/use-individuals';
-import { cn } from '@/lib/utils';
-import { AtSignIcon, PhoneIcon, UserIcon } from 'lucide-react';
-import { useEmails } from '@/lib/hooks/investigation/use-emails';
-import { usePhones } from '@/lib/hooks/investigation/use-phones';
-import { useSocials } from '@/lib/hooks/investigation/use-socials';
-import {
- Accordion,
- AccordionContent,
- AccordionItem,
- AccordionTrigger,
-} from "@/components/ui/accordion"
-import { useFlowStore } from '@/components/contexts/use-flow-store';
-import { usePlatformIcons } from '@/lib/hooks/use-platform-icons';
-
+import { Skeleton } from "@/components/ui/skeleton"
+import { cn } from "@/lib/utils"
+import { AtSignIcon, PhoneIcon, UserIcon } from "lucide-react"
+import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion"
+import { useInvestigationStore, useInvestigationData } from "@/store/investigation-store"
+import { usePlatformIcons } from "@/lib/hooks/use-platform-icons"
+import { useFlowStore } from "@/store/flow-store"
const Left = ({ investigation_id }: { investigation_id: string }) => {
- const { individuals, isLoading: isLoadingIndividuals, refetch: refetchIndividuals } = useIndividuals(investigation_id)
- const { emails, isLoading: isLoadingEmails, refetch: refetchEmails } = useEmails(investigation_id)
- const { phones, isLoading: isLoadingPhones, refetch: refetchPhones } = usePhones(investigation_id)
- const { socials, isLoading: isLoadingSocials, refetch: refetchSocials } = useSocials(investigation_id)
const platformsIcons = usePlatformIcons()
-
+ useInvestigationData(investigation_id)
const { currentNode, setCurrentNode } = useFlowStore()
+ const {
+ individuals,
+ isLoadingIndividuals,
+ emails,
+ isLoadingEmails,
+ phones,
+ isLoadingPhones,
+ socials,
+ isLoadingSocials,
+ } = useInvestigationStore()
return (
- <div className='flex flex-col'>
- <Accordion type="single" collapsible defaultValue='individuals'>
+ <div className="flex flex-col">
+ <Accordion type="single" collapsible defaultValue="individuals">
<AccordionItem value="individuals">
- <AccordionTrigger className='p-2 px-4 hover:bg-sidebar-accent text-sidebar-accent-foreground/60 hover:text-sidebar-accent-foreground text-sm rounded-none'>
- Profiles {!isLoadingIndividuals && <>({individuals?.length})</>}</AccordionTrigger>
+ <AccordionTrigger className="p-2 px-4 hover:bg-sidebar-accent text-sidebar-accent-foreground/60 hover:text-sidebar-accent-foreground text-sm rounded-none">
+ Profiles {!isLoadingIndividuals && <>({individuals?.length})</>}
+ </AccordionTrigger>
<AccordionContent>
- {isLoadingIndividuals && <div className='flex flex-col gap-1'>
- <Skeleton className='w-full h-[20px] bg-foreground/10 rounded-none' />
- <Skeleton className='w-full h-[20px] bg-foreground/10 rounded-none' />
- <Skeleton className='w-full h-[20px] bg-foreground/10 rounded-none' />
- </div>
- }
+ {isLoadingIndividuals && (
+ <div className="flex flex-col gap-1">
+ <Skeleton className="w-full h-[20px] bg-foreground/10 rounded-none" />
+ <Skeleton className="w-full h-[20px] bg-foreground/10 rounded-none" />
+ <Skeleton className="w-full h-[20px] bg-foreground/10 rounded-none" />
+ </div>
+ )}
<ul>
{individuals?.map((individual: any) => (
- <li className={cn('hover:bg-sidebar-accent text-sidebar-accent-foreground/90 hover:text-sidebar-accent-foreground text-sm', currentNode === individual.id && "bg-sidebar-accent text-sidebar-accent-foreground")} key={individual.id}>
- <button onClick={() => setCurrentNode(individual.id)} className='flex items-center p-1 px-4 w-full gap-2'>
- <UserIcon className='h-3 w-3 opacity-60' />
+ <li
+ className={cn(
+ "hover:bg-sidebar-accent text-sidebar-accent-foreground/90 hover:text-sidebar-accent-foreground text-sm",
+ currentNode === individual.id && "bg-sidebar-accent text-sidebar-accent-foreground",
+ )}
+ key={individual.id}
+ >
+ <button
+ onClick={() => setCurrentNode(individual.id)}
+ className="flex items-center p-1 px-4 w-full gap-2"
+ >
+ <UserIcon className="h-3 w-3 opacity-60" />
{individual.full_name}
</button>
</li>
- ))
- }
+ ))}
</ul>
</AccordionContent>
</AccordionItem>
</Accordion>
- <Accordion type="single" collapsible defaultValue='emails'>
+ <Accordion type="single" collapsible defaultValue="emails">
<AccordionItem value="emails">
- <AccordionTrigger className='p-2 px-4 hover:bg-sidebar-accent text-sidebar-accent-foreground/60 hover:text-sidebar-accent-foreground text-sm rounded-none'>
- Emails {!isLoadingEmails && <>({emails?.length})</>}</AccordionTrigger>
+ <AccordionTrigger className="p-2 px-4 hover:bg-sidebar-accent text-sidebar-accent-foreground/60 hover:text-sidebar-accent-foreground text-sm rounded-none">
+ Emails {!isLoadingEmails && <>({emails?.length})</>}
+ </AccordionTrigger>
<AccordionContent>
- {isLoadingEmails && <div className='flex flex-col gap-1'>
- <Skeleton className='w-full h-[20px] bg-foreground/10 rounded-none' />
- <Skeleton className='w-full h-[20px] bg-foreground/10 rounded-none' />
- <Skeleton className='w-full h-[20px] bg-foreground/10 rounded-none' />
- </div>
- }
+ {isLoadingEmails && (
+ <div className="flex flex-col gap-1">
+ <Skeleton className="w-full h-[20px] bg-foreground/10 rounded-none" />
+ <Skeleton className="w-full h-[20px] bg-foreground/10 rounded-none" />
+ <Skeleton className="w-full h-[20px] bg-foreground/10 rounded-none" />
+ </div>
+ )}
<ul>
{emails?.map((email: any) => (
- <li className={cn('hover:bg-sidebar-accent text-sidebar-accent-foreground/90 hover:text-sidebar-accent-foreground text-sm', currentNode === email.id && "bg-sidebar-accent text-sidebar-accent-foreground")} key={email.id}>
- <button onClick={() => setCurrentNode(email.id)} className='flex items-center p-1 px-4 w-full gap-2'>
- <AtSignIcon className='h-3 w-3 opacity-60' />
+ <li
+ className={cn(
+ "hover:bg-sidebar-accent text-sidebar-accent-foreground/90 hover:text-sidebar-accent-foreground text-sm",
+ currentNode === email.id && "bg-sidebar-accent text-sidebar-accent-foreground",
+ )}
+ key={email.id}
+ >
+ <button onClick={() => setCurrentNode(email.id)} className="flex items-center p-1 px-4 w-full gap-2">
+ <AtSignIcon className="h-3 w-3 opacity-60" />
{email.email}
</button>
</li>
- ))
- }
+ ))}
</ul>
</AccordionContent>
</AccordionItem>
</Accordion>
- <Accordion type="single" collapsible defaultValue='phones'>
+ <Accordion type="single" collapsible defaultValue="phones">
<AccordionItem value="phones">
- <AccordionTrigger className='p-2 px-4 hover:bg-sidebar-accent text-sidebar-accent-foreground/60 hover:text-sidebar-accent-foreground text-sm rounded-none'>
- Phones {!isLoadingPhones && <>({phones?.length})</>}</AccordionTrigger>
+ <AccordionTrigger className="p-2 px-4 hover:bg-sidebar-accent text-sidebar-accent-foreground/60 hover:text-sidebar-accent-foreground text-sm rounded-none">
+ Phones {!isLoadingPhones && <>({phones?.length})</>}
+ </AccordionTrigger>
<AccordionContent>
- {isLoadingPhones && <div className='flex flex-col gap-1'>
- <Skeleton className='w-full h-[20px] bg-foreground/10 rounded-none' />
- <Skeleton className='w-full h-[20px] bg-foreground/10 rounded-none' />
- <Skeleton className='w-full h-[20px] bg-foreground/10 rounded-none' />
- </div>
- }
+ {isLoadingPhones && (
+ <div className="flex flex-col gap-1">
+ <Skeleton className="w-full h-[20px] bg-foreground/10 rounded-none" />
+ <Skeleton className="w-full h-[20px] bg-foreground/10 rounded-none" />
+ <Skeleton className="w-full h-[20px] bg-foreground/10 rounded-none" />
+ </div>
+ )}
<ul>
{phones?.map((phone: any) => (
- <li className={cn('hover:bg-sidebar-accent text-sidebar-accent-foreground/90 hover:text-sidebar-accent-foreground text-sm', currentNode === phone.id && "bg-sidebar-accent text-sidebar-accent-foreground")} key={phone.id}>
- <button onClick={() => setCurrentNode(phone.id)} className='flex items-center p-1 px-4 w-full gap-2'>
- <PhoneIcon className='h-3 w-3 opacity-60' />
+ <li
+ className={cn(
+ "hover:bg-sidebar-accent text-sidebar-accent-foreground/90 hover:text-sidebar-accent-foreground text-sm",
+ currentNode === phone.id && "bg-sidebar-accent text-sidebar-accent-foreground",
+ )}
+ key={phone.id}
+ >
+ <button onClick={() => setCurrentNode(phone.id)} className="flex items-center p-1 px-4 w-full gap-2">
+ <PhoneIcon className="h-3 w-3 opacity-60" />
{phone.phone_number}
</button>
</li>
- ))
- }
+ ))}
</ul>
</AccordionContent>
</AccordionItem>
</Accordion>
- <Accordion type="single" collapsible defaultValue='socials'>
+ <Accordion type="single" collapsible defaultValue="socials">
<AccordionItem value="socials">
- <AccordionTrigger className='p-2 px-4 hover:bg-sidebar-accent text-sidebar-accent-foreground/60 hover:text-sidebar-accent-foreground text-sm rounded-none'>
- Socials {!isLoadingSocials && <>({socials?.length})</>}</AccordionTrigger>
+ <AccordionTrigger className="p-2 px-4 hover:bg-sidebar-accent text-sidebar-accent-foreground/60 hover:text-sidebar-accent-foreground text-sm rounded-none">
+ Socials {!isLoadingSocials && <>({socials?.length})</>}
+ </AccordionTrigger>
<AccordionContent>
- {isLoadingSocials && <div className='flex flex-col gap-1'>
- <Skeleton className='w-full h-[20px] bg-foreground/10 rounded-none' />
- <Skeleton className='w-full h-[20px] bg-foreground/10 rounded-none' />
- <Skeleton className='w-full h-[20px] bg-foreground/10 rounded-none' />
- </div>
- }
+ {isLoadingSocials && (
+ <div className="flex flex-col gap-1">
+ <Skeleton className="w-full h-[20px] bg-foreground/10 rounded-none" />
+ <Skeleton className="w-full h-[20px] bg-foreground/10 rounded-none" />
+ <Skeleton className="w-full h-[20px] bg-foreground/10 rounded-none" />
+ </div>
+ )}
<ul>
{socials?.map((social: any) => (
- <li className={cn('hover:bg-sidebar-accent text-sidebar-accent-foreground/90 hover:text-sidebar-accent-foreground text-sm', currentNode === social.id && "bg-sidebar-accent text-sidebar-accent-foreground")} key={social.id}>
- <button onClick={() => setCurrentNode(social.id)} className='flex items-center p-1 px-4 w-full gap-2'>
- <span className='opacity-60'>
+ <li
+ className={cn(
+ "hover:bg-sidebar-accent text-sidebar-accent-foreground/90 hover:text-sidebar-accent-foreground text-sm",
+ currentNode === social.id && "bg-sidebar-accent text-sidebar-accent-foreground",
+ )}
+ key={social.id}
+ >
+ <button onClick={() => setCurrentNode(social.id)} className="flex items-center p-1 px-4 w-full gap-2">
+ <span className="opacity-60">
{/* @ts-ignore */}
{platformsIcons?.[social?.platform]?.icon}
</span>
{social.username || social.profile_url}
</button>
</li>
- ))
- }
+ ))}
</ul>
</AccordionContent>
</AccordionItem>
</Accordion>
- </div >
+ </div>
)
}
-export default Left
\ No newline at end of file
+export default Left
+
diff --git a/src/app/layout.tsx b/src/app/layout.tsx
index 2012734b..cfe946b9 100644
--- a/src/app/layout.tsx
+++ b/src/app/layout.tsx
@@ -7,6 +7,7 @@ import { fontSans } from "@/config/fonts";
import { ConfirmContextProvider } from "@/components/use-confirm-dialog";
import NextTopLoader from 'nextjs-toploader';
import { TooltipProvider } from "@/components/ui/tooltip";
+import { NuqsAdapter } from 'nuqs/adapters/next/app'
export const metadata: Metadata = {
title: {
@@ -40,16 +41,18 @@ export default function RootLayout({
fontSans.variable,
)}
>
- <Providers themeProps={{ attribute: "class", defaultTheme: "dark" }}>
- <main>
- <NextTopLoader color="var(--primary)"/>
- <TooltipProvider>
- <ConfirmContextProvider>
- {children}
- </ConfirmContextProvider>
- </TooltipProvider>
- </main>
- </Providers>
+ <NuqsAdapter>
+ <Providers themeProps={{ attribute: "class", defaultTheme: "dark" }}>
+ <main>
+ <NextTopLoader color="var(--primary)" />
+ <TooltipProvider>
+ <ConfirmContextProvider>
+ {children}
+ </ConfirmContextProvider>
+ </TooltipProvider>
+ </main>
+ </Providers>
+ </NuqsAdapter>
</body>
</html>
);
diff --git a/src/components/contexts/investigation-provider.tsx b/src/components/contexts/investigation-provider.tsx
index bb25ffb2..4e07121c 100644
--- a/src/components/contexts/investigation-provider.tsx
+++ b/src/components/contexts/investigation-provider.tsx
@@ -1,43 +1,18 @@
"use client"
-import useLocalStorage from "@/lib/hooks/use-local-storage";
-import React, { createContext, useContext, ReactNode, useState, useCallback } from "react";
-import {
- Dialog,
- DialogContent,
- DialogDescription,
- DialogClose,
- DialogTitle,
-} from "@/components/ui/dialog"
-import { Button } from "@/components/ui/button";
-import { Switch } from "@/components/ui/switch";
-import { useParams, useRouter, usePathname, useSearchParams } from "next/navigation";
-import { Investigation } from "@/types/investigation";
-import { useInvestigation } from "@/lib/hooks/investigation/investigation";
-import { ThemeSwitch } from "@/components/theme-switch";
-import { useConfirm } from "@/components/use-confirm-dialog";
-import { supabase } from "@/lib/supabase/client";
-// import FloatingEdge from "../investigations/floating-edge";
-import { cn } from "@/lib/utils";
-
-interface InvestigationContextType {
- filters: any,
- setFilters: any,
- settings: any,
- setSettings: any,
- setOpenSettingsModal: any,
- investigation: Investigation | null,
- isLoadingInvestigation: boolean | undefined,
- handleOpenIndividualModal: any,
- handleDeleteInvestigation: any,
- currentNode: any,
- setCurrentNode: any,
- panelOpen: boolean,
- setPanelOpen: any
-}
-const InvestigationContext = createContext<InvestigationContextType | undefined>(undefined);
+import type React from "react"
+import { type ReactNode, useEffect } from "react"
+import { useInvestigationStore } from "@/store/investigation-store"
+import { useParams, useRouter, usePathname, useSearchParams } from "next/navigation"
+import { useInvestigation } from "@/lib/hooks/investigation/investigation"
+import { useConfirm } from "@/components/use-confirm-dialog"
+import { supabase } from "@/lib/supabase/client"
+import { Dialog, DialogContent, DialogDescription, DialogClose, DialogTitle } from "@/components/ui/dialog"
+import { Button } from "@/components/ui/button"
+import { Switch } from "@/components/ui/switch"
+import { cn } from "@/lib/utils"
interface InvestigationProviderProps {
- children: ReactNode;
+ children: ReactNode
}
export const InvestigationProvider: React.FC<InvestigationProviderProps> = ({ children }) => {
@@ -45,78 +20,128 @@ export const InvestigationProvider: React.FC<InvestigationProviderProps> = ({ ch
const router = useRouter()
const pathname = usePathname()
const searchParams = useSearchParams()
- const [panelOpen, setPanelOpen] = useLocalStorage('panel_open', false)
- const [filters, setFilters] = useLocalStorage('filters', {});
- const [currentNode, setCurrentNode] = useState<null | Node>(null)
- const { investigation, isLoading: isLoadingInvestigation } = useInvestigation(investigation_id)
- const [openSettingsModal, setOpenSettingsModal] = useState(false)
const { confirm } = useConfirm()
- const [settings, setSettings] = useLocalStorage('settings', {
- showNodeLabel: true,
- showEdgeLabel: true,
- showMiniMap: true,
- showCopyIcon: true,
- showNodeToolbar: true,
- // floatingEdges: false
- });
+ const { investigation, isLoading: isLoadingInvestigation } = useInvestigation(investigation_id)
- const createQueryString = useCallback(
- (name: string, value: string) => {
+ const {
+ settings,
+ setSettings,
+ openSettingsModal,
+ setOpenSettingsModal,
+ setInvestigation,
+ setIsLoadingInvestigation,
+ setHandleOpenIndividualModal,
+ setHandleDeleteInvestigation,
+ } = useInvestigationStore()
+
+ useEffect(() => {
+ setInvestigation(investigation)
+ setIsLoadingInvestigation(isLoadingInvestigation)
+
+ const createQueryString = (name: string, value: string) => {
const params = new URLSearchParams(searchParams.toString())
params.set(name, value)
-
return params.toString()
- },
- [searchParams]
- )
- const handleOpenIndividualModal = (id: string) => router.push(pathname + '?' + createQueryString('individual_id', id))
+ }
+
+ const handleOpenIndividualModal = (id: string) =>
+ router.push(pathname + "?" + createQueryString("individual_id", id))
- const handleDeleteInvestigation = async () => {
- if (await confirm({ title: "Delete investigation", message: "Are you really sure you want to delete this investigation ?" })) {
- if (await confirm({ title: "Just making sure", message: "You will definetly delete all nodes, edges and relationships." })) {
- const { error } = await supabase.from("investigations").delete().eq('id', investigation_id)
- if (error) throw error
- return router.push("/dashboard")
+ setHandleOpenIndividualModal(() => handleOpenIndividualModal)
+
+ const handleDeleteInvestigation = async () => {
+ if (
+ await confirm({
+ title: "Delete investigation",
+ message: "Are you really sure you want to delete this investigation ?",
+ })
+ ) {
+ if (
+ await confirm({
+ title: "Just making sure",
+ message: "You will definitely delete all nodes, edges and relationships.",
+ })
+ ) {
+ const { error } = await supabase.from("investigations").delete().eq("id", investigation_id)
+ if (error) throw error
+ return router.push("/dashboard")
+ }
}
}
- }
- const SettingSwitch = ({ setting, value, title, description, disabled = false }: { setting: string, value: boolean, title: string, description: string, disabled?: boolean }) => (
- <div className={cn("flex items-center justify-between gap-4", disabled && 'opacity-60')}>
+ setHandleDeleteInvestigation(handleDeleteInvestigation)
+ }, [
+ investigation,
+ isLoadingInvestigation,
+ investigation_id,
+ router,
+ pathname,
+ searchParams,
+ confirm,
+ setInvestigation,
+ setIsLoadingInvestigation,
+ setHandleOpenIndividualModal,
+ setHandleDeleteInvestigation,
+ ])
+
+ const SettingSwitch = ({
+ setting,
+ value,
+ title,
+ description,
+ disabled = false,
+ }: { setting: string; value: boolean; title: string; description: string; disabled?: boolean }) => (
+ <div className={cn("flex items-center justify-between gap-4", disabled && "opacity-60")}>
<div className="flex flex-col gap-1">
<p className="font-medium">{title}</p>
- <p className="opacity-70 text-sm">
- {description}
- </p>
+ <p className="opacity-70 text-sm">{description}</p>
</div>
- <Switch disabled={disabled} checked={value} onCheckedChange={(val: boolean) => setSettings({ ...settings, [setting]: val })} />
+ <Switch
+ disabled={disabled}
+ checked={value}
+ onCheckedChange={(val: boolean) => setSettings({ ...settings, [setting]: val })}
+ />
</div>
)
+
return (
- <InvestigationContext.Provider value={{ filters, setFilters, settings, setSettings, setOpenSettingsModal, investigation, isLoadingInvestigation, handleOpenIndividualModal, handleDeleteInvestigation, currentNode, setCurrentNode, panelOpen, setPanelOpen }}>
+ <>
{children}
<Dialog open={openSettingsModal} onOpenChange={setOpenSettingsModal}>
<DialogContent>
<DialogTitle>Settings</DialogTitle>
- <DialogDescription>
- Make changes to your settings.
- </DialogDescription>
+ <DialogDescription>Make changes to your settings.</DialogDescription>
<div className="flex flex-col gap-3">
- <SettingSwitch setting={"showNodeLabel"} value={settings.showNodeLabel} title={"Show labels on nodes"} description={"Displays the labels on the nodes, like username or avatar."} />
- <SettingSwitch setting={"showEdgeLabel"} value={settings.showEdgeLabel} title={"Show labels on edges"} description={"Displays the labels on the edges, like relation type."} />
- <SettingSwitch setting={"showMiniMap"} value={settings.showMiniMap} title={"Show minimap on the canva"} description={"Displays the minimap on canva."} />
- <SettingSwitch setting={"showCopyIcon"} value={settings.showCopyIcon} title={"Show copy button on nodes"} description={"Displays a copy button on the nodes."} />
- <SettingSwitch setting={"showNodeToolbar"} value={settings.showNodeToolbar} title={"Show toolbar on nodes"} description={"Displays a toolbar with actions on the nodes."} />
- {/* <SettingSwitch disabled setting={"floatingEdges"} value={settings.floatingEdges} title={"Floating edges"} description={"Edges are not stuck to one point."} /> */}
- <div className="flex items-center justify-between gap-4">
- <div className="flex flex-col gap-1">
- <p className="font-medium">Theme</p>
- <p className="opacity-70 text-sm">
- Switch to dark or light mode.
- </p>
- </div>
- <ThemeSwitch />
- </div>
+ <SettingSwitch
+ setting={"showNodeLabel"}
+ value={settings.showNodeLabel}
+ title={"Show labels on nodes"}
+ description={"Displays the labels on the nodes, like username or avatar."}
+ />
+ <SettingSwitch
+ setting={"showEdgeLabel"}
+ value={settings.showEdgeLabel}
+ title={"Show labels on edges"}
+ description={"Displays the labels on the edges, like relation type."}
+ />
+ <SettingSwitch
+ setting={"showMiniMap"}
+ value={settings.showMiniMap}
+ title={"Show minimap on the canva"}
+ description={"Displays the minimap on canva."}
+ />
+ <SettingSwitch
+ setting={"showCopyIcon"}
+ value={settings.showCopyIcon}
+ title={"Show copy button on nodes"}
+ description={"Displays a copy button on the nodes."}
+ />
+ <SettingSwitch
+ setting={"showNodeToolbar"}
+ value={settings.showNodeToolbar}
+ title={"Show toolbar on nodes"}
+ description={"Displays a toolbar with actions on the nodes."}
+ />
</div>
<div className="flex items-center gap-2 justify-end">
<DialogClose asChild>
@@ -127,14 +152,9 @@ export const InvestigationProvider: React.FC<InvestigationProviderProps> = ({ ch
</div>
</DialogContent>
</Dialog>
- </InvestigationContext.Provider >
- );
-};
+ </>
+ )
+}
+
+export const useInvestigationContext = useInvestigationStore
-export const useInvestigationContext = (): InvestigationContextType => {
- const context = useContext(InvestigationContext);
- if (!context) {
- throw new Error("useInvestigationContext must be used within a InvestigationProvider");
- }
- return context;
-};
\ No newline at end of file
diff --git a/src/components/dashboard/search-palette.tsx b/src/components/dashboard/search-palette.tsx
index def8a775..a1cf0c94 100644
--- a/src/components/dashboard/search-palette.tsx
+++ b/src/components/dashboard/search-palette.tsx
@@ -3,21 +3,22 @@
import { useState, useCallback, useEffect, SetStateAction } from 'react'
// @ts-ignore
import debounce from "lodash.debounce"
-import { Search } from 'lucide-react'
+import { Search, UserIcon } from 'lucide-react'
// @ts-ignore
import Highlighter from "react-highlight-words"
-import { useSearchResults } from '../../lib/hooks/investigation/use-search-results'
-import { useInvestigationContext } from '../contexts/investigation-provider'
+import { useSearchResults } from '@/lib/hooks/investigation/use-search-results'
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog"
import { Input } from "@/components/ui/input"
import { Button } from "@/components/ui/button"
import { Card, CardContent } from "@/components/ui/card"
import { ScrollArea } from "@/components/ui/scroll-area"
+import { useFlowStore } from '@/store/flow-store'
+import { cn } from '@/lib/utils'
const SearchModal = ({ investigation_id }: { investigation_id: string }) => {
const [search, setSearch] = useState("")
const [open, setOpen] = useState(false)
- const { setCurrentNode } = useInvestigationContext()
+ const { setCurrentNode } = useFlowStore()
const {
results,
error,
@@ -49,30 +50,20 @@ const SearchModal = ({ investigation_id }: { investigation_id: string }) => {
}, [])
const SearchItem = ({ item }: any) => (
- <li onClick={() => setOpen(false)}>
- <Card className='cursor-pointer hover:border-primary border border-transparent' onClick={() => setCurrentNode(item.id)}>
- <CardContent className='p-3'>
- <div className='flex flex-col gap-1 text-left'>
- <span className='text-xs text-muted-foreground'>Individual</span>
- <div className='flex items-center flex-col items-start gap-1'>
- <span className='truncate'>
- <Highlighter
- searchWords={search.split(" ")}
- autoEscape={true}
- textToHighlight={item?.full_name}
- />
- </span>
- <span className='truncate text-ellipsis text-sm text-muted-foreground'>
- <Highlighter
- searchWords={search.split(" ")}
- autoEscape={true}
- textToHighlight={item?.notes}
- />
- </span>
- </div>
- </div>
- </CardContent>
- </Card>
+ <li
+ className={cn(
+ "hover:bg-sidebar-accent text-sidebar-accent-foreground/90 hover:text-sidebar-accent-foreground text-sm",
+ "bg-sidebar-accent text-sidebar-accent-foreground",
+ )}
+ key={item.id}
+ >
+ <button
+ onClick={() => setCurrentNode(item.id)}
+ className="flex items-center p-1 px-4 w-full gap-2"
+ >
+ <UserIcon className="h-3 w-3 opacity-60" />
+ {item.full_name}
+ </button>
</li>
)
diff --git a/src/components/investigations/case-selector.tsx b/src/components/investigations/case-selector.tsx
index 1184dea9..7bed30c2 100644
--- a/src/components/investigations/case-selector.tsx
+++ b/src/components/investigations/case-selector.tsx
@@ -1,5 +1,5 @@
import { useInvestigations } from "@/lib/hooks/investigation/investigation";
-import { useInvestigationContext } from "../contexts/investigation-provider";
+import { useInvestigationStore } from '@/store/investigation-store';
import { useRouter } from "next/navigation";
import {
Select,
@@ -13,7 +13,7 @@ import { Skeleton } from "@/components/ui/skeleton";
export default function CaseSelector() {
const router = useRouter()
const { investigations, isLoading } = useInvestigations()
- const { investigation, isLoadingInvestigation } = useInvestigationContext()
+ const { investigation, isLoadingInvestigation } = useInvestigationStore()
const handleSelectionChange = (value: string) => {
router.push(`/investigations/${value}`);
};
diff --git a/src/components/investigations/current-node-card.tsx b/src/components/investigations/current-node-card.tsx
index 4aeb9d2e..e76617e7 100644
--- a/src/components/investigations/current-node-card.tsx
+++ b/src/components/investigations/current-node-card.tsx
@@ -1,9 +1,9 @@
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardHeader } from "@/components/ui/card"
-import { Phone, User2, XIcon } from "lucide-react"
+import { Phone, XIcon } from "lucide-react"
import { useState } from "react"
-import { useInvestigationContext } from "../contexts/investigation-provider"
+import { useInvestigationStore } from '@/store/investigation-store';
interface PhoneNumber {
id: string
@@ -31,7 +31,7 @@ interface CurrentNodeProps {
}
export default function CurrentNode({ individual }: CurrentNodeProps) {
- const { handleOpenIndividualModal } = useInvestigationContext()
+ const { handleOpenIndividualModal } = useInvestigationStore()
const [show, setShow] = useState(true)
if (!show) return
return (
@@ -65,7 +65,7 @@ export default function CurrentNode({ individual }: CurrentNodeProps) {
</div>
)}
<div className="flex gap-2 justify-center">
- <Button onClick={() => handleOpenIndividualModal(individual.id)}
+ <Button onClick={() => handleOpenIndividualModal(individual.id as string)}
variant="outline">View Details</Button>
{/* <Button>Contact</Button> */}
</div>
diff --git a/src/components/investigations/custom-edge.tsx b/src/components/investigations/custom-edge.tsx
index 2a1e1840..e7a20fa0 100644
--- a/src/components/investigations/custom-edge.tsx
+++ b/src/components/investigations/custom-edge.tsx
@@ -3,7 +3,7 @@ import {
EdgeLabelRenderer,
getBezierPath,
} from '@xyflow/react';
-import { useInvestigationContext } from '../contexts/investigation-provider';
+import { useInvestigationStore } from '@/store/investigation-store';
import { Badge } from '@/components/ui/badge';
export default function CustomEdge(props: any) {
@@ -14,7 +14,7 @@ export default function CustomEdge(props: any) {
targetX,
targetY,
});
- const { settings } = useInvestigationContext()
+ const { settings } = useInvestigationStore()
return (
<>
<BaseEdge id={id} path={edgePath} style={style} />
diff --git a/src/components/investigations/floating-edge.tsx b/src/components/investigations/floating-edge.tsx
index cac0d34f..18cf4ab1 100644
--- a/src/components/investigations/floating-edge.tsx
+++ b/src/components/investigations/floating-edge.tsx
@@ -4,13 +4,13 @@ import {
getBezierPath,
useInternalNode
} from '@xyflow/react';
-import { useInvestigationContext } from '@/components/contexts/investigation-provider';
+import { useInvestigationStore } from '@/store/investigation-store';
import { Badge } from '@/components/ui/badge';
function FloatingEdge(props: any) {
const { id, source, target, markerEnd, label, confidence_level, sourceX, sourceY, targetX, targetY, style } = props
const sourceNode = useInternalNode(source);
const targetNode = useInternalNode(target);
- const { settings } = useInvestigationContext()
+ const { settings } = useInvestigationStore()
if (!sourceNode || !targetNode) {
return null;
diff --git a/src/components/investigations/graph.tsx b/src/components/investigations/graph.tsx
index 1008b30b..cdbf0c2e 100644
--- a/src/components/investigations/graph.tsx
+++ b/src/components/investigations/graph.tsx
@@ -26,8 +26,8 @@ import { Tooltip, TooltipContent } from '@/components/ui/tooltip';
import { Button } from '@/components/ui/button';
import { TooltipTrigger } from '@radix-ui/react-tooltip';
import { cn } from '@/lib/utils';
-import { useInvestigationContext } from '@/components/contexts/investigation-provider';
-import { useFlowStore } from '../contexts/use-flow-store';
+import { useInvestigationStore } from '@/store/investigation-store';
+import { useFlowStore } from '../../store/flow-store';
// import CurrentNode from './current-node-card';
const edgeTypes = {
@@ -46,7 +46,7 @@ const nodeTypes = {
const LayoutFlow = ({ theme }: { theme: ColorMode }) => {
const { fitView, zoomIn, zoomOut, addNodes, getNode, setCenter } = useReactFlow();
const { investigation_id } = useParams();
- const { settings } = useInvestigationContext();
+ const { settings } = useInvestigationStore();
const {
nodes,
diff --git a/src/components/investigations/individual-modal.tsx b/src/components/investigations/individual-modal.tsx
index 8065339e..fbce95b5 100644
--- a/src/components/investigations/individual-modal.tsx
+++ b/src/components/investigations/individual-modal.tsx
@@ -1,14 +1,13 @@
"use client"
import type React from "react"
import { useEffect, useState } from "react"
-import { usePathname, useRouter, useSearchParams } from "next/navigation"
import { useIndividual } from "@/lib/hooks/individuals/use-individual"
import { useEmailsAndBreaches } from "@/lib/hooks/individuals/use-emails-breaches"
import { useRelations } from "@/lib/hooks/individuals/use-relations"
-import { useInvestigationContext } from "../contexts/investigation-provider"
+import { useInvestigationStore } from '@/store/investigation-store';
import { usePlatformIcons } from "@/lib/hooks/use-platform-icons"
import { supabase } from "@/lib/supabase/client"
-import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogTitle } from "@/components/ui/dialog"
+import { Sheet, SheetContent, SheetDescription, SheetFooter, SheetTitle } from "@/components/ui/sheet"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
@@ -18,17 +17,15 @@ import { Alert, AlertDescription } from "@/components/ui/alert"
import { Card, CardContent } from "@/components/ui/card"
import { Pencil, X, Plus, Trash2 } from "lucide-react"
import Breaches from "../breach"
+import { useQueryState } from "nuqs"
const IndividualModal = () => {
- const router = useRouter()
- const pathname = usePathname()
- const searchParams = useSearchParams()
- const individual_id = searchParams.get("individual_id")
- const { handleOpenIndividualModal } = useInvestigationContext()
- const { individual, isLoading } = useIndividual(individual_id)
- const { emails, isLoading: isLoadingEmails } = useEmailsAndBreaches(individual_id)
+ const [individualId, setIndividualId] = useQueryState("individual_id")
+ const { handleOpenIndividualModal } = useInvestigationStore()
+ const { individual, isLoading } = useIndividual(individualId)
+ const { emails, isLoading: isLoadingEmails } = useEmailsAndBreaches(individualId)
const platformsIcons = usePlatformIcons("medium")
- const { relations, isLoading: isLoadingRelations } = useRelations(individual_id)
+ const { relations, isLoading: isLoadingRelations } = useRelations(individualId)
const [editMode, setEditMode] = useState(false)
const [image, setImage] = useState<string | null>("")
const [phones, setPhones] = useState([""])
@@ -44,7 +41,7 @@ const IndividualModal = () => {
const handleCloseModal = () => {
setEditMode(false)
- router.push(pathname)
+ setIndividualId(null)
}
const handleSave = async (event: React.FormEvent<HTMLFormElement>) => {
@@ -54,7 +51,7 @@ const IndividualModal = () => {
const { data } = await supabase
.from("individuals")
.update({ ...formContent, birth_date: null })
- .eq("id", individual_id)
+ .eq("id", individualId)
.select("image_url")
.single()
setImage(data?.image_url)
@@ -76,27 +73,27 @@ const IndividualModal = () => {
if (!isLoading && !individual) {
return (
- <Dialog open={Boolean(individual_id)} onOpenChange={handleCloseModal}>
- <DialogContent>
- <DialogTitle>No data</DialogTitle>
- <DialogDescription>No data found for this individual.</DialogDescription>
- <DialogFooter>
+ <Sheet open={Boolean(individualId)} onOpenChange={handleCloseModal}>
+ <SheetContent>
+ <SheetTitle>No data</SheetTitle>
+ <SheetDescription>No data found for this individual.</SheetDescription>
+ <SheetFooter>
<Button variant="outline" onClick={handleCloseModal}>
Close
</Button>
- </DialogFooter>
- </DialogContent>
- </Dialog>
+ </SheetFooter>
+ </SheetContent>
+ </Sheet>
)
}
return (
- <Dialog open={Boolean(individual_id)} onOpenChange={handleCloseModal}>
- <DialogContent className="sm:max-w-[80vw] max-h-[90vh] overflow-y-auto">
+ <Sheet open={Boolean(individualId)} onOpenChange={handleCloseModal}>
+ <SheetContent className="sm:max-w-[80vw] p-12 overflow-y-auto">
<form className="flex flex-col gap-3 justify-between h-full" onSubmit={handleSave}>
<div className="flex flex-col gap-4 flex-grow-0">
<div className="flex justify-between items-center">
- <DialogTitle>User Profile</DialogTitle>
+ <SheetTitle>User Profile</SheetTitle>
<Button
variant="ghost"
size="icon"
@@ -353,15 +350,15 @@ const IndividualModal = () => {
</div>
</div>
</div>
- <DialogFooter>
+ <SheetFooter>
<Button variant="outline" onClick={handleCloseModal}>
Cancel
</Button>
{editMode && <Button type="submit">Save Changes</Button>}
- </DialogFooter>
+ </SheetFooter>
</form>
- </DialogContent>
- </Dialog>
+ </SheetContent>
+ </Sheet>
)
}
diff --git a/src/components/investigations/layout.tsx b/src/components/investigations/layout.tsx
index 1678a76f..6d04a192 100644
--- a/src/components/investigations/layout.tsx
+++ b/src/components/investigations/layout.tsx
@@ -5,11 +5,9 @@ import CaseSelector from './case-selector';
import NewCase from '@/components/dashboard/new-case';
import SearchModal from '@/components/dashboard/search-palette';
import { Panel, PanelGroup, PanelResizeHandle } from 'react-resizable-panels';
-import { BotMessageSquareIcon, PanelRightIcon, PlusIcon } from 'lucide-react';
-import { useChatContext } from '@/components/contexts/chatbot-context';
+import { PanelRightIcon, PlusIcon } from 'lucide-react';
import Logo from '@/components/logo';
-import { useInvestigationContext } from '@/components/contexts/investigation-provider';
-import { NavUser } from '@/components/user';
+import { useInvestigationStore } from '@/store/investigation-store';
import { Button } from '../ui/button';
import { ScrollArea } from '../ui/scroll-area';
import Assistant from '../assistant';
@@ -27,7 +25,7 @@ const InvestigationLayout = ({
investigation_id: string
user: any
}) => {
- const { panelOpen, setPanelOpen } = useInvestigationContext()
+ const { panelOpen, setPanelOpen } = useInvestigationStore()
return (
<SidebarProvider defaultOpen={false}>
<AppSidebar user={user} defaultChecked={false} />
diff --git a/src/components/investigations/more-menu.tsx b/src/components/investigations/more-menu.tsx
index 737b0242..26a8320d 100644
--- a/src/components/investigations/more-menu.tsx
+++ b/src/components/investigations/more-menu.tsx
@@ -1,5 +1,5 @@
import { Ellipsis } from "lucide-react";
-import { useInvestigationContext } from "../contexts/investigation-provider";
+import { useInvestigationStore } from '@/store/investigation-store';
import {
DropdownMenu,
DropdownMenuTrigger,
@@ -8,7 +8,7 @@ import {
} from "@/components/ui/dropdown-menu";
import { Button } from "@/components/ui/button";
export default function MoreMenu() {
- const { setOpenSettingsModal, handleDeleteInvestigation } = useInvestigationContext();
+ const { setOpenSettingsModal, handleDeleteInvestigation } = useInvestigationStore();
return (
<DropdownMenu>
@@ -18,6 +18,7 @@ export default function MoreMenu() {
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
+ {/* @ts-ignore */}
<DropdownMenuItem onClick={setOpenSettingsModal}>Settings</DropdownMenuItem>
<DropdownMenuItem onClick={handleDeleteInvestigation} className="text-red-500">
Delete
diff --git a/src/components/investigations/nodes/email.tsx b/src/components/investigations/nodes/email.tsx
index 2beadec6..9a191508 100644
--- a/src/components/investigations/nodes/email.tsx
+++ b/src/components/investigations/nodes/email.tsx
@@ -2,12 +2,12 @@
import { memo } from "react"
import { Handle, Position, useStore } from "@xyflow/react"
-import { NodeProvider, useNodeContext } from "../../contexts/node-context"
+import { NodeProvider, useNodeContext } from "@/components/contexts/node-context"
import { AtSignIcon, Zap } from "lucide-react"
import { cn, zoomSelector } from "@/lib/utils"
-import { useInvestigationContext } from "../../contexts/investigation-provider"
-import { CopyButton } from "../../copy"
-import { useSearchContext } from "../../contexts/search-context"
+import { useInvestigationStore } from "@/store/investigation-store"
+import { CopyButton } from "@/components/copy"
+import { useSearchContext } from "@/components/contexts/search-context"
import { Card } from "@/components/ui/card"
import { Badge } from "@/components/ui/badge"
import { Avatar, AvatarFallback } from "@/components/ui/avatar"
@@ -20,11 +20,11 @@ import {
ContextMenuTrigger,
} from "@/components/ui/context-menu"
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"
-import { useFlowStore } from "@/components/contexts/use-flow-store"
+import { useFlowStore } from "@/store/flow-store"
function EmailNode({ data }: any) {
const { handleDeleteNode, loading } = useNodeContext()
- const { settings } = useInvestigationContext()
+ const { settings } = useInvestigationStore()
const { currentNode } = useFlowStore()
const { handleOpenSearchModal } = useSearchContext()
const showContent = useStore(zoomSelector)
diff --git a/src/components/investigations/nodes/individual.tsx b/src/components/investigations/nodes/individual.tsx
index 664c6884..54173f13 100644
--- a/src/components/investigations/nodes/individual.tsx
+++ b/src/components/investigations/nodes/individual.tsx
@@ -2,7 +2,7 @@
import { memo } from "react"
import { Handle, NodeToolbar, Position, useStore } from "@xyflow/react"
-import { useInvestigationContext } from "@/components/contexts/investigation-provider"
+import { useInvestigationStore } from "@/store/investigation-store"
import { NodeProvider, useNodeContext } from "@/components/contexts/node-context"
import { useSearchContext } from "@/components/contexts/search-context"
import { cn, zoomSelector } from "@/lib/utils"
@@ -39,15 +39,17 @@ import {
User,
Zap,
} from "lucide-react"
-import { useFlowStore } from "@/components/contexts/use-flow-store"
+import { useFlowStore } from "@/store/flow-store"
+import { useQueryState } from "nuqs"
function Custom(props: any) {
- const { settings, handleOpenIndividualModal } = useInvestigationContext()
+ const { settings } = useInvestigationStore()
const { currentNode } = useFlowStore()
const { setOpenAddNodeModal, handleDuplicateNode, handleDeleteNode, loading } = useNodeContext()
const { handleOpenSearchModal } = useSearchContext()
const { handleOpenChat } = useChatContext()
const showContent = useStore(zoomSelector)
+ const [_, setIndividualId] = useQueryState("individual_id")
const { data } = props
return (
@@ -56,7 +58,7 @@ function Custom(props: any) {
<NodeToolbar isVisible={data.forceToolbarVisible || undefined} position={Position.Top}>
<Card className="p-1 rounded-full shadow-none backdrop-blur bg-background/40">
<div className="flex gap-1">
- <Button variant="outline" className="rounded-full" size="sm" onClick={() => handleOpenIndividualModal(data.id)}>
+ <Button variant="outline" className="rounded-full" size="sm" onClick={() => setIndividualId(data.id)}>
<Edit className="h-4 w-4 mr-2" />
Edit
</Button>
@@ -77,7 +79,7 @@ function Custom(props: any) {
<div className={cn(loading ? "opacity-40" : "opacity-100", "overflow-hidden group")}>
{settings.showNodeLabel && showContent ? (
<Card
- onDoubleClick={() => handleOpenIndividualModal(data.id)}
+ onDoubleClick={() => setIndividualId(data.id)}
className={cn(
"p-1 border border-border hover:border-primary/40 duration-100 rounded-full shadow-none backdrop-blur bg-background/40",
currentNode === data.id && "border-primary",
@@ -101,7 +103,7 @@ function Custom(props: any) {
<Tooltip>
<TooltipTrigger asChild>
<button
- onDoubleClick={() => handleOpenIndividualModal(data.id)}
+ onDoubleClick={() => setIndividualId(data.id)}
className={cn(
"rounded-full border border-transparent hover:border-primary",
currentNode === data.id && "border-primary",
@@ -200,7 +202,7 @@ function Custom(props: any) {
</ContextMenuSub>
</ContextMenuSubContent>
</ContextMenuSub>
- <ContextMenuItem onClick={() => handleOpenIndividualModal(data.id)}>View and edit</ContextMenuItem>
+ <ContextMenuItem onClick={() => setIndividualId(data.id)}>View and edit</ContextMenuItem>
<ContextMenuItem onClick={handleDuplicateNode}>Duplicate</ContextMenuItem>
<ContextMenuSeparator />
<ContextMenuItem onClick={handleDeleteNode} className="text-red-600">
diff --git a/src/components/investigations/nodes/ip_address.tsx b/src/components/investigations/nodes/ip_address.tsx
index abfdc87c..fa34bb44 100644
--- a/src/components/investigations/nodes/ip_address.tsx
+++ b/src/components/investigations/nodes/ip_address.tsx
@@ -2,12 +2,12 @@
import { memo } from "react"
import { Handle, Position, useStore } from "@xyflow/react"
-import { NodeProvider, useNodeContext } from "../../contexts/node-context"
-import { AtSign, LocateIcon, Zap } from "lucide-react"
+import { NodeProvider, useNodeContext } from "@/components/contexts/node-context"
+import { LocateIcon, Zap } from "lucide-react"
import { cn, zoomSelector } from "@/lib/utils"
-import { useInvestigationContext } from "../../contexts/investigation-provider"
-import { CopyButton } from "../../copy"
-import { useSearchContext } from "../../contexts/search-context"
+import { useInvestigationStore } from "@/store/investigation-store"
+import { CopyButton } from "@/components/copy"
+import { useSearchContext } from "@/components/contexts/search-context"
import { Card } from "@/components/ui/card"
import { Badge } from "@/components/ui/badge"
import { Avatar, AvatarFallback } from "@/components/ui/avatar"
@@ -20,11 +20,11 @@ import {
ContextMenuTrigger,
} from "@/components/ui/context-menu"
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"
-import { useFlowStore } from "@/components/contexts/use-flow-store"
+import { useFlowStore } from "@/store/flow-store"
function IpNode({ data }: any) {
const { handleDeleteNode, loading } = useNodeContext()
- const { settings } = useInvestigationContext()
+ const { settings } = useInvestigationStore()
const { currentNode } = useFlowStore()
const { handleOpenSearchModal } = useSearchContext()
const showContent = useStore(zoomSelector)
diff --git a/src/components/investigations/nodes/phone.tsx b/src/components/investigations/nodes/phone.tsx
index c9c4636c..d3573411 100644
--- a/src/components/investigations/nodes/phone.tsx
+++ b/src/components/investigations/nodes/phone.tsx
@@ -2,12 +2,12 @@
import { memo } from "react"
import { Handle, Position, useStore } from "@xyflow/react"
-import { NodeProvider, useNodeContext } from "../../contexts/node-context"
-import { AtSign, LocateIcon, PhoneIcon, Zap } from "lucide-react"
+import { NodeProvider, useNodeContext } from "@/components/contexts/node-context"
+import { PhoneIcon, Zap } from "lucide-react"
import { cn, zoomSelector } from "@/lib/utils"
-import { useInvestigationContext } from "../../contexts/investigation-provider"
-import { CopyButton } from "../../copy"
-import { useSearchContext } from "../../contexts/search-context"
+import { useInvestigationStore } from "@/store/investigation-store"
+import { CopyButton } from "@/components/copy"
+import { useSearchContext } from "@/components/contexts/search-context"
import { Card } from "@/components/ui/card"
import { Badge } from "@/components/ui/badge"
import { Avatar, AvatarFallback } from "@/components/ui/avatar"
@@ -20,11 +20,11 @@ import {
ContextMenuTrigger,
} from "@/components/ui/context-menu"
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"
-import { useFlowStore } from "@/components/contexts/use-flow-store"
+import { useFlowStore } from "@/store/flow-store"
function PhoneNode({ data }: any) {
const { handleDeleteNode, loading } = useNodeContext()
- const { settings } = useInvestigationContext()
+ const { settings } = useInvestigationStore()
const { currentNode } = useFlowStore()
const { handleOpenSearchModal } = useSearchContext()
const showContent = useStore(zoomSelector)
diff --git a/src/components/investigations/nodes/physical_address.tsx b/src/components/investigations/nodes/physical_address.tsx
index 830a72e4..0008e7b9 100644
--- a/src/components/investigations/nodes/physical_address.tsx
+++ b/src/components/investigations/nodes/physical_address.tsx
@@ -2,12 +2,12 @@
import { memo } from "react"
import { Handle, Position, useStore } from "@xyflow/react"
-import { NodeProvider, useNodeContext } from "../../contexts/node-context"
+import { NodeProvider, useNodeContext } from "@/components/contexts/node-context"
import { MapPinIcon, Zap } from "lucide-react"
import { cn, zoomSelector } from "@/lib/utils"
-import { useInvestigationContext } from "../../contexts/investigation-provider"
-import { CopyButton } from "../../copy"
-import { useSearchContext } from "../../contexts/search-context"
+import { useInvestigationStore } from "@/store/investigation-store"
+import { CopyButton } from "@/components/copy"
+import { useSearchContext } from "@/components/contexts/search-context"
import { Card } from "@/components/ui/card"
import { Badge } from "@/components/ui/badge"
import { Avatar, AvatarFallback } from "@/components/ui/avatar"
@@ -20,11 +20,11 @@ import {
ContextMenuTrigger,
} from "@/components/ui/context-menu"
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"
-import { useFlowStore } from "@/components/contexts/use-flow-store"
+import { useFlowStore } from "@/store/flow-store"
function AddressNode({ data }: any) {
const { handleDeleteNode, loading } = useNodeContext()
- const { settings } = useInvestigationContext()
+ const { settings } = useInvestigationStore()
const { currentNode } = useFlowStore()
const { handleOpenSearchModal } = useSearchContext()
const showContent = useStore(zoomSelector)
diff --git a/src/components/investigations/nodes/social.tsx b/src/components/investigations/nodes/social.tsx
index ff1f4bb1..745975ad 100644
--- a/src/components/investigations/nodes/social.tsx
+++ b/src/components/investigations/nodes/social.tsx
@@ -2,12 +2,12 @@
import { memo } from "react"
import { Handle, Position, useStore } from "@xyflow/react"
-import { NodeProvider, useNodeContext } from "../../contexts/node-context"
+import { NodeProvider, useNodeContext } from "@/components/contexts/node-context"
import { MapPinIcon, Zap } from "lucide-react"
import { cn, zoomSelector } from "@/lib/utils"
-import { useInvestigationContext } from "../../contexts/investigation-provider"
-import { CopyButton } from "../../copy"
-import { useSearchContext } from "../../contexts/search-context"
+import { useInvestigationStore } from "@/store/investigation-store"
+import { CopyButton } from "@/components/copy"
+import { useSearchContext } from "@/components/contexts/search-context"
import { Card } from "@/components/ui/card"
import { Badge } from "@/components/ui/badge"
import { Avatar, AvatarFallback } from "@/components/ui/avatar"
@@ -21,11 +21,11 @@ import {
} from "@/components/ui/context-menu"
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"
import { usePlatformIcons } from "@/lib/hooks/use-platform-icons"
-import { useFlowStore } from "@/components/contexts/use-flow-store"
+import { useFlowStore } from "@/store/flow-store"
function SocialNode({ data }: any) {
const { handleDeleteNode, loading } = useNodeContext()
- const { settings } = useInvestigationContext()
+ const { settings } = useInvestigationStore()
const { currentNode } = useFlowStore()
const platformsIcons = usePlatformIcons()
const { handleOpenSearchModal } = useSearchContext()
diff --git a/src/components/nav-user.tsx b/src/components/nav-user.tsx
index 99c51607..ed086700 100644
--- a/src/components/nav-user.tsx
+++ b/src/components/nav-user.tsx
@@ -30,6 +30,7 @@ import {
useSidebar,
} from "@/components/ui/sidebar"
import { logout } from "@/lib/actions/auth"
+import { ThemeSwitch } from "./theme-switch"
export function NavUser({
user,
@@ -97,6 +98,10 @@ export function NavUser({
<Bell />
Notifications
</DropdownMenuItem>
+ <DropdownMenuItem>
+ <ThemeSwitch />
+ Theme
+ </DropdownMenuItem>
</DropdownMenuGroup>
<DropdownMenuSeparator />
<DropdownMenuItem onClick={logout}>
diff --git a/src/components/user.tsx b/src/components/user.tsx
deleted file mode 100644
index 9871fe9e..00000000
--- a/src/components/user.tsx
+++ /dev/null
@@ -1,103 +0,0 @@
-"use client"
-
-import {
- BadgeCheck,
- Bell,
- ChevronsUpDown,
- CreditCard,
- LogOut,
- Sparkles,
-} from "lucide-react"
-
-import {
- Avatar,
- AvatarFallback,
- AvatarImage,
-} from "@/components/ui/avatar"
-import {
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuGroup,
- DropdownMenuItem,
- DropdownMenuLabel,
- DropdownMenuSeparator,
- DropdownMenuTrigger,
-} from "@/components/ui/dropdown-menu"
-import { Button } from "./ui/button"
-
-export function NavUser({
- user,
-}: {
- user: {
- name?: string
- email: string
- avatar?: string
- }
-}) {
-
- return (
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button
- size="lg"
- variant="outline"
- >
- <Avatar className="h-8 w-8 rounded-lg">
- <AvatarImage src={user.avatar} alt={user.name} />
- <AvatarFallback className="rounded-lg">CN</AvatarFallback>
- </Avatar>
- <div className="grid flex-1 text-left text-sm leading-tight">
- <span className="truncate font-semibold">{user.name}</span>
- <span className="truncate text-xs">{user.email}</span>
- </div>
- <ChevronsUpDown className="ml-auto size-4" />
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent
- className="w-[--radix-dropdown-menu-trigger-width] min-w-56 rounded-lg"
- align="end"
- sideOffset={4}
- >
- <DropdownMenuLabel className="p-0 font-normal">
- <div className="flex items-center gap-2 px-1 py-1.5 text-left text-sm">
- <Avatar className="h-8 w-8 rounded-lg">
- <AvatarImage src={user.avatar} alt={user.name} />
- <AvatarFallback className="rounded-lg">CN</AvatarFallback>
- </Avatar>
- <div className="grid flex-1 text-left text-sm leading-tight">
- <span className="truncate font-semibold">{user.name}</span>
- <span className="truncate text-xs">{user.email}</span>
- </div>
- </div>
- </DropdownMenuLabel>
- <DropdownMenuSeparator />
- <DropdownMenuGroup>
- <DropdownMenuItem>
- <Sparkles />
- Upgrade to Pro
- </DropdownMenuItem>
- </DropdownMenuGroup>
- <DropdownMenuSeparator />
- <DropdownMenuGroup>
- <DropdownMenuItem>
- <BadgeCheck />
- Account
- </DropdownMenuItem>
- <DropdownMenuItem>
- <CreditCard />
- Billing
- </DropdownMenuItem>
- <DropdownMenuItem>
- <Bell />
- Notifications
- </DropdownMenuItem>
- </DropdownMenuGroup>
- <DropdownMenuSeparator />
- <DropdownMenuItem>
- <LogOut />
- Log out
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- )
-}
diff --git a/src/components/contexts/use-flow-store.tsx b/src/store/flow-store.ts
similarity index 100%
rename from src/components/contexts/use-flow-store.tsx
rename to src/store/flow-store.ts
diff --git a/src/store/investigation-store.ts b/src/store/investigation-store.ts
new file mode 100644
index 00000000..78f69cca
--- /dev/null
+++ b/src/store/investigation-store.ts
@@ -0,0 +1,182 @@
+"use client"
+
+import React from "react"
+
+import { create } from "zustand"
+import { persist, createJSONStorage } from "zustand/middleware"
+import type { Investigation } from "@/types/investigation"
+import { useIndividuals } from "@/lib/hooks/investigation/use-individuals"
+import { useEmails } from "@/lib/hooks/investigation/use-emails"
+import { usePhones } from "@/lib/hooks/investigation/use-phones"
+import { useSocials } from "@/lib/hooks/investigation/use-socials"
+
+interface InvestigationState {
+ filters: any
+ setFilters: (filters: any) => void
+ settings: any
+ setSettings: (settings: any) => void
+ openSettingsModal: boolean
+ setOpenSettingsModal: (open: boolean) => void
+ investigation: Investigation | null
+ setInvestigation: (investigation: Investigation | null) => void
+ isLoadingInvestigation: boolean | undefined
+ setIsLoadingInvestigation: (isLoading: boolean | undefined) => void
+ handleOpenIndividualModal: (id: string) => void
+ setHandleOpenIndividualModal: (handler: (id: string) => void) => void
+ handleDeleteInvestigation: () => Promise<void>
+ setHandleDeleteInvestigation: (handler: () => Promise<void>) => void
+ currentNode: any
+ setCurrentNode: (node: any) => void
+ panelOpen: boolean
+ setPanelOpen: (open: boolean) => void
+ individuals: any[]
+ setIndividuals: (individuals: any[]) => void
+ isLoadingIndividuals: boolean
+ setIsLoadingIndividuals: (isLoading: boolean) => void
+ refetchIndividuals: () => void
+ setRefetchIndividuals: (refetch: () => void) => void
+ emails: any[]
+ setEmails: (emails: any[]) => void
+ isLoadingEmails: boolean
+ setIsLoadingEmails: (isLoading: boolean) => void
+ refetchEmails: () => void
+ setRefetchEmails: (refetch: () => void) => void
+ phones: any[]
+ setPhones: (phones: any[]) => void
+ isLoadingPhones: boolean
+ setIsLoadingPhones: (isLoading: boolean) => void
+ refetchPhones: () => void
+ setRefetchPhones: (refetch: () => void) => void
+ socials: any[]
+ setSocials: (socials: any[]) => void
+ isLoadingSocials: boolean
+ setIsLoadingSocials: (isLoading: boolean) => void
+ refetchSocials: () => void
+ setRefetchSocials: (refetch: () => void) => void
+}
+
+const isServer = typeof window === "undefined"
+
+export const useInvestigationStore = create(
+ persist<InvestigationState>(
+ (set, get) => ({
+ filters: {},
+ setFilters: (filters) => set({ filters }),
+ settings: {
+ showNodeLabel: true,
+ showEdgeLabel: true,
+ showMiniMap: true,
+ showCopyIcon: true,
+ showNodeToolbar: true,
+ },
+ setSettings: (settings) => set({ settings }),
+ openSettingsModal: false,
+ setOpenSettingsModal: (open) => set({ openSettingsModal: open }),
+ investigation: null,
+ setInvestigation: (investigation) => set({ investigation }),
+ isLoadingInvestigation: undefined,
+ setIsLoadingInvestigation: (isLoading) => set({ isLoadingInvestigation: isLoading }),
+ handleOpenIndividualModal: () => { },
+ setHandleOpenIndividualModal: (handler) => set({ handleOpenIndividualModal: handler }),
+ handleDeleteInvestigation: async () => { },
+ setHandleDeleteInvestigation: (handler) => set({ handleDeleteInvestigation: handler }),
+ currentNode: null,
+ setCurrentNode: (node) => set({ currentNode: node }),
+ panelOpen: false,
+ setPanelOpen: (open) => set({ panelOpen: open }),
+ individuals: [],
+ setIndividuals: (individuals) => set({ individuals }),
+ isLoadingIndividuals: true,
+ setIsLoadingIndividuals: (isLoading) => set({ isLoadingIndividuals: isLoading }),
+ refetchIndividuals: () => { },
+ setRefetchIndividuals: (refetch) => set({ refetchIndividuals: refetch }),
+ emails: [],
+ setEmails: (emails) => set({ emails }),
+ isLoadingEmails: true,
+ setIsLoadingEmails: (isLoading) => set({ isLoadingEmails: isLoading }),
+ refetchEmails: () => { },
+ setRefetchEmails: (refetch) => set({ refetchEmails: refetch }),
+ phones: [],
+ setPhones: (phones) => set({ phones }),
+ isLoadingPhones: true,
+ setIsLoadingPhones: (isLoading) => set({ isLoadingPhones: isLoading }),
+ refetchPhones: () => { },
+ setRefetchPhones: (refetch) => set({ refetchPhones: refetch }),
+ socials: [],
+ setSocials: (socials) => set({ socials }),
+ isLoadingSocials: true,
+ setIsLoadingSocials: (isLoading) => set({ isLoadingSocials: isLoading }),
+ refetchSocials: () => { },
+ setRefetchSocials: (refetch) => set({ refetchSocials: refetch }),
+ }),
+ {
+ name: "investigation-storage",
+ storage: createJSONStorage(() => (isServer ? localStorage : localStorage)),
+ // @ts-ignore
+ partialize: (state) => ({
+ // Only persist these fields
+ filters: state.filters,
+ settings: state.settings,
+ investigation: state.investigation,
+ individuals: state.individuals,
+ emails: state.emails,
+ phones: state.phones,
+ socials: state.socials
+ }),
+ },
+ ),
+)
+
+export const useInvestigationData = (investigation_id: string) => {
+ const {
+ setIndividuals,
+ setIsLoadingIndividuals,
+ setRefetchIndividuals,
+ setEmails,
+ setIsLoadingEmails,
+ setRefetchEmails,
+ setPhones,
+ setIsLoadingPhones,
+ setRefetchPhones,
+ setSocials,
+ setIsLoadingSocials,
+ setRefetchSocials,
+ } = useInvestigationStore()
+
+ const { individuals, isLoading: isLoadingIndividuals, refetch: refetchIndividuals } = useIndividuals(investigation_id)
+ const { emails, isLoading: isLoadingEmails, refetch: refetchEmails } = useEmails(investigation_id)
+ const { phones, isLoading: isLoadingPhones, refetch: refetchPhones } = usePhones(investigation_id)
+ const { socials, isLoading: isLoadingSocials, refetch: refetchSocials } = useSocials(investigation_id)
+
+ React.useEffect(() => {
+ setIndividuals(individuals || [])
+ setIsLoadingIndividuals(isLoadingIndividuals)
+ setRefetchIndividuals(() => refetchIndividuals)
+ }, [
+ individuals,
+ isLoadingIndividuals,
+ refetchIndividuals,
+ setIndividuals,
+ setIsLoadingIndividuals,
+ setRefetchIndividuals,
+ ])
+
+ React.useEffect(() => {
+ setEmails(emails || [])
+ setIsLoadingEmails(isLoadingEmails)
+ setRefetchEmails(() => refetchEmails)
+ }, [emails, isLoadingEmails, refetchEmails, setEmails, setIsLoadingEmails, setRefetchEmails])
+
+ React.useEffect(() => {
+ setPhones(phones || [])
+ setIsLoadingPhones(isLoadingPhones)
+ setRefetchPhones(() => refetchPhones)
+ }, [phones, isLoadingPhones, refetchPhones, setPhones, setIsLoadingPhones, setRefetchPhones])
+
+ React.useEffect(() => {
+ setSocials(socials || [])
+ setIsLoadingSocials(isLoadingSocials)
+ setRefetchSocials(() => refetchSocials)
+ }, [socials, isLoadingSocials, refetchSocials, setSocials, setIsLoadingSocials, setRefetchSocials])
+}
+
diff --git a/yarn.lock b/yarn.lock
index edc9b666..e3840d49 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -4284,6 +4284,11 @@ minimist@^1.2.0, minimist@^1.2.6:
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c"
integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==
+mitt@^3.0.1:
+ version "3.0.1"
+ resolved "https://registry.yarnpkg.com/mitt/-/mitt-3.0.1.tgz#ea36cf0cc30403601ae074c8f77b7092cdab36d1"
+ integrity sha512-vKivATfr97l2/QBCYAkXYDbrIWPM2IIKEl7YPhjCvKlG3kE2gm+uBo6nEXK3M5/Ffh/FLpKExzOQ3JJoJGFKBw==
+
motion-dom@^12.0.0:
version "12.0.0"
resolved "https://registry.yarnpkg.com/motion-dom/-/motion-dom-12.0.0.tgz#7045c63642eecbcc04c40b4457ebb07b3c2b3d0c"
@@ -4372,6 +4377,13 @@ nprogress@^0.2.0:
resolved "https://registry.yarnpkg.com/nprogress/-/nprogress-0.2.0.tgz#cb8f34c53213d895723fcbab907e9422adbcafb1"
integrity sha512-I19aIingLgR1fmhftnbWWO3dXc0hSxqHQHQb3H8m+K3TnEn/iSeTZZOyvKXWqQESMwuUVnatlCnZdLBZZt2VSA==
+nuqs@^2.4.0:
+ version "2.4.0"
+ resolved "https://registry.yarnpkg.com/nuqs/-/nuqs-2.4.0.tgz#74001dde07a72cd35972e4bb88cee281a97464cf"
+ integrity sha512-+yOdX0q/wdYlseSYtWC8StDDt2QFcYX/zV5/E67J1cOJo3PR0mggxMx4acZGC0Hu66xFHENKQkqI2zSpH742xQ==
+ dependencies:
+ mitt "^3.0.1"
+
object-assign@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"