Adding a click to copy feature in SystemInfo
This commit is contained in:
parent
ef909b475b
commit
95cfa8c8d7
|
@ -0,0 +1,3 @@
|
||||||
|
.clickPrompt {
|
||||||
|
font-style: italic;
|
||||||
|
}
|
|
@ -4,10 +4,19 @@ import {
|
||||||
ListItemIcon,
|
ListItemIcon,
|
||||||
ListItemText,
|
ListItemText,
|
||||||
} from '@suid/material';
|
} from '@suid/material';
|
||||||
import { Component, createEffect, createSignal, For, Show } from 'solid-js';
|
import {
|
||||||
|
Component,
|
||||||
|
createEffect,
|
||||||
|
createSignal,
|
||||||
|
For,
|
||||||
|
onMount,
|
||||||
|
Show,
|
||||||
|
} from 'solid-js';
|
||||||
import SystemSecurityUpdateWarningIcon from '@suid/icons-material/SystemSecurityUpdateWarning';
|
import SystemSecurityUpdateWarningIcon from '@suid/icons-material/SystemSecurityUpdateWarning';
|
||||||
import Dialog from '../dialog';
|
import Dialog from '../dialog';
|
||||||
import dispatch from '../../workers/dispatcher-main';
|
import dispatch from '../../workers/dispatcher-main';
|
||||||
|
import { sleep } from '../../lib/async-wait';
|
||||||
|
import style from './SystemInfo.module.css';
|
||||||
|
|
||||||
const [error, setError] = createSignal<any[]>([]);
|
const [error, setError] = createSignal<any[]>([]);
|
||||||
|
|
||||||
|
@ -63,6 +72,35 @@ const SystemInfo: Component<Props> = (props) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let content: any;
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
if (!!content) {
|
||||||
|
content.onclick = function () {
|
||||||
|
document.execCommand('copy');
|
||||||
|
};
|
||||||
|
|
||||||
|
content.addEventListener('copy', function (event: any) {
|
||||||
|
event.preventDefault();
|
||||||
|
if (event.clipboardData) {
|
||||||
|
event.clipboardData.setData('text/plain', content.textContent);
|
||||||
|
console.log(event.clipboardData.getData('text'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const clickHandler = async (event: any) => {
|
||||||
|
const range = document.createRange();
|
||||||
|
range.selectNode(content);
|
||||||
|
window.getSelection()?.removeAllRanges();
|
||||||
|
window.getSelection()?.addRange(range);
|
||||||
|
document.execCommand('copy');
|
||||||
|
await sleep(300);
|
||||||
|
window.getSelection()?.removeAllRanges();
|
||||||
|
console.log({ caller: 'SystemInfo / clickHandler', event, range });
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ListItem>
|
<ListItem>
|
||||||
|
@ -79,23 +117,26 @@ const SystemInfo: Component<Props> = (props) => {
|
||||||
closeHandler={() => setOpen(false)}
|
closeHandler={() => setOpen(false)}
|
||||||
title='System info'
|
title='System info'
|
||||||
>
|
>
|
||||||
<div>
|
<div onclick={clickHandler}>
|
||||||
<p>Platform: {window.Capacitor.platform}</p>
|
<div class={style.clickPrompt}>Click to copy to clipboard</div>
|
||||||
<p>User agent: {navigator.userAgent}</p>
|
<div ref={content}>
|
||||||
<p>App release: {import.meta.env.VITE_GIT_COMMIT_HASH}</p>
|
<p>Platform: {window.Capacitor.platform}</p>
|
||||||
<p>Account id: {settings()?.currentAccountId}</p>
|
<p>User agent: {navigator.userAgent}</p>
|
||||||
<p>Account name: {account()?.name}</p>
|
<p>App release: {import.meta.env.VITE_GIT_COMMIT_HASH}</p>
|
||||||
<p>Remote DB user: {account()?.remoteDbUser}</p>
|
<p>Account id: {settings()?.currentAccountId}</p>
|
||||||
<p>Remote DB server: {account()?.remoteDbServer}</p>
|
<p>Account name: {account()?.name}</p>
|
||||||
</div>
|
<p>Remote DB user: {account()?.remoteDbUser}</p>
|
||||||
<Show when={error().length > 0}>
|
<p>Remote DB server: {account()?.remoteDbServer}</p>
|
||||||
<div>
|
|
||||||
<p>Errors:</p>
|
|
||||||
<ul>
|
|
||||||
<For each={error()}>{(item) => <li>{item.message}</li>}</For>
|
|
||||||
</ul>
|
|
||||||
</div>
|
</div>
|
||||||
</Show>
|
<Show when={error().length > 0}>
|
||||||
|
<div>
|
||||||
|
<p>Errors:</p>
|
||||||
|
<ul>
|
||||||
|
<For each={error()}>{(item) => <li>{item.message}</li>}</For>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</Show>
|
||||||
|
</div>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
</Show>
|
</Show>
|
||||||
</>
|
</>
|
||||||
|
|
Loading…
Reference in New Issue