Skip to content

Commit

Permalink
optimize: optimized code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ohh-889 committed Aug 15, 2024
1 parent d923752 commit f94b58b
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/hooks/src/use-svg-icon-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function useSvgIconRender(SvgIcon: ({ icon, localIcon, style, cla
}

if (!icon && !localIcon) {
return undefined;
return null;
}

return createElement(SvgIcon, { icon, localIcon, style });
Expand Down
4 changes: 2 additions & 2 deletions packages/materials/src/libs/admin-layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const AdminLayout: FC<AdminLayoutProps> = ({
style={cssVar}
>
<div
id={isWrapperScroll ? scrollElId : undefined}
id={isWrapperScroll ? scrollElId : ''}
className={classNames('h-full flex flex-col', scrollWrapperClass, commonClass, {
'overflow-y-auto': isWrapperScroll
})}
Expand Down Expand Up @@ -203,7 +203,7 @@ const AdminLayout: FC<AdminLayoutProps> = ({

{/* Main Content */}
<main
id={isContentScroll ? scrollElId : undefined}
id={isContentScroll ? scrollElId : ''}
className={classNames('flex flex-col flex-grow bg-layout', commonClass, contentClass, leftGapClass, {
'overflow-y-auto': isContentScroll
})}
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const FallbackRender: FC<Props> = ({ error }) => {
return (
<div className="size-full min-h-520px flex-col-center gap-24px overflow-hidden">
<div className="flex text-400px text-primary">
<SvgIcon localIcon="service-error"></SvgIcon>
<SvgIcon localIcon="service-error" />
</div>
<pre>{error.message}</pre>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/hooks/common/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function useLogin() {
startLoading();
await dispatch(login(params));
const userName = dispatch(getUerName());

if (userName) {
dispatch(initAuthRoute());
if (redirect) {
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/common/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export function useTableOperate<T extends TableData = TableData>(
}

/** the editing row data */
const [editingData, setEditingData] = useState<T | undefined>(undefined);
const [editingData, setEditingData] = useState<T>();

function handleEdit(id: T['id']) {
setOperateType('edit');
Expand Down Expand Up @@ -204,7 +204,7 @@ export function useTableOperate<T extends TableData = TableData>(

export function useTableScroll(scrollX: number = 702) {
const tableWrapperRef = useRef<HTMLDivElement>(null);
// const height = tableWrapperRef.current?.nativeElement.clientHeight;

const height = tableWrapperRef.current?.clientHeight;

const scrollConfig = {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/manage/user/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export function Component() {
loading={loading}
dataSource={data}
columns={columns}
></Table>
/>
<UserOperateDrawer
open={drawerVisible}
rowData={editingData}
Expand Down
8 changes: 2 additions & 6 deletions src/store/slice/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,10 @@ export const { selectToken, selectUserInfo } = authSlice.selectors;
export const { login, resetAuth } = authSlice.actions;
// We can also write thunks by hand, which may contain both sync and async logic.
// Here's an example of conditionally dispatching actions based on current state.
export const getUerName = (): AppThunk<string | undefined> => (_, getState) => {
export const getUerName = (): AppThunk<string> => (_, getState) => {
const pass = selectToken(getState());

if (pass) {
const { userName } = selectUserInfo(getState());
return userName;
}
return undefined;
return pass ? selectUserInfo(getState()).userName : '';
};

/** is super role in static route */
Expand Down

0 comments on commit f94b58b

Please sign in to comment.