Use hello both in tab and dialog

This commit is contained in:
frostime 2023-05-20 16:01:39 +08:00
parent 5cf4d6efd1
commit de42dc1b55
2 changed files with 11 additions and 21 deletions

View file

@ -8,7 +8,6 @@
import { showMessage } from "siyuan";
export let name: string;
export let i18n: any;
export let opendCount: number;
let time;
let ver;
@ -17,14 +16,6 @@
time = new Date();
}, 1000);
let intv2 = setInterval(async () => {
ver = await version();
showMessage(
`[${opendCount}] Hello ${name} v${ver}`,
5000
);
}, 10000);
onMount(async () => {
time = new Date();
ver = await version();
@ -36,7 +27,6 @@
onDestroy(() => {
showMessage("Hello panel closed");
clearInterval(intv1);
clearInterval(intv2);
});
$: time_str = new Date(time).toLocaleTimeString();
@ -46,7 +36,7 @@
<div id="hello">
<div class="fn__flex">
<div class="fn__flex-1">
<h2>[{opendCount}] Hello {name} v{ver}</h2>
<h2>Hello {name} v{ver}</h2>
</div>
<div class="fn__flex-1 b3-label__text __text-right">
{time_str}

View file

@ -33,21 +33,22 @@ export default class SamplePlugin extends Plugin {
}
});
let div = document.createElement("div");
new HelloExample({
target: div,
props: {
name: this.i18n.name,
i18n: this.i18n.hello
}
});
this.customTab = this.addTab({
type: TAB_TYPE,
init() {
this.tab = new HelloExample({
target: this.element,
props: {
name: this.i18n.name,
opendCount: this.counter.hello,
i18n: this.i18n.hello
}
});
this.element.appendChild(div);
console.log(this.element);
},
destroy() {
console.log("destroy tab:", TAB_TYPE);
this.tab.$destroy(); //Call svelte component destroy
}
});
@ -192,7 +193,6 @@ export default class SamplePlugin extends Plugin {
target: dialog.element.querySelector("#helloPanel"),
props: {
name: this.i18n.name,
opendCount: this.counter.hello,
i18n: this.i18n.hello
}
});