|
1 | | -import { useChannelEvents } from '@api/channels' |
2 | 1 | import { Disclosure, Popover, Transition } from '@headlessui/react' |
3 | 2 | import pluralize from 'pluralize' |
4 | 3 | import clsx from 'clsx' |
5 | | -import { useState, useEffect, Fragment } from 'react' |
6 | | -import { |
7 | | - useIDE, |
8 | | - EnumErrorKey, |
9 | | - type ErrorIDE, |
10 | | - type ErrorKey, |
11 | | -} from '../../pages/ide/context' |
| 4 | +import { useState, Fragment } from 'react' |
| 5 | +import { useIDE, type ErrorIDE, type ErrorKey } from '../../pages/ide/context' |
12 | 6 | import { toDate, toDateFormat } from '@utils/index' |
13 | 7 | import { MinusCircleIcon, PlusCircleIcon } from '@heroicons/react/24/solid' |
14 | 8 | import { Divider } from '@components/divider/Divider' |
15 | 9 |
|
16 | 10 | export default function ReportErrors(): JSX.Element { |
17 | | - const subscribe = useChannelEvents() |
18 | | - |
19 | | - const { errors, addError } = useIDE() |
| 11 | + const { errors } = useIDE() |
20 | 12 |
|
21 | 13 | const [isShow, setIsShow] = useState(false) |
22 | 14 |
|
23 | | - useEffect(() => { |
24 | | - const unsubscribeErrors = subscribe<ErrorIDE>('errors', displayErrors) |
25 | | - |
26 | | - return () => { |
27 | | - unsubscribeErrors?.() |
28 | | - } |
29 | | - }, []) |
30 | | - |
31 | | - function displayErrors(data: ErrorIDE): void { |
32 | | - addError(EnumErrorKey.General, data) |
33 | | - } |
34 | | - |
35 | 15 | const hasError = errors.size > 0 |
36 | 16 |
|
37 | 17 | return ( |
38 | | - <> |
39 | | - <Popover |
40 | | - onMouseEnter={() => { |
41 | | - setIsShow(true) |
42 | | - }} |
43 | | - onMouseLeave={() => { |
44 | | - setIsShow(false) |
45 | | - }} |
46 | | - className="flex" |
47 | | - > |
48 | | - {() => ( |
49 | | - <> |
50 | | - <span |
| 18 | + <Popover |
| 19 | + onMouseEnter={() => { |
| 20 | + setIsShow(true) |
| 21 | + }} |
| 22 | + onMouseLeave={() => { |
| 23 | + setIsShow(false) |
| 24 | + }} |
| 25 | + className="flex" |
| 26 | + > |
| 27 | + {() => ( |
| 28 | + <> |
| 29 | + <span |
| 30 | + className={clsx( |
| 31 | + 'block ml-1 px-2 first-child:ml-0 rounded-full border whitespace-nowrap dark:text-neutral-100 text-xs text-center', |
| 32 | + hasError |
| 33 | + ? 'border-danger-500 text-danger-100 bg-danger-500 cursor-pointer' |
| 34 | + : 'border-neutral-500 cursor-default text-neutral-700', |
| 35 | + )} |
| 36 | + > |
| 37 | + {hasError ? ( |
| 38 | + <span> |
| 39 | + {errors.size} {pluralize('Error', errors.size)} |
| 40 | + </span> |
| 41 | + ) : ( |
| 42 | + <span>No Errors</span> |
| 43 | + )} |
| 44 | + </span> |
| 45 | + <Transition |
| 46 | + show={isShow && hasError} |
| 47 | + as={Fragment} |
| 48 | + enter="transition ease-out duration-200" |
| 49 | + enterFrom="opacity-0 translate-y-1" |
| 50 | + enterTo="opacity-100 translate-y-0" |
| 51 | + leave="transition ease-in duration-150" |
| 52 | + leaveFrom="opacity-100 translate-y-0" |
| 53 | + leaveTo="opacity-0 translate-y-1" |
| 54 | + > |
| 55 | + <Popover.Panel |
51 | 56 | className={clsx( |
52 | | - 'block ml-1 px-2 first-child:ml-0 rounded-full border whitespace-nowrap dark:text-neutral-100 text-xs text-center', |
53 | | - hasError |
54 | | - ? 'border-danger-500 text-danger-100 bg-danger-500 cursor-pointer' |
55 | | - : 'border-neutral-500 cursor-default text-neutral-700', |
| 57 | + 'absolute rounded-md top-20 right-2 z-[1000] bg-light p-2 transform overflow-hidden text-danger-700 shadow-2xl', |
| 58 | + 'w-[90vw] max-h-[80vh]', |
56 | 59 | )} |
57 | 60 | > |
58 | | - {hasError ? ( |
59 | | - <span> |
60 | | - {errors.size} {pluralize('Error', errors.size)} |
61 | | - </span> |
62 | | - ) : ( |
63 | | - <span>No Errors</span> |
64 | | - )} |
65 | | - </span> |
66 | | - <Transition |
67 | | - show={isShow && hasError} |
68 | | - as={Fragment} |
69 | | - enter="transition ease-out duration-200" |
70 | | - enterFrom="opacity-0 translate-y-1" |
71 | | - enterTo="opacity-100 translate-y-0" |
72 | | - leave="transition ease-in duration-150" |
73 | | - leaveFrom="opacity-100 translate-y-0" |
74 | | - leaveTo="opacity-0 translate-y-1" |
75 | | - > |
76 | | - <Popover.Panel |
| 61 | + <ul |
77 | 62 | className={clsx( |
78 | | - 'absolute rounded-md top-20 right-2 z-[1000] bg-light p-2 transform overflow-hidden text-danger-700 shadow-2xl', |
79 | | - 'w-[90vw] max-h-[80vh]', |
| 63 | + 'w-full bg-danger-10 py-4 pl-3 pr-1 rounded-md overflow-auto scrollbar scrollbar--vertical scrollbar--horizontal', |
| 64 | + 'max-w-[90vw] max-h-[80vh]', |
80 | 65 | )} |
81 | 66 | > |
82 | | - <ul |
83 | | - className={clsx( |
84 | | - 'w-full bg-danger-10 py-4 pl-3 pr-1 rounded-md overflow-auto scrollbar scrollbar--vertical scrollbar--horizontal', |
85 | | - 'max-w-[90vw] max-h-[80vh]', |
86 | | - )} |
87 | | - > |
88 | | - {Array.from(errors.entries()) |
89 | | - .reverse() |
90 | | - .map(([scope, error]) => ( |
91 | | - <li |
92 | | - key={`${scope}-${error.message}`} |
93 | | - className="mb-10" |
94 | | - > |
95 | | - <DisplayError |
96 | | - scope={scope} |
97 | | - error={error} |
98 | | - /> |
99 | | - </li> |
100 | | - ))} |
101 | | - </ul> |
102 | | - </Popover.Panel> |
103 | | - </Transition> |
104 | | - </> |
105 | | - )} |
106 | | - </Popover> |
107 | | - </> |
| 67 | + {Array.from(errors.entries()) |
| 68 | + .reverse() |
| 69 | + .map(([scope, error]) => ( |
| 70 | + <li |
| 71 | + key={`${scope}-${error.message}`} |
| 72 | + className="mb-10" |
| 73 | + > |
| 74 | + <DisplayError |
| 75 | + scope={scope} |
| 76 | + error={error} |
| 77 | + /> |
| 78 | + </li> |
| 79 | + ))} |
| 80 | + </ul> |
| 81 | + </Popover.Panel> |
| 82 | + </Transition> |
| 83 | + </> |
| 84 | + )} |
| 85 | + </Popover> |
108 | 86 | ) |
109 | 87 | } |
110 | 88 |
|
|
0 commit comments