Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
09d0c7ab
Commit
09d0c7ab
authored
Dec 09, 2022
by
Lyza Danger Gardner
Committed by
Lyza Gardner
Dec 13, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert `NotebookModal` to TS
parent
7838c8f2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
26 deletions
+21
-26
NotebookModal.tsx
src/annotator/components/NotebookModal.tsx
+21
-26
No files found.
src/annotator/components/NotebookModal.
js
→
src/annotator/components/NotebookModal.
tsx
View file @
09d0c7ab
...
...
@@ -4,28 +4,26 @@ import classnames from 'classnames';
import
{
addConfigFragment
}
from
'../../shared/config-fragment'
;
import
{
createAppConfig
}
from
'../config/app'
;
import
type
{
EventBus
,
Emitter
}
from
'../util/emitter'
;
/**
* Configuration used to launch the notebook application.
*
* This includes the URL for the iframe and configuration to pass to the
* application on launch.
*
* @typedef {{ notebookAppUrl: string } & Record<string, unknown>} NotebookConfig
*/
/**
* @typedef NotebookIframeProps
* @prop {NotebookConfig} config
* @prop {string} groupId
*/
export
type
NotebookConfig
=
{
notebookAppUrl
:
string
;
}
&
Record
<
string
,
unknown
>
;
type
NotebookIframeProps
=
{
config
:
NotebookConfig
;
groupId
:
string
;
};
/**
* Create the iframe that will load the notebook application.
*
* @param {NotebookIframeProps} props
*/
function
NotebookIframe
({
config
,
groupId
})
{
function
NotebookIframe
({
config
,
groupId
}
:
NotebookIframeProps
)
{
const
notebookAppSrc
=
addConfigFragment
(
config
.
notebookAppUrl
,
{
...
createAppConfig
(
config
.
notebookAppUrl
,
config
),
...
...
@@ -47,30 +45,27 @@ function NotebookIframe({ config, groupId }) {
/>
);
}
/** @typedef {import('../util/emitter').Emitter} Emitter */
/**
* @typedef NotebookModalProps
* @prop {import('../util/emitter').EventBus} eventBus
* @prop {NotebookConfig} config
*/
export
type
NotebookModalProps
=
{
eventBus
:
EventBus
;
config
:
NotebookConfig
;
};
/**
* Create a modal component that hosts (1) the notebook iframe and (2) a button to close the modal.
*
* @param {NotebookModalProps} props
*/
export
default
function
NotebookModal
({
eventBus
,
config
})
{
export
default
function
NotebookModal
({
eventBus
,
config
,
}:
NotebookModalProps
)
{
// Temporary solution: while there is no mechanism to sync new annotations in
// the notebook, we force re-rendering of the iframe on every 'openNotebook'
// event, so that the new annotations are displayed.
// https://github.com/hypothesis/client/issues/3182
const
[
iframeKey
,
setIframeKey
]
=
useState
(
0
);
const
[
isHidden
,
setIsHidden
]
=
useState
(
true
);
const
[
groupId
,
setGroupId
]
=
useState
(
/** @type {string|null} */
(
null
)
);
const
[
groupId
,
setGroupId
]
=
useState
<
string
|
null
>
(
null
);
const
originalDocumentOverflowStyle
=
useRef
(
''
);
const
emitterRef
=
useRef
(
/** @type {Emitter|null} */
(
null
)
);
const
emitterRef
=
useRef
<
Emitter
|
null
>
(
null
);
// Stores the original overflow CSS property of document.body and reset it
// when the component is destroyed
...
...
@@ -94,7 +89,7 @@ export default function NotebookModal({ eventBus, config }) {
useEffect
(()
=>
{
const
emitter
=
eventBus
.
createEmitter
();
emitter
.
subscribe
(
'openNotebook'
,
(
/** @type {string} */
groupId
)
=>
{
emitter
.
subscribe
(
'openNotebook'
,
(
groupId
:
string
)
=>
{
setIsHidden
(
false
);
setIframeKey
(
iframeKey
=>
iframeKey
+
1
);
setGroupId
(
groupId
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment