Skip to content

Commit

Permalink
💚 fix: setting crash #46
Browse files Browse the repository at this point in the history
  • Loading branch information
canisminor1990 committed Apr 22, 2023
1 parent afdbe53 commit 4f1a030
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 65 deletions.
114 changes: 57 additions & 57 deletions javascript/index.js

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions src/components/ExtraNetworkSidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,21 @@ const Sidebar: React.FC<SidebarProps> = ({ children, style }) => {
maxHeight
style={style}
placement="right"
defaultSize={{ width: setting.extraNetworkSidebarWidth }}
defaultSize={{ width: setting?.extraNetworkSidebarWidth || 340 }}
isExpand={expand}
onExpandChange={setExpand}
>
<View>
<SidebarView size={size}>{children}</SidebarView>
<Footer>
<ZoomInOutlined />
<ZoomSlider defaultValue={setting.extraNetworkCardSize} step={8} max={256} min={64} onChange={setSize} />
<ZoomSlider
defaultValue={setting?.extraNetworkCardSize || 86}
step={8}
max={256}
min={64}
onChange={setSize}
/>
</Footer>
</View>
</DraggablePanel>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Header/Setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface WebuiSetting {
extraNetworkCardSize: number
}

const defaultValue = {
export const defaultValue = {
sidebarWidth: 280,
enableExtraNetworkSidebar: true,
extraNetworkSidebarWidth: 340,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const Sidebar: React.FC<SidebarProps> = ({ children, loading, style }) => {
maxHeight
style={style}
placement="left"
defaultSize={{ width: setting.sidebarWidth }}
defaultSize={{ width: setting?.sidebarWidth || 280 }}
isExpand={expand}
onExpandChange={setExpand}
>
Expand Down
10 changes: 6 additions & 4 deletions src/pages/index/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Content, ExtraNetworkSidebar, Header, Sidebar } from '@/components'
import { WebuiSetting } from '@/components/Header/Setting'
import { WebuiSetting, defaultValue } from '@/components/Header/Setting'
import { useAppStore } from '@/store'
import { useLocalStorageState } from 'ahooks'
import { Spin } from 'antd'
Expand Down Expand Up @@ -38,7 +38,9 @@ interface AppProps {
}

const App: React.FC<AppProps> = ({ themeMode }) => {
const [setting] = useLocalStorageState<WebuiSetting>('SD-KITCHEN-SETTING')
const [setting] = useLocalStorageState<WebuiSetting>('SD-KITCHEN-SETTING', {
defaultValue,
})
const [currentTab, setCurrentTab] = useAppStore((st) => [st.currentTab, st.setCurrentTab], shallow)
const [loading, setLoading] = useState(true)
const sidebarRef: any = useRef<HTMLElement>()
Expand All @@ -64,7 +66,7 @@ const App: React.FC<AppProps> = ({ themeMode }) => {
if (sidebar) sidebarRef.current?.appendChild(sidebar)

// ExtraNetworkSidebar
if (setting.enableExtraNetworkSidebar) {
if (setting?.enableExtraNetworkSidebar) {
const txt2imgExtraNetworks = gradioApp().querySelector('div#txt2img_extra_networks')
const img2imgExtraNetworks = gradioApp().querySelector('div#img2img_extra_networks')
if (txt2imgExtraNetworks && img2imgExtraNetworks) {
Expand Down Expand Up @@ -107,7 +109,7 @@ const App: React.FC<AppProps> = ({ themeMode }) => {
)}
<div id="content" ref={mainRef} />
</Content>
{setting.enableExtraNetworkSidebar && (
{setting?.enableExtraNetworkSidebar && (
<ExtraNetworkSidebar style={['tab_txt2img', 'tab_img2img'].includes(currentTab) ? {} : { display: 'none' }}>
{loading && (
<LoadingBox>
Expand Down

0 comments on commit 4f1a030

Please sign in to comment.