Skip to content

Commit

Permalink
Add display mode option (#747)
Browse files Browse the repository at this point in the history
  • Loading branch information
gadelkareem authored Jul 9, 2024
1 parent 80adc3b commit b96ba7c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/config/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export const TriggerMode = {
manually: 'Manually',
}

export const DisplayMode = {
sidebar: 'Display in sidebar',
floatingToolbar: 'Display in floating toolbar',
}

export const ThemeMode = {
light: 'Light',
dark: 'Dark',
Expand Down Expand Up @@ -202,6 +207,8 @@ export const defaultConfig = {

/** @type {keyof TriggerMode}*/
triggerMode: 'manually',
/** @type {keyof DisplayMode}*/
displayMode: 'sidebar',
/** @type {keyof ThemeMode}*/
themeMode: 'auto',
/** @type {keyof Models}*/
Expand Down
24 changes: 23 additions & 1 deletion src/content-script/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,33 @@ async function mountComponent(siteConfig, userConfig) {
unmountComponentAtNode(e)
e.remove()
})

const position = {
x: window.innerWidth - 300 - (Math.floor((20 / 100) * window.innerWidth)),
y: window.innerHeight / 2 - 200,
}
const toolbarContainer = createElementAtPosition(position.x, position.y)
toolbarContainer.className = 'chatgptbox-toolbar-container-not-queryable'
if (userConfig.displayMode === 'floatingToolbar') {
render(
<FloatingToolbar
session={initSession({ modelName: userConfig.modelName })}
selection={question}
container={toolbarContainer}
dockable={true}
triggered={true}
closeable={true}
prompt={question}
/>,
toolbarContainer,
)
return
}
const container = document.createElement('div')
container.id = 'chatgptbox-container'
render(
<DecisionCard
session={initSession({ modelName: (await getUserConfig()).modelName })}
session={initSession({ modelName: userConfig.modelName })}
question={question}
siteConfig={siteConfig}
container={container}
Expand Down
19 changes: 19 additions & 0 deletions src/popup/sections/GeneralPart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
Models,
ThemeMode,
TriggerMode,
DisplayMode,
isUsingMoonshotApi,
} from '../../config/index.mjs'
import Browser from 'webextension-polyfill'
Expand Down Expand Up @@ -118,6 +119,24 @@ export function GeneralPart({ config, updateConfig }) {
})}
</select>
</label>
<label>
<legend>{t('DisplayMode')}</legend>
<select
required
onChange={(e) => {
const mode = e.target.value
updateConfig({ displayMode: mode })
}}
>
{Object.entries(DisplayMode).map(([key, desc]) => {
return (
<option value={key} key={key} selected={key === config.displayMode}>
{t(desc)}
</option>
)
})}
</select>
</label>
<label>
<legend>{t('Theme')}</legend>
<select
Expand Down

0 comments on commit b96ba7c

Please sign in to comment.