Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

index.tsx 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { useTranslate } from '@/hooks/common-hooks';
  2. import { DownOutlined, GithubOutlined } from '@ant-design/icons';
  3. import { Dropdown, MenuProps, Space } from 'antd';
  4. import camelCase from 'lodash/camelCase';
  5. import React from 'react';
  6. import User from '../user';
  7. import { useTheme } from '@/components/theme-provider';
  8. import { LanguageList, LanguageMap } from '@/constants/common';
  9. import { useChangeLanguage } from '@/hooks/logic-hooks';
  10. import { useFetchUserInfo } from '@/hooks/user-setting-hooks';
  11. import { MoonIcon, SunIcon } from 'lucide-react';
  12. import styled from './index.less';
  13. const Circle = ({ children, ...restProps }: React.PropsWithChildren) => {
  14. return (
  15. <div {...restProps} className={styled.circle}>
  16. {children}
  17. </div>
  18. );
  19. };
  20. const handleGithubCLick = () => {
  21. window.open('https://github.com/infiniflow/ragflow', 'target');
  22. };
  23. const RightToolBar = () => {
  24. const { t } = useTranslate('common');
  25. const changeLanguage = useChangeLanguage();
  26. const { setTheme, theme } = useTheme();
  27. const {
  28. data: { language = 'English' },
  29. } = useFetchUserInfo();
  30. const handleItemClick: MenuProps['onClick'] = ({ key }) => {
  31. changeLanguage(key);
  32. };
  33. const items: MenuProps['items'] = LanguageList.map((x) => ({
  34. key: x,
  35. label: <span>{LanguageMap[x as keyof typeof LanguageMap]}</span>,
  36. })).reduce<MenuProps['items']>((pre, cur) => {
  37. return [...pre!, { type: 'divider' }, cur];
  38. }, []);
  39. const onMoonClick = React.useCallback(() => {
  40. setTheme('light');
  41. }, [setTheme]);
  42. const onSunClick = React.useCallback(() => {
  43. setTheme('dark');
  44. }, [setTheme]);
  45. return (
  46. <div className={styled.toolbarWrapper}>
  47. <Space wrap size={16}>
  48. <Dropdown menu={{ items, onClick: handleItemClick }} placement="bottom">
  49. <Space className={styled.language}>
  50. <b>{t(camelCase(language))}</b>
  51. <DownOutlined />
  52. </Space>
  53. </Dropdown>
  54. <Circle>
  55. <GithubOutlined onClick={handleGithubCLick} />
  56. </Circle>
  57. <Circle>
  58. {theme === 'dark' ? (
  59. <MoonIcon onClick={onMoonClick} size={20} />
  60. ) : (
  61. <SunIcon onClick={onSunClick} size={20} />
  62. )}
  63. </Circle>
  64. <User></User>
  65. </Space>
  66. </div>
  67. );
  68. };
  69. export default RightToolBar;