Skip to content

Commit

Permalink
♻️ refactor(wip): refactor with @lobehub/ui
Browse files Browse the repository at this point in the history
  • Loading branch information
canisminor1990 committed Jun 18, 2023
1 parent e9e51e6 commit e116458
Show file tree
Hide file tree
Showing 8 changed files with 874 additions and 501 deletions.
2 changes: 1 addition & 1 deletion .releaserc.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('@lobehub/lint/dist/semantic-release');
module.exports = require('@lobehub/lint').semanticRelease;
1,051 changes: 753 additions & 298 deletions javascript/index.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@ant-design/icons": "^5",
"@commitlint/cli": "^17",
"@lobehub/lint": "latest",
"@lobehub/ui": "latest",
"@types/lodash-es": "^4",
"@types/node": "^20",
"@types/react": "^18",
Expand All @@ -62,7 +63,7 @@
"@umijs/lint": "^4",
"ahooks": "^3",
"antd": "^5",
"antd-style": "^3",
"antd-style": "latest",
"babel-plugin-styled-components": "^2",
"browserslist": "^4",
"commitlint": "^17",
Expand All @@ -83,14 +84,13 @@
"react-dnd": "^16",
"react-dnd-html5-backend": "^16",
"react-dom": "^18",
"react-font-loader": "^2",
"react-layout-kit": "^1",
"react-rnd": "^10",
"react-tag-input": "^6",
"remark": "^14",
"remark-cli": "^11",
"semantic-release": "^21",
"styled-components": "^5",
"styled-components": "latest",
"stylelint": "^15",
"typescript": "^5",
"umi": "^4",
Expand Down
96 changes: 48 additions & 48 deletions src/components/ExtraNetworkSidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ZoomInOutlined } from '@ant-design/icons';
import { Slider } from 'antd';
import { useResponsive } from 'antd-style';
import { type CSSProperties, type ReactNode, memo, useEffect, useState } from 'react';
import styled, { createGlobalStyle } from 'styled-components';
import { shallow } from 'zustand/shallow';
import {ZoomInOutlined} from '@ant-design/icons';
import {DraggablePanel} from '@lobehub/ui';
import {Slider} from 'antd';
import {useResponsive} from 'antd-style';
import {type CSSProperties, type ReactNode, memo, useEffect, useState} from 'react';
import styled, {createGlobalStyle} from 'styled-components';
import {shallow} from 'zustand/shallow';

import { DraggablePanel } from '@/components';
import { useAppStore } from '@/store';
import {useAppStore} from '@/store';

