-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ivan Kudinov
committed
Dec 24, 2024
1 parent
62a150d
commit 67b6763
Showing
9 changed files
with
121 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { observer } from 'mobx-react' | ||
import React, { FC, useEffect } from 'react' | ||
import { useStore } from '../../hooks/useStore' | ||
import FeatureHeader from '../../components/FeatureHeader' | ||
import FeaturePage from '../../components/FeaturePage' | ||
import Input from '../../components/Input' | ||
import Button from '../../components/Button' | ||
|
||
const AppVisibilityPage: FC = () => { | ||
const { appVisibilityStore } = useStore() | ||
|
||
useEffect(() => { | ||
appVisibilityStore.subscribeAppVisibilityChange() | ||
|
||
return () => { | ||
appVisibilityStore.unsubscribeAppVisibilityChange() | ||
} | ||
}, []) | ||
|
||
const handleSubmit = () => appVisibilityStore.getAppVisibility() | ||
|
||
return ( | ||
<FeaturePage> | ||
<FeatureHeader name="Видимость окна SmartApp" /> | ||
<span>Видимость</span> | ||
<Input | ||
value={`${appVisibilityStore.visibile === null ? '' : appVisibilityStore.visibile}`} | ||
id="layout-type-text" | ||
disabled | ||
/> | ||
<Button onClick={handleSubmit} id="submit" title="Получить" /> | ||
<br /> | ||
<br /> | ||
<br /> | ||
<i>Сверните и разверните окно SmartApp чтобы увидеть сообщение о смене видимости.</i> | ||
</FeaturePage> | ||
) | ||
} | ||
|
||
export default observer(AppVisibilityPage) |
58 changes: 58 additions & 0 deletions
58
frontend/app/modules/app-visibility/app-visibility.store.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import * as SDK from '@expressms/smartapp-sdk' | ||
import { makeObservable, observable, runInAction } from 'mobx' | ||
import { RootStore } from '../../store/rootStore' | ||
import { GetAppVisibilityResponse, STATUS, SubscriptionEventType } from '@expressms/smartapp-sdk/build/main/types' | ||
import { AppVisibilitySubscriptionEvent } from './app-visibility.types' | ||
|
||
export class AppVisibilityStore { | ||
rootStore: RootStore | ||
@observable visibile: boolean | null | ||
callback: () => void | ||
|
||
constructor(rootStore: RootStore) { | ||
makeObservable(this) | ||
|
||
this.rootStore = rootStore | ||
this.visibile = null | ||
this.callback = this.visibilityChangeCallback.bind(this) | ||
} | ||
|
||
private visibilityChangeCallback(event: AppVisibilitySubscriptionEvent) { | ||
alert(event.payload.visible ? 'SmartApp видим' : 'SmartApp скрыт') | ||
} | ||
|
||
async getAppVisibility() { | ||
try { | ||
const response: GetAppVisibilityResponse = await SDK.getAppVisibility() | ||
|
||
if (response.payload.status === STATUS.ERROR) { | ||
this.rootStore.toastStore.showToast(`Error getting app visibility ${response.payload.errorCode}`) | ||
return | ||
} | ||
|
||
runInAction(() => { | ||
this.visibile = response.payload.visible | ||
}) | ||
} catch (e) { | ||
this.rootStore.toastStore.showToast(`Error getting app visibility ${e?.message || e}`) | ||
} | ||
} | ||
|
||
async subscribeAppVisibilityChange() { | ||
await SDK.subscribeClientEvents({ | ||
eventType: SubscriptionEventType.APP_VISIBILITY, | ||
callback: this.callback, | ||
}) | ||
|
||
console.log('Subscribed app_visibility') | ||
} | ||
|
||
async unsubscribeAppVisibilityChange() { | ||
await SDK.unsubscribeClientEvents({ | ||
eventType: SubscriptionEventType.APP_VISIBILITY, | ||
callback: this.callback, | ||
}) | ||
|
||
console.log('Unsubscribed app_visibility') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { EmitterEventPayload } from '@expressms/smartapp-bridge/build/main/types/eventEmitter.d' | ||
|
||
export interface AppVisibilitySubscriptionEvent extends Omit<EmitterEventPayload, 'payload'> { | ||
payload: { | ||
visible: boolean | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1160,10 +1160,10 @@ | |
lodash-es "^4.17.21" | ||
uuid "^8.3.2" | ||
|
||
"@expressms/[email protected].0": | ||
version "1.11.0-alpha.0" | ||
resolved "https://registry.yarnpkg.com/@expressms/smartapp-sdk/-/smartapp-sdk-1.11.0-alpha.0.tgz#3eb59eca09aaa9f2d4f73b0bce7cfa9ff07e4ec7" | ||
integrity sha512-dhdL5ysnRzUw8+d6/nBG7RFryfIvHD8dHA2FTAlYyi4bGr5Eh2mVCu7s75uHyIrTNGmViDig4QWzCz4DXJUCbg== | ||
"@expressms/[email protected].2": | ||
version "1.11.0-alpha.2" | ||
resolved "https://registry.yarnpkg.com/@expressms/smartapp-sdk/-/smartapp-sdk-1.11.0-alpha.2.tgz#7fee41260795b361d2a9af1fe6d4fba57f59f8c9" | ||
integrity sha512-uoW1OFbKrwmKs+MhGcndf0DaEKBGvkUCtphpteXkA2Pd/cnHJMBdt2gcW0WlGLlxW8YosE6u2/uUgSNvF7nqgQ== | ||
dependencies: | ||
"@expressms/smartapp-bridge" "1.4.0-alpha.1" | ||
|
||
|