@adriansteffan/reactive 0.0.21 → 0.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,11 +2,10 @@ import { useCallback, useEffect, useRef, useState } from 'react';
2
2
  import { useMutation } from '@tanstack/react-query';
3
3
  import { v4 as uuidv4 } from 'uuid';
4
4
  import { post } from '../utils/request';
5
- import { FileUpload, getParam, StudyEvent } from '../utils/common';
5
+ import { BaseComponentProps, FileUpload, getParam, getPlatform, Platform, Store, TrialData } from '../utils/common';
6
6
  import { BlobWriter, TextReader, ZipWriter } from '@zip.js/zip.js';
7
7
 
8
8
  import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
9
- import { Capacitor } from '@capacitor/core';
10
9
 
11
10
  interface UploadPayload {
12
11
  sessionId: string;
@@ -120,25 +119,13 @@ const createCapacitorFileBackend = (parentFolder?: string): FileBackend => {
120
119
  };
121
120
  };
122
121
 
123
- export type Platform = 'electron' | 'capacitor' | 'web';
124
-
125
- export const getPlatform = (): Platform => {
126
- if ((window as any).electronAPI) {
127
- return 'electron';
128
- } else if (Capacitor.isNativePlatform()) {
129
- return 'capacitor';
130
- } else {
131
- return 'web';
132
- }
133
- };
134
-
135
122
  const getFileBackend = (parentDir?: string): { backend: FileBackend | null, type: Platform } => {
136
123
  const platform = getPlatform();
137
124
 
138
125
  switch (platform) {
139
- case 'electron':
126
+ case 'desktop':
140
127
  return { backend: createElectronFileBackend(), type: platform };
141
- case 'capacitor':
128
+ case 'mobile':
142
129
  return { backend: createCapacitorFileBackend(parentDir), type: platform };
143
130
  case 'web':
144
131
  return { backend: null, type: platform };
@@ -168,16 +155,15 @@ const getUniqueDirectoryName = async (
168
155
  export default function Upload({
169
156
  data,
170
157
  next,
158
+ store,
171
159
  sessionID,
172
160
  generateFiles,
173
161
  uploadRaw = true,
174
162
  autoUpload = false,
175
163
  androidFolderName,
176
- }: {
177
- data: StudyEvent[];
178
- next: () => void;
164
+ }: BaseComponentProps & {
179
165
  sessionID?: string | null;
180
- generateFiles: (sessionID: string, data: StudyEvent[]) => FileUpload[];
166
+ generateFiles: (sessionID: string, data: TrialData[], store?: Store) => FileUpload[];
181
167
  uploadRaw: boolean;
182
168
  autoUpload: boolean;
183
169
  androidFolderName?: string;
@@ -199,7 +185,7 @@ export default function Upload({
199
185
  onSuccess: (res: UploadResponse) => {
200
186
  if (res.status === 200) {
201
187
  setUploadState('success');
202
- next();
188
+ next({});
203
189
  } else {
204
190
  setUploadState('error');
205
191
  }
@@ -239,7 +225,7 @@ export default function Upload({
239
225
 
240
226
  const sessionIDUpload = sessionID ?? uuidv4();
241
227
 
242
- const files: FileUpload[] = generateFiles ? generateFiles(sessionIDUpload, data) : [];
228
+ const files: FileUpload[] = generateFiles ? generateFiles(sessionIDUpload, data, store) : [];
243
229
  if (uploadRaw) {
244
230
  files.push({
245
231
  filename: `${sessionIDUpload}.raw.json`,
@@ -259,7 +245,7 @@ export default function Upload({
259
245
  }
260
246
 
261
247
  if (!shouldUpload) {
262
- next();
248
+ next({});
263
249
  return;
264
250
  }
265
251
 
@@ -283,7 +269,7 @@ export default function Upload({
283
269
  }
284
270
 
285
271
  setUploadState('success');
286
- next();
272
+ next({});
287
273
  } catch (error) {
288
274
  console.error(`Error saving files with ${type}:`, error);
289
275
  setUploadState('error');
package/src/mod.tsx CHANGED
@@ -1,5 +1,6 @@
1
1
  import './index.css';
2
2
  import Text from './components/text';
3
+ import PlainInput from './components/plaininput';
3
4
  import ProlificEnding from './components/prolificending';
4
5
  import MicCheck from './components/microphonecheck';
5
6
  import Quest from './components/quest';
@@ -10,7 +11,7 @@ import ExperimentProvider from './components/experimentprovider';
10
11
  import Experiment from './components/experiment';
11
12
  import { BaseComponentProps, ExperimentConfig } from './utils/common';
12
13
 
13
- export { Text, ProlificEnding, MicCheck, Quest, Upload, EnterFullscreen, ExitFullscreen, Experiment, ExperimentProvider};
14
+ export { Text, ProlificEnding, MicCheck, Quest, Upload, EnterFullscreen, ExitFullscreen, Experiment, ExperimentProvider, PlainInput};
14
15
  export type { BaseComponentProps, ExperimentConfig };
15
16
  export * from './utils/common';
16
17
 
@@ -1,3 +1,5 @@
1
+ import { Capacitor } from "@capacitor/core";
2
+
1
3
  export function now() {
2
4
  return Math.round(performance.now());
3
5
  }
@@ -11,13 +13,14 @@ export function shuffle(array: any[]) {
11
13
  return array;
12
14
  }
13
15
 
14
- export function isDesktop(){
15
- return (window as any).electronAPI !== undefined
16
+ export function isDesktop() {
17
+ return (window as any).electronAPI !== undefined;
16
18
  }
17
19
 
18
20
  // Generic type for all data structures
19
- export interface StudyEvent {
21
+ export interface TrialData {
20
22
  index: number;
23
+ trialNumber: number,
21
24
  type: string;
22
25
  name: string;
23
26
  data: any;
@@ -36,10 +39,13 @@ export interface ExperimentConfig {
36
39
  showProgressBar: boolean;
37
40
  }
38
41
 
42
+ export interface Store { [key: string]: any }
43
+
39
44
  export interface BaseComponentProps {
40
45
  next: (data: object) => void;
41
- data?: object;
42
- metaData?: object;
46
+ data: TrialData[];
47
+ store?: Store;
48
+ updateStore: (mergeIn: Store) => void;
43
49
  }
44
50
 
45
51
  type ParamType = 'string' | 'number' | 'boolean' | 'array' | 'json';
@@ -115,3 +121,17 @@ export function getParam<T extends ParamType>(
115
121
  if (value === undefined || value === null) return defaultValue;
116
122
  return convertValue(value);
117
123
  }
124
+
125
+
126
+
127
+ export type Platform = 'desktop' | 'mobile' | 'web';
128
+
129
+ export const getPlatform = (): Platform => {
130
+ if ((window as any).electronAPI) {
131
+ return 'desktop';
132
+ } else if (Capacitor.isNativePlatform()) {
133
+ return 'mobile';
134
+ } else {
135
+ return 'web';
136
+ }
137
+ };
@@ -178,6 +178,8 @@ For ease of use, it makes sense to run the web version for most of the developme
178
178
 
179
179
  To build an iOS app containing your experiment, you will need a machine running MacOS and an installation of [XCode](https://apps.apple.com/us/app/xcode/id497799835). Furthermore, you will need to install [CocoaPods](https://cocoapods.org/), which is most easily installed with [Homebrew](https://brew.sh/).
180
180
 
181
+ Temporary uglyness: Due to a bug in the dependency in for the capacitor fullscreening plugin, we need to manually add a file if we want to build for iOS, described (in the related Github issue)[https://github.com/hugotomazi/navigation-bar/issues/31#issuecomment-2687412929]. Here's to hope that that will be fixed in the near future.
182
+
181
183
  To set up the iOS project, run
182
184
 
183
185
  ```