Skip to content

Commit

Permalink
fix: revert hide ask ai button (#1539)
Browse files Browse the repository at this point in the history
  • Loading branch information
boojack authored Apr 16, 2023
1 parent 58fa000 commit 73b8d1d
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 63 deletions.
2 changes: 0 additions & 2 deletions api/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,4 @@ type SystemStatus struct {
StorageServiceID int `json:"storageServiceId"`
// Local storage path
LocalStoragePath string `json:"localStoragePath"`
// Local storage path
OpenAIConfig OpenAIConfig `json:"openAIConfig"`
}
11 changes: 0 additions & 11 deletions server/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
},
StorageServiceID: api.DatabaseStorage,
LocalStoragePath: "",
OpenAIConfig: api.OpenAIConfig{
Key: "",
Host: "",
},
}

systemSettingList, err := s.Store.FindSystemSettingList(ctx, &api.SystemSettingFind{})
Expand Down Expand Up @@ -99,13 +95,6 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
systemStatus.StorageServiceID = int(baseValue.(float64))
} else if systemSetting.Name == api.SystemSettingLocalStoragePathName {
systemStatus.LocalStoragePath = baseValue.(string)
} else if systemSetting.Name == api.SystemSettingOpenAIConfigName {
openAIConfig := api.OpenAIConfig{}
err := json.Unmarshal([]byte(systemSetting.Value), &openAIConfig)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to unmarshal system setting open ai config value").SetInternal(err)
}
systemStatus.OpenAIConfig = openAIConfig
}
}

