feat: init profiles prefs
This commit is contained in:
parent
0819becfd9
commit
d6ad3e2071
3 changed files with 36 additions and 23 deletions
|
|
@ -5,7 +5,7 @@ import { getParagraphNodeFromString } from "../mainInput/utils";
|
|||
import { ConversationStarterCard } from "./ConversationStarterCard";
|
||||
import { useBookmarkedSlashCommands } from "./useBookmarkedSlashCommands";
|
||||
|
||||
const NUM_CARDS_TO_RENDER_COLLAPSED = 3;
|
||||
const NUM_CARDS_TO_RENDER = 3;
|
||||
|
||||
export function ConversationStarterCards() {
|
||||
const dispatch = useAppDispatch();
|
||||
|
|
@ -26,17 +26,15 @@ export function ConversationStarterCards() {
|
|||
|
||||
return (
|
||||
<div className="flex w-full max-w-full flex-col lg:grid lg:grid-cols-3 lg:gap-4">
|
||||
{cmdsSortedByBookmark
|
||||
.slice(0, NUM_CARDS_TO_RENDER_COLLAPSED)
|
||||
.map((command, i) => (
|
||||
<ConversationStarterCard
|
||||
key={command.name + i}
|
||||
command={command}
|
||||
onClick={onClick}
|
||||
onBookmark={() => toggleBookmark(command)}
|
||||
isBookmarked={bookmarkStatuses[command.name]}
|
||||
/>
|
||||
))}
|
||||
{cmdsSortedByBookmark.slice(0, NUM_CARDS_TO_RENDER).map((command, i) => (
|
||||
<ConversationStarterCard
|
||||
key={command.name + i}
|
||||
command={command}
|
||||
onClick={onClick}
|
||||
onBookmark={() => toggleBookmark(command)}
|
||||
isBookmarked={bookmarkStatuses[command.name]}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { ProfileDescription } from "core/config/ConfigHandler";
|
||||
import { OrganizationDescription } from "core/config/ProfileLifecycleManager";
|
||||
import { ensureProfilePreferences } from "./utils";
|
||||
|
||||
interface PreferencesState {
|
||||
export interface PreferencesState {
|
||||
bookmarksByName: string[];
|
||||
}
|
||||
|
||||
interface ProfilesState {
|
||||
export interface ProfilesState {
|
||||
availableProfiles: ProfileDescription[] | null;
|
||||
selectedProfileId: string | null;
|
||||
organizations: OrganizationDescription[];
|
||||
|
|
@ -28,12 +29,22 @@ export const profilesSlice = createSlice({
|
|||
reducers: {
|
||||
setSelectedProfile: (state, { payload }: PayloadAction<string | null>) => {
|
||||
state.selectedProfileId = payload;
|
||||
|
||||
if (payload) {
|
||||
ensureProfilePreferences(state, payload);
|
||||
}
|
||||
},
|
||||
setAvailableProfiles: (
|
||||
state,
|
||||
{ payload }: PayloadAction<ProfileDescription[] | null>,
|
||||
) => {
|
||||
state.availableProfiles = payload;
|
||||
|
||||
if (payload) {
|
||||
for (const profile of payload) {
|
||||
ensureProfilePreferences(state, profile.id);
|
||||
}
|
||||
}
|
||||
},
|
||||
setOrganizations: (
|
||||
state,
|
||||
|
|
@ -56,14 +67,6 @@ export const profilesSlice = createSlice({
|
|||
|
||||
if (!profileId) return;
|
||||
|
||||
// Initialize preferences for this profile if needed
|
||||
if (!state.preferencesByProfileId[profileId]) {
|
||||
state.preferencesByProfileId[profileId] = {
|
||||
bookmarksByName: [],
|
||||
};
|
||||
}
|
||||
|
||||
// Only add if not already bookmarked
|
||||
const bookmarks = state.preferencesByProfileId[profileId].bookmarksByName;
|
||||
if (!bookmarks.includes(commandName)) {
|
||||
bookmarks.push(commandName);
|
||||
|
|
@ -77,7 +80,7 @@ export const profilesSlice = createSlice({
|
|||
const { commandName } = action.payload;
|
||||
const profileId = state.selectedProfileId;
|
||||
|
||||
if (!profileId || !state.preferencesByProfileId[profileId]) return;
|
||||
if (!profileId) return;
|
||||
|
||||
const preferences = state.preferencesByProfileId[profileId];
|
||||
preferences.bookmarksByName = preferences.bookmarksByName.filter(
|
||||
|
|
|
|||
12
gui/src/redux/slices/profiles/utils.ts
Normal file
12
gui/src/redux/slices/profiles/utils.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import { ProfilesState } from "./slice";
|
||||
|
||||
export function ensureProfilePreferences(
|
||||
state: ProfilesState,
|
||||
profileId: string,
|
||||
) {
|
||||
if (!state.preferencesByProfileId[profileId]) {
|
||||
state.preferencesByProfileId[profileId] = {
|
||||
bookmarksByName: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue