diff options
| author | omagdy7 <omar.professional8777@gmail.com> | 2023-11-03 17:57:35 +0200 |
|---|---|---|
| committer | omagdy7 <omar.professional8777@gmail.com> | 2023-11-03 17:57:35 +0200 |
| commit | dd4299a4de8a31802a4551d631c67836484d9699 (patch) | |
| tree | bae16e70a7000533316b01ae30e8982d20255d51 /src/utils.ts | |
| parent | 189d9e8173049aac2cb9f0aea923e339bfc76de7 (diff) | |
| download | ollama-logseq-dd4299a4de8a31802a4551d631c67836484d9699.tar.xz ollama-logseq-dd4299a4de8a31802a4551d631c67836484d9699.zip | |
Moved to react instead of vanilla js and added the basic skeleton of the plgin
Diffstat (limited to 'src/utils.ts')
| -rw-r--r-- | src/utils.ts | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..171bf71 --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,24 @@ +import { LSPluginUserEvents } from "@logseq/libs/dist/LSPlugin.user"; +import React from "react"; + +let _visible = logseq.isMainUIVisible; + +function subscribeLogseqEvent<T extends LSPluginUserEvents>( + eventName: T, + handler: (...args: any) => void +) { + logseq.on(eventName, handler); + return () => { + logseq.off(eventName, handler); + }; +} + +const subscribeToUIVisible = (onChange: () => void) => + subscribeLogseqEvent("ui:visible:changed", ({ visible }) => { + _visible = visible; + onChange(); + }); + +export const useAppVisible = () => { + return React.useSyncExternalStore(subscribeToUIVisible, () => _visible); +}; |
