fix: program exception when Awesome data is empty (#248)

This commit is contained in:
lencx
2023-01-25 16:49:20 +08:00
parent 7aa70c83de
commit ca171b7c1b
4 changed files with 38 additions and 21 deletions

View File

@@ -1,5 +1,11 @@
# UPDATE LOG # UPDATE LOG
## v0.10.1
Fix:
- Program exception when `Awesome` data is empty (https://github.com/lencx/ChatGPT/issues/248)
## v0.10.0 ## v0.10.0
Fix: Fix:

View File

@@ -18,6 +18,11 @@ const SwitchOrigin: FC<SwitchOriginProps> = ({ name }) => {
const originName = `${name}_origin`; const originName = `${name}_origin`;
const isEnable = Form.useWatch(dashboardName, form); const isEnable = Form.useWatch(dashboardName, form);
let urlList = [{ title: 'ChatGPT', url: 'https://chat.openai.com', init: true }];
if (Array.isArray(list)) {
urlList = urlList.concat(list);
}
return ( return (
<> <>
<Form.Item <Form.Item
@@ -74,8 +79,7 @@ const SwitchOrigin: FC<SwitchOriginProps> = ({ name }) => {
name={originName} name={originName}
> >
<Select disabled={isEnable} showSearch {...DISABLE_AUTO_COMPLETE} optionLabelProp="url"> <Select disabled={isEnable} showSearch {...DISABLE_AUTO_COMPLETE} optionLabelProp="url">
{[{ title: 'ChatGPT', url: 'https://chat.openai.com', init: true }, ...list].map( {urlList.map((i, idx) => (
(i, idx) => (
<Select.Option <Select.Option
key={`${idx}_${i.url}`} key={`${idx}_${i.url}`}
label={i.title} label={i.title}
@@ -84,8 +88,7 @@ const SwitchOrigin: FC<SwitchOriginProps> = ({ name }) => {
> >
<Tag color={i.init ? 'orange' : 'geekblue'}>{i.title}</Tag> {i.url} <Tag color={i.init ? 'orange' : 'geekblue'}>{i.title}</Tag> {i.url}
</Select.Option> </Select.Option>
), ))}
)}
</Select> </Select>
</Form.Item> </Form.Item>
</> </>

View File

@@ -7,6 +7,10 @@
} }
} }
.markdown-body {
background-color: unset;
}
.about-tab { .about-tab {
.imgs { .imgs {
img { img {

View File

@@ -29,6 +29,7 @@ export default function Dashboard() {
if (!json) return; if (!json) return;
const categories = new Map(); const categories = new Map();
if (Array.isArray(json)) {
json?.forEach((i) => { json?.forEach((i) => {
if (!i.enable) return; if (!i.enable) return;
if (!categories.has(i.category)) { if (!categories.has(i.category)) {
@@ -36,8 +37,11 @@ export default function Dashboard() {
} }
categories.get(i?.category).push(i); categories.get(i?.category).push(i);
}); });
setList(Array.from(categories)); setList(Array.from(categories) || []);
}, [json?.length]); } else {
setList([]);
}
}, [JSON.stringify(json)]);
const handleLink = async (item: Record<string, any>) => { const handleLink = async (item: Record<string, any>) => {
await invoke('wa_window', { await invoke('wa_window', {