-
Notifications
You must be signed in to change notification settings - Fork 103
/
ErrorLog.svelte
58 lines (52 loc) · 1.63 KB
/
ErrorLog.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<script lang="typescript">
import { Button, Text } from 'shared/components'
import { errorLog } from '@core/error'
import { localize } from '@core/i18n'
import { closePopup } from '@auxiliary/popup'
import { setClipboard } from '@core/utils'
function handleClearClick(): () => void {
errorLog.set([])
closePopup()
}
function handleCopyClick(): () => void {
const str = []
for (const err of $errorLog) {
str.push(new Date(err.time).toUTCString())
str.push(`${err.type}: ${err.message}`)
str.push('')
}
setClipboard(str.join('\r\n'))
}
</script>
<div class="mb-5">
<Text type="h4">{localize('popups.errorLog.title')}</Text>
</div>
<div class="log overflow-y-auto">
{#if $errorLog.length > 0}
{#each $errorLog as error}
<div class="mb-7">
<Text type="p" secondary>{new Date(error.time).toUTCString()}</Text>
<Text type="p">
{error.type}:
{error.message}
</Text>
</div>
{/each}
{:else}
<Text type="p" secondary>{localize('popups.errorLog.empty')}</Text>
{/if}
</div>
{#if $errorLog.length > 0}
<div class="flex w-full justify-center pt-8 space-x-4">
<Button classes="w-1/2" onClick={handleClearClick}>{localize('actions.clear')}</Button>
<Button classes="w-1/2" onClick={handleCopyClick}>{localize('actions.copy')}</Button>
</div>
{/if}
<style type="text/scss">
.log {
max-height: 50vh;
@screen md {
max-height: 30vh;
}
}
</style>