Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dialog service for retrieving info from users. Select Project Dialog. useDialogCallback hook #553

Merged
merged 15 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions extensions/src/hello-someone/hello-someone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@ export async function activate(context: ExecutionActivationContext): Promise<voi
await peopleWebViewProviderPromise,
await helloSomeoneCommandPromise,
await echoSomeoneRendererPromise,
papi.webViews.onDidAddWebView((addWebViewEvent) => {
if (addWebViewEvent.webView.webViewType === peopleWebViewType)
logger.info(
`We noticed a ${peopleWebViewType} webView was added with id ${addWebViewEvent.webView.id}`,
);
}),
);

logger.info('Hello Someone is finished activating!');
Expand Down
4 changes: 4 additions & 0 deletions extensions/src/hello-someone/hello-someone.web-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@
newWebViewButton.addEventListener('click', async () => {
const webViewId = await papi.webViews.getWebView('helloSomeone.peopleViewer', {
type: 'float',
floatSize: {
width: 450,
height: 350,
},
});
print(`New People webview id: ${webViewId}`);
});
Expand Down
155 changes: 155 additions & 0 deletions extensions/src/hello-world/assets/offline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions extensions/src/hello-world/hello-world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const reactWebViewProvider: IWebViewProviderWithType = {
);
return {
...savedWebView,
iconUrl: 'papi-extension://hello-world/assets/offline.svg',
title: 'Hello World React',
content: helloWorldReactWebView,
styles: helloWorldReactWebViewStyles,
Expand Down
19 changes: 17 additions & 2 deletions extensions/src/hello-world/web-views/hello-world.web-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import {
import type { QuickVerseDataTypes } from 'quick-verse';
import type { PeopleDataProvider, PeopleDataTypes } from 'hello-someone';
import type { UsfmProviderDataTypes } from 'usfm-data-provider';
import { Key, useCallback, useContext, useMemo, useState } from 'react';
import { Key, useCallback, useContext, useMemo, useRef, useState } from 'react';
import type { HelloWorldEvent } from 'hello-world';
import type { DialogTypes } from 'renderer/components/dialogs/dialog.data';
import Clock from './components/clock.component';

type Row = {
Expand All @@ -27,7 +28,7 @@ type Row = {
const {
react: {
context: { TestContext },
hooks: { useData, useDataProvider, usePromise, useEvent, useSetting },
hooks: { useData, useDataProvider, usePromise, useEvent, useSetting, useDialogCallback },
},
logger,
} = papi;
Expand Down Expand Up @@ -85,6 +86,16 @@ globalThis.webViewComponent = function HelloWorld() {
'retrieving',
);

const [project, selectProject] = useDialogCallback(
'platform.selectProject',
useRef({
prompt: 'Please select a project for Hello World WebView:',
iconUrl: 'papi-extension://hello-world/assets/offline.svg',
title: 'Select Hello World Project',
}).current,
'None' as DialogTypes['platform.selectProject']['responseType'],
);

const [latestVerseText] = useData.Verse<QuickVerseDataTypes, 'Verse'>(
'quickVerse.quickVerse',
'latest',
Expand Down Expand Up @@ -152,6 +163,10 @@ globalThis.webViewComponent = function HelloWorld() {
</div>
<div>{personGreeting}</div>
<div>{personAge}</div>
<div>Selected Project: {project}</div>
<div>
<Button onClick={selectProject}>Select Project</Button>
</div>
<h3>John 1:1</h3>
<div>{john11}</div>
<h3>Psalm 1</h3>
Expand Down
Loading