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
d83b3785
Commit
d83b3785
authored
Mar 20, 2024
by
Alejandro Celaya
Committed by
Alejandro Celaya
Mar 20, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Display pending updates notification when there have been deletions
parent
5ef08e4b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
8 deletions
+33
-8
PendingUpdatesNotification.tsx
src/sidebar/components/PendingUpdatesNotification.tsx
+5
-5
PendingUpdatesNotification-test.js
...idebar/components/test/PendingUpdatesNotification-test.js
+3
-3
real-time-updates.ts
src/sidebar/store/modules/real-time-updates.ts
+9
-0
real-time-updates-test.js
src/sidebar/store/modules/test/real-time-updates-test.js
+16
-0
No files found.
src/sidebar/components/PendingUpdatesNotification.tsx
View file @
d83b3785
...
@@ -27,7 +27,7 @@ function PendingUpdatesNotification({
...
@@ -27,7 +27,7 @@ function PendingUpdatesNotification({
}:
PendingUpdatesNotificationProps
)
{
}:
PendingUpdatesNotificationProps
)
{
const
store
=
useSidebarStore
();
const
store
=
useSidebarStore
();
const
pendingUpdateCount
=
store
.
pendingUpdateCount
();
const
pendingUpdateCount
=
store
.
pendingUpdateCount
();
const
hasPending
Updates
=
store
.
hasPendingUpdate
s
();
const
hasPending
Changes
=
store
.
hasPendingUpdatesOrDeletion
s
();
const
applyPendingUpdates
=
useCallback
(
const
applyPendingUpdates
=
useCallback
(
()
=>
streamer
.
applyPendingUpdates
(),
()
=>
streamer
.
applyPendingUpdates
(),
[
streamer
],
[
streamer
],
...
@@ -35,10 +35,10 @@ function PendingUpdatesNotification({
...
@@ -35,10 +35,10 @@ function PendingUpdatesNotification({
const
[
collapsed
,
setCollapsed
]
=
useState
(
false
);
const
[
collapsed
,
setCollapsed
]
=
useState
(
false
);
const
timeout
=
useRef
<
number
|
null
>
(
null
);
const
timeout
=
useRef
<
number
|
null
>
(
null
);
useShortcut
(
'l'
,
()
=>
hasPending
Updat
es
&&
applyPendingUpdates
());
useShortcut
(
'l'
,
()
=>
hasPending
Chang
es
&&
applyPendingUpdates
());
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
hasPending
Updat
es
)
{
if
(
hasPending
Chang
es
)
{
timeout
.
current
=
setTimeout_
(()
=>
{
timeout
.
current
=
setTimeout_
(()
=>
{
setCollapsed
(
true
);
setCollapsed
(
true
);
timeout
.
current
=
null
;
timeout
.
current
=
null
;
...
@@ -48,9 +48,9 @@ function PendingUpdatesNotification({
...
@@ -48,9 +48,9 @@ function PendingUpdatesNotification({
}
}
return
()
=>
timeout
.
current
&&
clearTimeout_
(
timeout
.
current
);
return
()
=>
timeout
.
current
&&
clearTimeout_
(
timeout
.
current
);
},
[
clearTimeout_
,
hasPending
Updat
es
,
setTimeout_
]);
},
[
clearTimeout_
,
hasPending
Chang
es
,
setTimeout_
]);
if
(
!
hasPending
Updat
es
)
{
if
(
!
hasPending
Chang
es
)
{
return
null
;
return
null
;
}
}
...
...
src/sidebar/components/test/PendingUpdatesNotification-test.js
View file @
d83b3785
...
@@ -20,7 +20,7 @@ describe('PendingUpdatesNotification', () => {
...
@@ -20,7 +20,7 @@ describe('PendingUpdatesNotification', () => {
};
};
fakeStore
=
{
fakeStore
=
{
pendingUpdateCount
:
sinon
.
stub
().
returns
(
3
),
pendingUpdateCount
:
sinon
.
stub
().
returns
(
3
),
hasPendingUpdates
:
sinon
.
stub
().
returns
(
true
),
hasPendingUpdates
OrDeletions
:
sinon
.
stub
().
returns
(
true
),
};
};
$imports
.
$mock
({
$imports
.
$mock
({
...
@@ -68,7 +68,7 @@ describe('PendingUpdatesNotification', () => {
...
@@ -68,7 +68,7 @@ describe('PendingUpdatesNotification', () => {
}
}
it
(
'does not render anything while there are no pending updates'
,
()
=>
{
it
(
'does not render anything while there are no pending updates'
,
()
=>
{
fakeStore
.
hasPendingUpdates
.
returns
(
false
);
fakeStore
.
hasPendingUpdates
OrDeletions
.
returns
(
false
);
const
wrapper
=
createComponent
();
const
wrapper
=
createComponent
();
assert
.
isEmpty
(
wrapper
);
assert
.
isEmpty
(
wrapper
);
...
@@ -112,7 +112,7 @@ describe('PendingUpdatesNotification', () => {
...
@@ -112,7 +112,7 @@ describe('PendingUpdatesNotification', () => {
[
true
,
false
].
forEach
(
hasPendingUpdates
=>
{
[
true
,
false
].
forEach
(
hasPendingUpdates
=>
{
it
(
'applies updates when "l" is pressed'
,
()
=>
{
it
(
'applies updates when "l" is pressed'
,
()
=>
{
fakeStore
.
hasPendingUpdates
.
returns
(
hasPendingUpdates
);
fakeStore
.
hasPendingUpdates
OrDeletions
.
returns
(
hasPendingUpdates
);
let
wrapper
;
let
wrapper
;
const
container
=
document
.
createElement
(
'div'
);
const
container
=
document
.
createElement
(
'div'
);
document
.
body
.
append
(
container
);
document
.
body
.
append
(
container
);
...
...
src/sidebar/store/modules/real-time-updates.ts
View file @
d83b3785
...
@@ -213,6 +213,14 @@ function hasPendingUpdates(state: State): boolean {
...
@@ -213,6 +213,14 @@ function hasPendingUpdates(state: State): boolean {
return
Object
.
keys
(
state
.
pendingUpdates
).
length
>
0
;
return
Object
.
keys
(
state
.
pendingUpdates
).
length
>
0
;
}
}
/**
* Return true if at least one annotation has been created or deleted on the
* server, but it has not yet been applied.
*/
function
hasPendingUpdatesOrDeletions
(
state
:
State
):
boolean
{
return
pendingUpdateCount
(
state
)
>
0
;
}
export
const
realTimeUpdatesModule
=
createStoreModule
(
initialState
,
{
export
const
realTimeUpdatesModule
=
createStoreModule
(
initialState
,
{
namespace
:
'realTimeUpdates'
,
namespace
:
'realTimeUpdates'
,
reducers
,
reducers
,
...
@@ -223,6 +231,7 @@ export const realTimeUpdatesModule = createStoreModule(initialState, {
...
@@ -223,6 +231,7 @@ export const realTimeUpdatesModule = createStoreModule(initialState, {
selectors
:
{
selectors
:
{
hasPendingDeletion
,
hasPendingDeletion
,
hasPendingUpdates
,
hasPendingUpdates
,
hasPendingUpdatesOrDeletions
,
pendingDeletions
,
pendingDeletions
,
pendingUpdates
,
pendingUpdates
,
pendingUpdateCount
,
pendingUpdateCount
,
...
...
src/sidebar/store/modules/test/real-time-updates-test.js
View file @
d83b3785
...
@@ -193,4 +193,20 @@ describe('sidebar/store/modules/real-time-updates', () => {
...
@@ -193,4 +193,20 @@ describe('sidebar/store/modules/real-time-updates', () => {
assert
.
equal
(
store
.
hasPendingUpdates
(),
true
);
assert
.
equal
(
store
.
hasPendingUpdates
(),
true
);
});
});
});
});
describe
(
'hasPendingUpdatesOrDeletions'
,
()
=>
{
it
(
'returns false if there are no pending updates nor deletions'
,
()
=>
{
assert
.
isFalse
(
store
.
hasPendingUpdatesOrDeletions
());
});
it
(
'returns true if there are pending updates'
,
()
=>
{
addPendingUpdates
(
store
);
assert
.
isTrue
(
store
.
hasPendingUpdatesOrDeletions
());
});
it
(
'returns true if there are pending deletions'
,
()
=>
{
addPendingDeletions
(
store
);
assert
.
isTrue
(
store
.
hasPendingUpdatesOrDeletions
());
});
});
});
});
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