Expand Down
2 changes: 1 addition & 1 deletion web/src/components/AskAIDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const AskAIDialog: React.FC<Props> = (props: Props) => {
</div>
<div className="dialog-content-container !w-112 max-w-full">
{messageList.map((message, index) => (
<div key={index} className="w-full flex flex-col justify-start items-start mt-4 space-y-2">
<div key={index} className="w-full flex flex-col justify-start items-start space-y-2">
{message.role === "user" ? (
<div className="w-full flex flex-row justify-end items-start pl-6">
<span className="word-break shadow rounded-lg rounded-tr-none px-3 py-2 opacity-80 bg-gray-100 dark:bg-zinc-700">
Expand Down
20 changes: 8 additions & 12 deletions web/src/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect } from "react";
import { NavLink, useLocation } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { useGlobalStore, useLayoutStore, useUserStore } from "@/store/module";
import { useLayoutStore, useUserStore } from "@/store/module";
import { resolution } from "@/utils/layout";
import Icon from "./Icon";
import showSettingDialog from "./SettingDialog";
Expand All @@ -14,10 +14,8 @@ const Header = () => {
const { t } = useTranslation();
const location = useLocation();
const userStore = useUserStore();
const globalStore = useGlobalStore();
const layoutStore = useLayoutStore();
const showHeader = layoutStore.state.showHeader;
const showAskAI = globalStore.showAskAI();
const isVisitorMode = userStore.isVisitorMode() && !userStore.state.user;

useEffect(() => {
Expand Down Expand Up @@ -109,15 +107,13 @@ const Header = () => {
</NavLink>
{!isVisitorMode && (
<>
{showAskAI && (
<button
id="header-ask-ai"
className="px-4 pr-5 py-2 rounded-lg flex flex-row items-center text-lg text-gray-800 dark:text-gray-300 hover:bg-white hover:shadow dark:hover:bg-zinc-700"
onClick={() => showAskAIDialog()}
>
<Icon.Bot className="mr-3 w-6 h-auto opacity-70" /> {t("ask-ai.title")}
</button>
)}
<button
id="header-ask-ai"
className="px-4 pr-5 py-2 rounded-lg flex flex-row items-center text-lg text-gray-800 dark:text-gray-300 hover:bg-white hover:shadow dark:hover:bg-zinc-700"
onClick={() => showAskAIDialog()}
>
<Icon.Bot className="mr-3 w-6 h-auto opacity-70" /> {t("ask-ai.title")}
</button>
<button
id="header-archived-memo"
className="px-4 pr-5 py-2 rounded-lg flex flex-row items-center text-lg text-gray-800 dark:text-gray-300 hover:bg-white hover:shadow dark:hover:bg-zinc-700"
Expand Down
49 changes: 26 additions & 23 deletions web/src/components/Settings/SystemSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ interface State {
disablePublicMemos: boolean;
additionalStyle: string;
additionalScript: string;
openAIConfig: OpenAIConfig;
}

const SystemSection = () => {
Expand All @@ -30,13 +29,25 @@ const SystemSection = () => {
additionalStyle: systemStatus.additionalStyle,
additionalScript: systemStatus.additionalScript,
disablePublicMemos: systemStatus.disablePublicMemos,
openAIConfig: systemStatus.openAIConfig,
});
const [openAIConfig, setOpenAIConfig] = useState<OpenAIConfig>({
key: "",
host: "",
});

useEffect(() => {
globalStore.fetchSystemStatus();
}, []);

useEffect(() => {
api.getSystemSetting().then(({ data: { data: systemSettings } }) => {
const openAIConfigSetting = systemSettings.find((setting) => setting.name === "openai-config");
if (openAIConfigSetting) {
setOpenAIConfig(JSON.parse(openAIConfigSetting.value));
}
});
}, []);

useEffect(() => {
setState({
...state,
Expand All @@ -45,7 +56,6 @@ const SystemSection = () => {
additionalStyle: systemStatus.additionalStyle,
additionalScript: systemStatus.additionalScript,
disablePublicMemos: systemStatus.disablePublicMemos,
openAIConfig: systemStatus.openAIConfig,
});
}, [systemStatus]);

Expand Down Expand Up @@ -87,39 +97,32 @@ const SystemSection = () => {
};

const handleOpenAIConfigKeyChanged = (value: string) => {
setState({
...state,
openAIConfig: {
...state.openAIConfig,
key: value,
},
setOpenAIConfig({
...openAIConfig,
key: value,
});
};

const handleOpenAIConfigHostChanged = (value: string) => {
setOpenAIConfig({
...openAIConfig,
host: value,
});
};

const handleSaveOpenAIConfig = async () => {
try {
await api.upsertSystemSetting({
name: "openai-config",
value: JSON.stringify(state.openAIConfig),
value: JSON.stringify(openAIConfig),
});
globalStore.setSystemStatus({ openAIConfig: state.openAIConfig });
} catch (error) {
console.error(error);
return;
}
toast.success("OpenAI Config updated");
};

const handleOpenAIConfigHostChanged = (value: string) => {
setState({
...state,
openAIConfig: {
...state.openAIConfig,
host: value,
},
});
};

const handleAdditionalStyleChanged = (value: string) => {
setState({
...state,
Expand Down Expand Up @@ -222,7 +225,7 @@ const SystemSection = () => {
fontSize: "14px",
}}
placeholder={t("setting.system-section.openai-api-key-placeholder")}
value={state.openAIConfig.key}
value={openAIConfig.key}
onChange={(event) => handleOpenAIConfigKeyChanged(event.target.value)}
/>
<div className="form-label mt-2">
Expand All @@ -235,7 +238,7 @@ const SystemSection = () => {
fontSize: "14px",
}}
placeholder={t("setting.system-section.openai-api-host-placeholder")}
value={state.openAIConfig.host}
value={openAIConfig.host}
onChange={(event) => handleOpenAIConfigHostChanged(event.target.value)}
/>
<Divider className="!mt-3 !my-4" />
Expand Down
2 changes: 1 addition & 1 deletion web/src/locales/zh-Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@
},
"ask-ai": {
"placeholder": "随便问",
"title": "问AI",
"title": "Ask AI",
"not-enabled": "您尚未设置 OpenAI API 密钥。",
"go-to-settings": "前往设置"
},
Expand Down
8 changes: 0 additions & 8 deletions web/src/store/module/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ export const initialGlobalState = async () => {
appearance: "system",
externalUrl: "",
},
openAIConfig: {
key: "",
host: "",
},
} as SystemStatus,
};

Expand Down Expand Up @@ -69,10 +65,6 @@ export const useGlobalStore = () => {
isDev: () => {
return state.systemStatus.profile.mode !== "prod";
},
showAskAI: () => {
const openAIConfig = state.systemStatus.openAIConfig;
return Boolean(openAIConfig.key && openAIConfig.host);
},
fetchSystemStatus: async () => {
const { data: systemStatus } = (await api.getSystemStatus()).data;
store.dispatch(setGlobalState({ systemStatus: systemStatus }));
Expand Down
4 changes: 0 additions & 4 deletions web/src/store/reducer/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ const globalSlice = createSlice({
appearance: "system",
externalUrl: "",
},
openAIConfig: {
key: "",
host: "",
},
},
} as State,
reducers: {
Expand Down
1 change: 0 additions & 1 deletion web/src/types/modules/system.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ interface SystemStatus {
customizedProfile: CustomizedProfile;
storageServiceId: number;
localStoragePath: string;
openAIConfig: OpenAIConfig;
}

interface SystemSetting {
Expand Down

0 comments on commit 73b8d1d

Please sign in to comment.