Skip to content

Commit

Permalink
Merge pull request #2132 from quadratichq/show-ai-on-startup
Browse files Browse the repository at this point in the history
Add View Option: "Show AI on startup" (default = true)
  • Loading branch information
AyushAgrawal-A2 authored Dec 19, 2024
2 parents 94caef6 + 84d68bd commit 03a8154
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
19 changes: 7 additions & 12 deletions quadratic-client/src/app/atoms/aiAnalystAtom.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { aiAnalystOfflineChats } from '@/app/ai/offline/aiAnalystChats';
import { getPromptMessages } from '@/app/ai/tools/message.helper';
import { editorInteractionStateUserAtom, editorInteractionStateUuidAtom } from '@/app/atoms/editorInteractionStateAtom';
import { sheets } from '@/app/grid/controller/Sheets';
import { showAIAnalystOnStartupAtom } from '@/app/atoms/gridSettingsAtom';
import { focusGrid } from '@/app/helpers/focusGrid';
import { Chat, ChatMessage } from 'quadratic-shared/typesAndSchemasAI';
import { atom, DefaultValue, selector } from 'recoil';
Expand Down Expand Up @@ -34,18 +34,13 @@ export const aiAnalystAtom = atom<AIAnalystState>({
key: 'aiAnalystAtom',
default: defaultAIAnalystState,
effects: [
async ({ getPromise, setSelf, trigger }) => {
async ({ getPromise, setSelf, trigger, getLoadable }) => {
if (trigger === 'get') {
// Determine if we want to override the default showAIAnalyst value on initialization
const aiAnalystOpenCount = getAiAnalystOpenCount();
const isSheetEmpty = sheets.sheet.bounds.type === 'empty';
const showAIAnalyst = aiAnalystOpenCount <= 3 ? true : isSheetEmpty;
if (showAIAnalyst) {
setSelf({
...defaultAIAnalystState,
showAIAnalyst,
});
}
const showAIAnalyst = await getPromise(showAIAnalystOnStartupAtom);
setSelf({
...defaultAIAnalystState,
showAIAnalyst,
});

const user = await getPromise(editorInteractionStateUserAtom);
const uuid = await getPromise(editorInteractionStateUuidAtom);
Expand Down
3 changes: 3 additions & 0 deletions quadratic-client/src/app/atoms/gridSettingsAtom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type GridSettings = {
showA1Notation: boolean;
showCodePeek: boolean;
presentationMode: boolean;
showAIAnalystOnStartup: boolean;
};

export const defaultGridSettings: GridSettings = {
Expand All @@ -21,6 +22,7 @@ export const defaultGridSettings: GridSettings = {
showA1Notation: false,
showCodePeek: false,
presentationMode: false,
showAIAnalystOnStartup: true,
};

// Persist the GridSettings
Expand Down Expand Up @@ -76,3 +78,4 @@ export const showCellTypeOutlinesAtom = createSelector('showCellTypeOutlines');
export const showA1NotationAtom = createSelector('showA1Notation');
export const showCodePeekAtom = createSelector('showCodePeek');
export const presentationModeAtom = createSelector('presentationMode');
export const showAIAnalystOnStartupAtom = createSelector('showAIAnalystOnStartup');
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Action } from '@/app/actions/actions';
import {
presentationModeAtom,
showAIAnalystOnStartupAtom,
showCellTypeOutlinesAtom,
showCodePeekAtom,
showGridLinesAtom,
Expand Down Expand Up @@ -33,6 +34,7 @@ export const ViewMenubarMenu = () => {
const [showGridLines, setShowGridLines] = useRecoilState(showGridLinesAtom);
const [showCellTypeOutlines, setShowCellTypeOutlines] = useRecoilState(showCellTypeOutlinesAtom);
const [showCodePeek, setShowCodePeek] = useRecoilState(showCodePeekAtom);
const [showAIAnalystOnStartup, setShowAIAnalystOnStartup] = useRecoilState(showAIAnalystOnStartupAtom);
const setPresentationMode = useSetRecoilState(presentationModeAtom);

return (
Expand All @@ -50,6 +52,10 @@ export const ViewMenubarMenu = () => {
<MenubarItemCheckbox checked={showCellTypeOutlines} />
Show code cell outlines
</MenubarItem>
<MenubarItem onClick={() => setShowAIAnalystOnStartup((prev) => !prev)}>
<MenubarItemCheckbox checked={showAIAnalystOnStartup} />
Show AI on startup
</MenubarItem>
<MenubarItem onClick={() => setShowCodePeek((prev) => !prev)}>
<MenubarItemCheckbox checked={showCodePeek} />
Show code peek
Expand Down

0 comments on commit 03a8154

Please sign in to comment.