Files
coco-app/src/stores/searchStore.ts
BiggerRain 97d2450fa7 feat: selection settings add & delete (#992)
* feat: add selection window page

* fix: chat input

* feat: add selection page

* chore: add

* chore: test

* feat: add

* feat: add store

* feat: add selection settings

* chore: remove unused code

* docs: add release note

* docs: add release note

* chore: format code

* chore: format code

* fix: copy error

* disable hashbrown default feature

* Enable unstable feature allocator_api

To make coco-app compile in CI:

```
--> /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/hashbrown-0.15.5/src/raw/mod.rs:3856:12
     |
3856 | impl<T, A: Allocator> RawIntoIter<T, A> {
     |            ^^^^^^^^^
     |
     = note: see issue #32838 <https://github.com/rust-lang/rust/issues/32838> for more information
     = help: add `#![feature(allocator_api)]` to the crate attributes to enable
     = note: this compiler was built on 2025-06-25; consider upgrading it if it is out of date
```

I don't know why it does not compile, feature `allocator-api2` is
enabled for `hashbrown 0.15.5`, so technically [1] it should not use the
allocator APIs from the std. According to [2], enabling the `nightly`
feature of `allocator-api2` may cause this issue as well, but it is not
enabled in our case either.

Anyway, enabling `#![feature(allocator_api)]` should make it work.

[1]: b751eef8e9/src/raw/alloc.rs (L26-L47)
[2]: https://github.com/rust-lang/hashbrown/issues/564

* put it in main.rs

* format main.rs

* Enable default-features for hashbrown 0.15.5

* format main.rs

* enable feature allocator-api2

* feat: add selection set config

* fix: selection setting

* fix: ci error

* fix: ci error

* fix: ci error

* fix: ci error

* merge: merge main

* fix: rust code warn

* fix: rust code error

* fix: rust code error

* fix: selection settings

* style: selection styles

* style: selection styles

* feat: selection settings add & delete

* feat: selection settings add & delete

* feat: selection settings add & delete

* style: selection styles

* chore: add @tauri-store/zustand plugin

* refactor: the selection store using @tauri-store/zustand

* fix: data error

* fix: data error

* chore: remove config

* chore: selection

* chore: selection

* chore: width

* chore: ignore selection in the app itself

* style: selection styles

* style: remove

* docs: add notes

* chore: add permission check

* chore: selection

* chore: style & store

---------

Co-authored-by: Steve Lau <stevelauc@outlook.com>
2025-12-05 15:32:57 +08:00

150 lines
5.0 KiB
TypeScript

import { SearchExtensionItem } from "@/components/Search/ExtensionStore";
import {
ExtensionPermission,
ViewExtensionUISettings,
} from "@/components/Settings/Extensions";
import { create } from "zustand";
import { persist } from "zustand/middleware";
export type ViewExtensionOpened = [
// Extension name
string,
// An absolute path to the extension icon or a font code.
string,
// HTML file URL
string,
ExtensionPermission | null,
ViewExtensionUISettings | null,
];
export type ISearchStore = {
sourceData: any;
setSourceData: (sourceData: any) => void;
sourceDataIds: string[];
setSourceDataIds: (prevSourceDataId: string[]) => void;
MCPIds: string[];
setMCPIds: (prevSourceDataId: string[]) => void;
visibleContextMenu: boolean;
setVisibleContextMenu: (visibleContextMenu: boolean) => void;
selectedSearchContent?: Record<string, any>;
setSelectedSearchContent: (
selectedSearchContent?: Record<string, any>
) => void;
goAskAi: boolean;
setGoAskAi: (goAskAi: boolean) => void;
askAiMessage: string;
setAskAiMessage: (askAiMessage: string) => void;
askAiSessionId?: string;
setAskAiSessionId: (askAiSessionId?: string) => void;
selectedAssistant?: any;
setSelectedAssistant: (selectedAssistant?: any) => void;
askAiServerId?: string;
setAskAiServerId: (askAiServerId?: string) => void;
enabledAiOverview: boolean;
setEnabledAiOverview: (enabledAiOverview: boolean) => void;
askAiAssistantId?: string;
setAskAiAssistantId: (askAiAssistantId?: string) => void;
targetServerId?: string;
setTargetServerId: (targetServerId?: string) => void;
targetAssistantId?: string;
setTargetAssistantId: (targetAssistantId?: string) => void;
visibleExtensionStore: boolean;
setVisibleExtensionStore: (visibleExtensionStore: boolean) => void;
searchValue: string;
setSearchValue: (searchValue: string) => void;
selectedExtension?: SearchExtensionItem;
setSelectedExtension: (selectedExtension?: SearchExtensionItem) => void;
installingExtensions: string[];
setInstallingExtensions: (installingExtensions: string[]) => void;
uninstallingExtensions: string[];
setUninstallingExtensions: (uninstallingExtensions: string[]) => void;
visibleExtensionDetail: boolean;
setVisibleExtensionDetail: (visibleExtensionDetail: boolean) => void;
// When we open a View extension, we set this to a non-null value.
viewExtensionOpened?: ViewExtensionOpened;
setViewExtensionOpened: (showViewExtension?: ViewExtensionOpened) => void;
};
export const useSearchStore = create<ISearchStore>()(
persist(
(set) => ({
sourceData: undefined,
setSourceData: (sourceData: any) => set({ sourceData }),
sourceDataIds: [],
setSourceDataIds: (sourceDataIds: string[]) => set({ sourceDataIds }),
MCPIds: [],
setMCPIds: (MCPIds: string[]) => set({ MCPIds }),
visibleContextMenu: false,
setVisibleContextMenu: (visibleContextMenu) => {
return set({ visibleContextMenu });
},
setSelectedSearchContent: (selectedSearchContent) => {
return set({ selectedSearchContent });
},
goAskAi: false,
setGoAskAi: (goAskAi) => {
return set({ goAskAi });
},
askAiMessage: "",
setAskAiMessage: (askAiMessage) => {
return set({ askAiMessage });
},
setAskAiSessionId: (askAiSessionId) => {
return set({ askAiSessionId });
},
setSelectedAssistant: (selectedAssistant) => {
return set({ selectedAssistant });
},
setAskAiServerId: (askAiServerId) => {
return set({ askAiServerId });
},
enabledAiOverview: false,
setEnabledAiOverview: (enabledAiOverview) => {
return set({ enabledAiOverview });
},
setAskAiAssistantId: (askAiAssistantId) => {
return set({ askAiAssistantId });
},
setTargetServerId: (targetServerId) => {
return set({ targetServerId });
},
setTargetAssistantId: (targetAssistantId) => {
return set({ targetAssistantId });
},
visibleExtensionStore: false,
setVisibleExtensionStore: (visibleExtensionStore) => {
return set({ visibleExtensionStore });
},
searchValue: "",
setSearchValue: (searchValue) => {
return set({ searchValue });
},
setSelectedExtension(selectedExtension) {
return set({ selectedExtension });
},
installingExtensions: [],
setInstallingExtensions: (installingExtensions) => {
return set({ installingExtensions });
},
uninstallingExtensions: [],
setUninstallingExtensions: (uninstallingExtensions) => {
return set({ uninstallingExtensions });
},
visibleExtensionDetail: false,
setVisibleExtensionDetail: (visibleExtensionDetail) => {
return set({ visibleExtensionDetail });
},
setViewExtensionOpened: (viewExtensionOpened) => {
return set({ viewExtensionOpened });
},
}),
{
name: "search-store",
partialize: (state) => ({
sourceData: state.sourceData,
}),
}
)
);