const GlobalStyle = createGlobalStyle`
button#txt2img_extra_networks,
Expand Down Expand Up @@ -40,11 +40,11 @@ const SidebarView = styled.div<{ size: number }>`
.extra-network-cards,
.extra-network-thumbs {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(${({ size }) => size}px, 1fr));
grid-template-columns: repeat(auto-fill, minmax(${({size}) => size}px, 1fr));
> .card {
width: var(--fill-available) !important;
height: ${({ size }) => size * 1.5}px !important;
height: ${({size}) => size * 1.5}px !important;
}
}
`;
Expand All @@ -71,44 +71,44 @@ interface SidebarProps {
style?: CSSProperties;
}

const Sidebar = memo<SidebarProps>(({ children, style }) => {
const { mobile } = useResponsive();
const [setting] = useAppStore((st) => [st.setting], shallow);
const [mode] = useState<'fixed' | 'float'>(setting.extraNetworkFixedMode);
const [expand, setExpand] = useState<boolean>(setting.extraNetworkSidebarExpand);
const [size, setSize] = useState<number>(setting?.extraNetworkCardSize || 86);

useEffect(() => {
if (mobile) setExpand(false);
}, []);

return (
<>
<GlobalStyle />
<DraggablePanel
defaultSize={{ width: setting.extraNetworkSidebarWidth }}
expand={expand}
minWidth={setting.extraNetworkSidebarWidth}
mode={mode}
onExpandChange={setExpand}
pin={mode === 'fixed'}
placement="right"
style={{
display: 'flex',
flexDirection: 'column',
...style,
}}
>
<View>
<SidebarView size={size}>{children}</SidebarView>
<Footer>
<ZoomInOutlined />
<ZoomSlider defaultValue={size} max={256} min={64} onChange={setSize} step={8} />
</Footer>
</View>
</DraggablePanel>
</>
);
const Sidebar = memo<SidebarProps>(({children, style}) => {
const {mobile} = useResponsive();
const [setting] = useAppStore((st) => [st.setting], shallow);
const [mode] = useState<'fixed' | 'float'>(setting.extraNetworkFixedMode);
const [expand, setExpand] = useState<boolean>(setting.extraNetworkSidebarExpand);
const [size, setSize] = useState<number>(setting?.extraNetworkCardSize || 86);

useEffect(() => {
if (mobile) setExpand(false);
}, []);

return (
<>
<GlobalStyle />
<DraggablePanel
defaultSize={{width: setting.extraNetworkSidebarWidth}}
expand={expand}
minWidth={setting.extraNetworkSidebarWidth}
mode={mode}
onExpandChange={setExpand}
pin={mode === 'fixed'}
placement="right"
style={{
display: 'flex',
flexDirection: 'column',
...style,
}}
>
<View>
<SidebarView size={size}>{children}</SidebarView>
<Footer>
<ZoomInOutlined />
<ZoomSlider defaultValue={size} max={256} min={64} onChange={setSize} step={8} />
</Footer>
</View>
</DraggablePanel>
</>
);
});

export default Sidebar;
68 changes: 12 additions & 56 deletions src/components/Header/Nav.tsx
Original file line number Diff line number Diff line change
@@ -1,77 +1,33 @@
import type {MenuProps} from 'antd';
import {Menu} from 'antd';
import {TabsNav, type TabsNavProps} from '@lobehub/ui';
import {memo, useEffect, useState} from 'react';
import styled from 'styled-components';

/******************************************************
*********************** Style *************************
******************************************************/
const getNavButtons: HTMLButtonElement[] | any = () =>
gradioApp().querySelectorAll('#tabs > .tab-nav:first-child button') || [];

const NavBar = styled(Menu)`
overflow: hidden;
flex: 1;
line-height: 1;
border: none;
.ant-menu-overflow-item {
padding: 8px 12px;
color: var(--color-text-secondary);
border-radius: 4px !important;
&::after {
display: none !important;
}
&:hover {
color: var(--color-text);
background: var(--color-fill-tertiary);
}
&.ant-menu-item-selected {
font-weight: 600;
color: var(--color-text);
}
}
`;

/******************************************************
************************* Dom *************************
******************************************************/

const onClick: MenuProps['onClick'] = (e: any) => {
const buttons: HTMLButtonElement[] | any = gradioApp().querySelectorAll(
'#tabs > .tab-nav:first-child button',
);
buttons[Number(e.key)]?.click();
const onChange: TabsNavProps['onChange'] = (activeKey) => {
const buttons = getNavButtons();
buttons[Number(activeKey)]?.click();
};

const Nav = memo(() => {
const [items, setItems] = useState<MenuProps['items']>([]);
const [items, setItems] = useState<TabsNavProps['items']>([]);

useEffect(() => {
onUiLoaded(() => {
const buttons = gradioApp().querySelectorAll('#tabs > .tab-nav:first-child button');
const list: MenuProps['items'] | any = [];
buttons.forEach((button: HTMLButtonElement | any, index) => {
const buttons = getNavButtons();
const list: TabsNavProps['items'] | any = [];
buttons.forEach((button: HTMLButtonElement | any, index: number) => {

Check warning on line 19 in src/components/Header/Nav.tsx

View workflow job for this annotation

GitHub Actions / test

Use `for…of` instead of `.forEach(…)`
button.id = `kitchen-nav-${index}`;
list.push({
key: String(index),
label: button.textContent,
});
});
setItems(list);
setItems(list.filter(Boolean));
});
}, []);

return (
<NavBar
defaultActiveFirst
defaultSelectedKeys={['0']}
items={items}
mode="horizontal"
onClick={onClick}
/>
);
return <TabsNav items={items} onChange={onChange} />;
});

export default Nav;
71 changes: 21 additions & 50 deletions src/components/Header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import {BoldOutlined, GithubOutlined} from '@ant-design/icons';
import {Header as H} from '@lobehub/ui';
import {Button, Modal, Space} from 'antd';
import {useResponsive} from 'antd-style';
import qs from 'query-string';
import {type ReactNode, memo, useCallback, useEffect, useState} from 'react';
import styled from 'styled-components';
import {type ReactNode, memo, useCallback, useState} from 'react';
import {shallow} from 'zustand/shallow';

import {DraggablePanel} from '@/components';
import {useAppStore} from '@/store';

import Giscus from './Giscus';
Expand All @@ -15,39 +13,14 @@ import Nav from './Nav';
import Setting from './Setting';
import {civitaiLogo, themeIcon} from './style';

/******************************************************
*********************** Style *************************
******************************************************/

const HeaderView = styled.div`
display: flex;
flex-wrap: nowrap;
gap: 12px;
align-items: center;
justify-content: space-between;
height: var(--fill-available);
padding: 16px 24px;
`;

/******************************************************
************************* Dom *************************
******************************************************/

interface HeaderProps {
children: ReactNode;
}

const Header = memo<HeaderProps>(({children}) => {
const [themeMode] = useAppStore((st) => [st.themeMode], shallow);
const {mobile} = useResponsive();
const [expand, setExpand] = useState<boolean>(true);
const [isModalOpen, setIsModalOpen] = useState(false);

useEffect(() => {
if (mobile) setExpand(false);
}, []);

const handleSetTheme = useCallback(() => {
const theme = themeMode === 'light' ? 'dark' : 'light';
const gradioURL = qs.parseUrl(window.location.href);
Expand All @@ -61,25 +34,8 @@ const Header = memo<HeaderProps>(({children}) => {

return (
<>
<DraggablePanel
defaultSize={{height: 'auto'}}
expand={expand}
minHeight={64}
onExpandChange={setExpand}
placement="top"
>
<HeaderView id="header" style={{flexDirection: mobile ? 'column' : 'row'}}>
<a
href="https://github.com/canisminor1990/sd-webui-kitchen-theme"
rel="noreferrer"
target="_blank"
>
<Logo themeMode={themeMode} />
</a>

<Nav />
{children}

<H
actions={
<Space.Compact>
<a href="https://civitai.com/" rel="noreferrer" target="_blank">
<Button icon={civitaiLogo} title="Civitai" />
Expand All @@ -95,8 +51,23 @@ const Header = memo<HeaderProps>(({children}) => {
<Setting />
<Button icon={themeIcon[themeMode]} onClick={handleSetTheme} title="Switch Theme" />
</Space.Compact>
</HeaderView>
</DraggablePanel>
}
logo={
<a
href="https://github.com/canisminor1990/sd-webui-kitchen-theme"
rel="noreferrer"
target="_blank"
>
<Logo themeMode={themeMode} />
</a>
}
nav={
<>
<Nav />
{children}
</>
}
/>
<Modal
footer={false}
onCancel={handleCancel}
Expand Down
Loading

0 comments on commit e116458

Please sign in to comment.