index.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * index
  3. * @author: oldj
  4. * @homepage: https://oldj.net
  5. */
  6. import { useModel } from '@@/plugin-model/useModel'
  7. import HostsEditor from '@renderer/components/Editor/HostsEditor'
  8. import { actions } from '@renderer/core/agent'
  9. import useOnBroadcast from '@renderer/core/useOnBroadcast'
  10. import events from '@root/common/events'
  11. import React, { useEffect, useState } from 'react'
  12. import styles from './index.less'
  13. interface Props {
  14. }
  15. const MainPanel = (props: Props) => {
  16. const { current_hosts } = useModel('useHostsData')
  17. const [system_hosts_content, setSystemHostsContent] = useState('')
  18. useEffect(() => {
  19. if (!current_hosts) {
  20. actions.getSystemHosts().then(value => setSystemHostsContent(value))
  21. }
  22. }, [current_hosts])
  23. useOnBroadcast(events.system_hosts_updated, () => {
  24. if (!current_hosts) {
  25. actions.getSystemHosts().then(value => setSystemHostsContent(value))
  26. }
  27. }, [current_hosts])
  28. return (
  29. <div className={styles.root}>
  30. <HostsEditor hosts={current_hosts || {
  31. id: '0',
  32. content: system_hosts_content,
  33. }}/>
  34. </div>
  35. )
  36. }
  37. export default MainPanel