@@ -3,6 +3,7 @@ import { useContext, useEffect } from 'preact/hooks';
3
3
import { ActivityApiContext , ActivityServiceContext } from './ActivityProvider' ;
4
4
import { ACTION_BURN } from './constants.js' ;
5
5
import { batch , signal , useSignal } from '@preact/signals' ;
6
+ import { useEnv } from '../../../../shared/components/EnvironmentProvider.js' ;
6
7
7
8
export const ActivityBurningSignalContext = createContext ( {
8
9
/** @type {import("@preact/signals").Signal<string[]> } */
@@ -20,6 +21,7 @@ export function BurnProvider({ children }) {
20
21
const exiting = useSignal ( /** @type {string[] } */ ( [ ] ) ) ;
21
22
const { didClick : originalDidClick } = useContext ( ActivityApiContext ) ;
22
23
const service = useContext ( ActivityServiceContext ) ;
24
+ const { isReducedMotion } = useEnv ( ) ;
23
25
24
26
async function didClick ( e ) {
25
27
const button = /** @type {HTMLButtonElement|null } */ ( e . target ?. closest ( `button[value][data-action="${ ACTION_BURN } "]` ) ) ;
@@ -41,8 +43,8 @@ export function BurnProvider({ children }) {
41
43
// mark this item as burning - this will prevent further events until we're done
42
44
burning . value = burning . value . concat ( value ) ;
43
45
44
- // wait for either the animation to be finished, or the document visibility changed
45
- const feSignals = any ( animationExit ( ) , didChangeDocumentVisibility ( ) ) ;
46
+ // wait for a signal from the FE that we can continue
47
+ const feSignals = any ( reducedMotion ( isReducedMotion ) , animationExit ( ) , didChangeDocumentVisibility ( ) ) ;
46
48
47
49
// the signal from native that burning was complete
48
50
const nativeSignal = didCompleteNatively ( service ) ;
@@ -102,11 +104,21 @@ function toPromise(fn) {
102
104
} ) ;
103
105
}
104
106
107
+ function reducedMotion ( isReducedMotion ) {
108
+ console . log ( '+[reducedMotion] setup' ) ;
109
+ return ( subject ) => {
110
+ if ( isReducedMotion ) {
111
+ console . log ( ' .next() [reducedMotion] setup' ) ;
112
+ subject . next ( ) ;
113
+ }
114
+ } ;
115
+ }
116
+
105
117
function animationExit ( ) {
106
118
return ( subject ) => {
107
119
console . log ( '+[didExit] setup' ) ;
108
120
const handler = ( ) => {
109
- console . log ( ' -> [didExit] resolve .next() ' ) ;
121
+ console . log ( ' .next() -> [didExit]' ) ;
110
122
subject . next ( ) ;
111
123
} ;
112
124
window . addEventListener ( 'done-exiting' , handler , { once : true } ) ;
@@ -121,7 +133,7 @@ function timer(ms) {
121
133
return ( subject ) => {
122
134
console . log ( '+[timer] setup' ) ;
123
135
const int = setTimeout ( ( ) => {
124
- console . log ( ' -> [timer] .next() ' ) ;
136
+ console . log ( ' .next() -> [timer]' ) ;
125
137
return subject . next ( ) ;
126
138
} , ms ) ;
127
139
return ( ) => {
@@ -135,7 +147,7 @@ function didCompleteNatively(service) {
135
147
return ( subject ) => {
136
148
console . log ( '+[didCompleteNatively] setup' ) ;
137
149
const unsub = service ?. onBurnComplete ( ( ) => {
138
- console . log ( ' -> [didCompleteNatively] .next() ' ) ;
150
+ console . log ( ' .next() -> [didCompleteNatively] ' ) ;
139
151
subject . next ( ) ;
140
152
} ) ;
141
153
return ( ) => {
@@ -147,72 +159,72 @@ function didCompleteNatively(service) {
147
159
148
160
function didChangeDocumentVisibility ( ) {
149
161
return ( subject ) => {
150
- console . log ( '+[didChangeVisibilty ] setup' ) ;
162
+ console . log ( '+[didChangeVisibility ] setup' ) ;
151
163
const handler = ( ) => {
152
- console . log ( ' -> [didChangeVisibilty ] resolve .next() ' ) ;
164
+ console . log ( ' .next() -> [didChangeVisibility ] resolve ' ) ;
153
165
return subject . next ( document . visibilityState ) ;
154
166
} ;
155
167
document . addEventListener ( 'visibilitychange' , handler , { once : true } ) ;
156
168
return ( ) => {
157
- console . log ( '-[didChangeVisibilty ] teardown' ) ;
169
+ console . log ( '-[didChangeVisibility ] teardown' ) ;
158
170
window . removeEventListener ( 'visibilitychange' , handler ) ;
159
171
} ;
160
172
} ;
161
173
}
162
174
163
175
function any ( ...fns ) {
164
176
return ( subject ) => {
165
- const work = fns . map ( ( factory ) => {
177
+ const jobs = fns . map ( ( factory ) => {
166
178
const subject = {
167
179
/** @type {any } */
168
180
next : undefined ,
169
181
} ;
170
182
const promise = new Promise ( ( resolve ) => ( subject . next = resolve ) ) ;
171
183
const cleanup = factory ( subject ) ;
172
184
return {
173
- promise : promise ,
174
- cleanup : cleanup ,
185
+ promise,
186
+ cleanup,
175
187
} ;
176
188
} ) ;
177
189
178
- Promise . any ( work . map ( ( x ) => x . promise ) )
190
+ Promise . any ( jobs . map ( ( x ) => x . promise ) )
179
191
// eslint-disable-next-line promise/prefer-await-to-then
180
192
. then ( ( d ) => subject . next ( d ) )
181
193
// eslint-disable-next-line promise/prefer-await-to-then
182
194
. catch ( console . error ) ;
183
195
184
196
return ( ) => {
185
- for ( const workItem of work ) {
186
- workItem . cleanup ( ) ;
197
+ for ( const job of jobs ) {
198
+ job . cleanup ?. ( ) ;
187
199
}
188
200
} ;
189
201
} ;
190
202
}
191
203
192
204
function all ( ...fns ) {
193
205
return ( subject ) => {
194
- const work = fns . map ( ( factory ) => {
206
+ const jobs = fns . map ( ( factory ) => {
195
207
const subject = {
196
208
/** @type {any } */
197
209
next : undefined ,
198
210
} ;
199
211
const promise = new Promise ( ( resolve ) => ( subject . next = resolve ) ) ;
200
212
const cleanup = factory ( subject ) ;
201
213
return {
202
- promise : promise ,
203
- cleanup : cleanup ,
214
+ promise,
215
+ cleanup,
204
216
} ;
205
217
} ) ;
206
218
207
- Promise . all ( work . map ( ( x ) => x . promise ) )
219
+ Promise . all ( jobs . map ( ( x ) => x . promise ) )
208
220
// eslint-disable-next-line promise/prefer-await-to-then
209
221
. then ( ( d ) => subject . next ( d ) )
210
222
// eslint-disable-next-line promise/prefer-await-to-then
211
223
. catch ( console . error ) ;
212
224
213
225
return ( ) => {
214
- for ( const workItem of work ) {
215
- workItem . cleanup ( ) ;
226
+ for ( const job of jobs ) {
227
+ job . cleanup ?. ( ) ;
216
228
}
217
229
} ;
218
230
} ;
0 commit comments