Skip to content

Commit

Permalink
feat: add selection state to related prompts module
Browse files Browse the repository at this point in the history
  • Loading branch information
victorcg88 committed Nov 20, 2024
1 parent b4f0fff commit 8455cbe
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const relatedPromptsXStoreModule: RelatedPromptsXStoreModule = {
state: () => ({
query: '',
relatedPrompts: [],
selectedPrompt: -1,
selectedQuery: -1,
status: 'initial',
params: {}
}),
Expand All @@ -32,7 +34,15 @@ export const relatedPromptsXStoreModule: RelatedPromptsXStoreModule = {
setRelatedPromptsProducts(state, products) {
state.relatedPrompts = products;
},
setSelectedPrompt(state, selectedPrompt) {
state.selectedPrompt = selectedPrompt;
},
setSelectedQuery(state, selectedQuery) {
state.selectedQuery = selectedQuery;
},
resetRelatedPromptsState(state) {
state.selectedQuery = -1;
state.selectedPrompt = -1;
state.relatedPrompts = [];
}
},
Expand Down
16 changes: 16 additions & 0 deletions packages/x-components/src/x-modules/related-prompts/store/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import { XActionContext, XStoreModule } from '../../../store';
export interface RelatedPromptsState extends StatusState, QueryState {
/** The list of the related-prompts, related to the `query` property of the state. */
relatedPrompts: RelatedPrompt[];
/** The index of the selected related-prompt. */
selectedPrompt: number;
/** The index of the selected next query. */
selectedQuery: number;
/** The extra params property of the state. */
params: Dictionary<unknown>;
}
Expand Down Expand Up @@ -47,6 +51,18 @@ export interface RelatedPromptsMutations extends StatusMutations, QueryMutations
* @param relatedPrompts - The new related prompts to save to the state.
*/
setRelatedPromptsProducts(products: RelatedPrompt[]): void;
/**
* Sets the selected related prompt.
*
* @param index - The new selected related prompt.
*/
setSelectedPrompt(index: number): void;
/**
* Sets the selected next query.
*
* @param index - The new selected next query.
*/
setSelectedQuery(index: number): void;
/**
* Resets the related prompts state.
*/
Expand Down
16 changes: 16 additions & 0 deletions packages/x-components/src/x-modules/related-prompts/wiring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ const wireDispatchWithoutPayload = namespacedWireDispatchWithoutPayload(moduleNa
*/
const setRelatedPromptsQuery = wireCommit('setQuery');

/**
* Sets the related prompts state `selectedPrompt`.
*/
const setSelectedPromptWire = wireCommit('setSelectedPrompt');

/**
* Sets the related prompts state `selectedQuery`.
*/
const setSelectedQueryWire = wireCommit('setSelectedQuery');

/**
* Sets the related prompts state `query` from url params.
*/
Expand Down Expand Up @@ -93,5 +103,11 @@ export const relatedPromptsWiring = createWiring({
},
ExtraParamsChanged: {
setRelatedPromptsExtraParams
},
UserSelectedARelatedPrompt: {
setSelectedPromptWire
},
UserSelectedARelatedPromptQuery: {
setSelectedQueryWire
}
});

0 comments on commit 8455cbe

Please sign in to comment.