Skip to content

Commit

Permalink
feat: fixed the issue that some PDF documents could not be displayed …
Browse files Browse the repository at this point in the history
…on the chunk list page in small screens and logout (#105)

* feat: logout

* feat: fixed the issue that some PDF documents could not be displayed on the chunk list page in small screens
  • Loading branch information
cike8899 committed Mar 7, 2024
1 parent aaf3084 commit 6048926
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 50 deletions.
10 changes: 10 additions & 0 deletions web/src/hooks/userSettingHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,13 @@ export const useSelectParserList = (): Array<{

return parserList;
};

export const useLogout = () => {
const dispatch = useDispatch();

const logout = useCallback((): number => {
return dispatch<any>({ type: 'loginModel/logout' });
}, [dispatch]);

return logout;
};
24 changes: 16 additions & 8 deletions web/src/layouts/components/user/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import { useFetchUserInfo, useSelectUserInfo } from '@/hooks/userSettingHook';
import {
useFetchUserInfo,
useLogout,
useSelectUserInfo,
} from '@/hooks/userSettingHook';
import authorizationUtil from '@/utils/authorizationUtil';
import type { MenuProps } from 'antd';
import { Avatar, Button, Dropdown } from 'antd';
import React, { useMemo } from 'react';
import React, { useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { history } from 'umi';

const App: React.FC = () => {
const { t } = useTranslation();
const userInfo = useSelectUserInfo();
const logout = useLogout();

const logout = () => {
authorizationUtil.removeAll();
history.push('/login');
};
const handleLogout = useCallback(async () => {
const retcode = await logout();
if (retcode === 0) {
authorizationUtil.removeAll();
history.push('/login');
}
}, [logout]);

const toSetting = () => {
history.push('/setting');
Expand All @@ -23,7 +31,7 @@ const App: React.FC = () => {
return [
{
key: '1',
onClick: logout,
onClick: handleLogout,
label: <Button type="text">{t('header.logout')}</Button>,
},
{
Expand All @@ -32,7 +40,7 @@ const App: React.FC = () => {
label: <Button type="text">{t('header.setting')}</Button>,
},
];
}, [t]);
}, [t, handleLogout]);

useFetchUserInfo();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
.chunkText;
}

.chunkCard {
width: 100%;
}

.cardSelected {
background-color: @selectedBackgroundColor;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Image from '@/components/image';
import { IChunk } from '@/interfaces/database/knowledge';
import { Card, Checkbox, CheckboxProps, Flex, Popover, Switch } from 'antd';
import classNames from 'classnames';
import { useState } from 'react';

import styles from './index.less';

interface IProps {
Expand Down Expand Up @@ -44,33 +46,35 @@ const ChunkCard = ({
};

return (
<div>
<Card className={selected ? styles.cardSelected : ''}>
<Flex gap={'middle'} justify={'space-between'}>
<Checkbox onChange={handleCheck} checked={checked}></Checkbox>
{item.img_id && (
<Popover
placement="topRight"
content={
<Image id={item.img_id} className={styles.imagePreview}></Image>
}
>
<Image id={item.img_id} className={styles.image}></Image>
</Popover>
)}
<Card
className={classNames(styles.chunkCard, {
[styles.cardSelected]: selected,
})}
>
<Flex gap={'middle'} justify={'space-between'}>
<Checkbox onChange={handleCheck} checked={checked}></Checkbox>
{item.img_id && (
<Popover
placement="topRight"
content={
<Image id={item.img_id} className={styles.imagePreview}></Image>
}
>
<Image id={item.img_id} className={styles.image}></Image>
</Popover>
)}

<section
onDoubleClick={handleContentDoubleClick}
onClick={handleContentClick}
className={styles.content}
dangerouslySetInnerHTML={{ __html: item.content_with_weight }}
></section>
<div>
<Switch checked={enabled} onChange={onChange} />
</div>
</Flex>
</Card>
</div>
<section
onDoubleClick={handleContentDoubleClick}
onClick={handleContentClick}
className={styles.content}
dangerouslySetInnerHTML={{ __html: item.content_with_weight }}
></section>
<div>
<Switch checked={enabled} onChange={onChange} />
</div>
</Flex>
</Card>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
justify-content: space-between;
}

.pagePdfWrapper {
width: 60%;
}

.pageContent {
flex: 1;
width: 100%;
Expand All @@ -29,12 +33,11 @@
}

.chunkContainer {
height: calc(100vh - 320px);
overflow: auto;
width: 100%;
height: calc(100vh - 332px);
}

.pageFooter {
padding-top: 10px;
height: 32px;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const Chunk = () => {
const { removeChunk } = useDeleteChunkByIds();
const documentInfo = useSelectDocumentInfo();
const { handleChunkCardClick, selectedChunkId } = useHandleChunkCardClick();
const isPdf = documentInfo.type === 'pdf';

const getChunkList = useCallback(() => {
const payload: PayloadType = {
Expand Down Expand Up @@ -164,7 +165,7 @@ const Chunk = () => {
></ChunkToolBar>
<Divider></Divider>
<Flex flex={1} gap={'middle'}>
<Flex flex={1} vertical>
<Flex vertical className={isPdf ? styles.pagePdfWrapper : ''}>
<div className={styles.pageContent}>
<Spin spinning={loading} className={styles.spin} size="large">
<Space
Expand Down Expand Up @@ -204,7 +205,7 @@ const Chunk = () => {
</div>
</Flex>

{documentInfo.type === 'pdf' && (
{isPdf && (
<section className={styles.documentPreview}>
<DocumentPreview
selectedChunkId={selectedChunkId}
Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/chat/chat-container/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ const MessageItem = ({
<Flex vertical gap={8} flex={1}>
<b>{isAssistant ? '' : userInfo.nickname}</b>
<div className={styles.messageText}>
{item.content ? (
{item.content !== '' ? (
<Markdown
rehypePlugins={[rehypeWrapReference]}
components={
Expand Down
23 changes: 13 additions & 10 deletions web/src/pages/login/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,13 @@ const model: DvaModel<LoginModelState> = {
};
},
},
subscriptions: {
setup({ dispatch, history }) {
history.listen((location) => {});
},
},
effects: {
*login({ payload = {} }, { call, put }) {
*login({ payload = {} }, { call }) {
const { data, response } = yield call(userService.login, payload);
const { retcode, data: res } = data;
const authorization = response.headers.get(Authorization);
if (retcode === 0) {
message.success('登录成功!');
message.success('logged!');
const token = res.access_token;
const userInfo = {
avatar: res.avatar,
Expand All @@ -51,15 +46,23 @@ const model: DvaModel<LoginModelState> = {
}
return retcode;
},
*register({ payload = {} }, { call, put }) {
const { data, response } = yield call(userService.register, payload);
*register({ payload = {} }, { call }) {
const { data } = yield call(userService.register, payload);
console.log();
const { retcode, data: res, retmsg } = data;
const { retcode } = data;
if (retcode === 0) {
message.success('注册成功!');
}
return retcode;
},
*logout({ payload = {} }, { call }) {
const { data } = yield call(userService.logout, payload);
const { retcode } = data;
if (retcode === 0) {
message.success('logout');
}
return retcode;
},
},
};
export default model;
5 changes: 5 additions & 0 deletions web/src/services/userService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import request from '@/utils/request';

const {
login,
logout,
register,
setting,
user_info,
Expand All @@ -20,6 +21,10 @@ const methods = {
url: login,
method: 'post',
},
logout: {
url: logout,
method: 'get',
},
register: {
url: register,
method: 'post',
Expand Down
1 change: 1 addition & 0 deletions web/src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export { api_host };
export default {
// 用户
login: `${api_host}/user/login`,
logout: `${api_host}/user/logout`,
register: `${api_host}/user/register`,
setting: `${api_host}/user/setting`,
user_info: `${api_host}/user/info`,
Expand Down

0 comments on commit 6048926

Please sign in to comment.