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

Feature/experiments/go pro/multi select file upload #1205

Conversation

sultanmyrza
Copy link
Contributor

@sultanmyrza sultanmyrza commented Jan 28, 2022

┆Issue is synchronized with this Asana task by Unito
┆Created By: Tammy Yang

)
)
concatMap(async ([takePicture, recordVideo]) => {
// eslint-disable-next-line no-async-promise-executor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We follow eslint as much as possible whenever it is reasonable. Using async function as Promise executor is a common anti-pattern which sometimes causes some unexpected behavior so it is best avoided.
To use the getConnectedDevice() async function's result, you can use a combineLatest to combine it with the translteObject observable, see https://github.com/numbersprotocol/capture-lite/blob/master/src/app/features/home/details/details.page.ts#L254 for example

The goal here is to refactor this part so that // eslint-disable-next-line no-async-promise-executor won't be needed to pass lint

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f071852 should resolve

<ion-button
(click)="uploadToCapture()"
expand="block"
style="color: white; --box-shadow: 0; margin: 0 16px 0 16px"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good if these styles can be put in the .scss file and keep inline styling usage minimal

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hope this commit "move all html styles to" will resolve

Comment on lines 126 to 134
// // eslint-disable-next-line no-console
// console.log(fileToUpload);

// await new Promise(resolve => {
// setTimeout(() => {
// resolve(fileToUpload);
// // eslint-disable-next-line @typescript-eslint/no-magic-numbers
// }, 4000);
// });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These code should be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

03dd1d6 should resolve

Comment on lines 164 to 166
const { role } = await alert.onDidDismiss();
// eslint-disable-next-line no-console
console.log('onDidDismiss resolved with role', role);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If role does not do anything here, it should be removed to avoid confusion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a8e8dac should resolve

(click)="scanForBluetoothDevices()"
style="color: white; --box-shadow: 0; margin: 0 16px 0 16px"
>
{{ bluetoothIsScanning ? 'Scaning' : 'Scan for bluetooth devices' }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{{ bluetoothIsScanning ? 'Scaning' : 'Scan for bluetooth devices' }}
{{ bluetoothIsScanning ? 'Scanning' : 'Scan for bluetooth devices' }}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 70 to 78
try {
this.bluetoothIsScanning = true;
this.bluetoothScanResults =
await this.goProBluetoothService.scanForBluetoothDevices();
this.bluetoothIsScanning = false;
} catch (error) {
this.bluetoothScanResults = [];
this.bluetoothIsScanning = false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
try {
this.bluetoothIsScanning = true;
this.bluetoothScanResults =
await this.goProBluetoothService.scanForBluetoothDevices();
this.bluetoothIsScanning = false;
} catch (error) {
this.bluetoothScanResults = [];
this.bluetoothIsScanning = false;
}
try {
this.bluetoothIsScanning = true;
this.bluetoothScanResults =
await this.goProBluetoothService.scanForBluetoothDevices();
} catch (error) {
this.bluetoothScanResults = [];
} finally {
this.bluetoothIsScanning = false;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

73668e0 should resolve

private readonly enableGoProWiFiCommand = [0x03, 0x17, 0x01, 0x01];

constructor() {
BleClient.initialize();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because these services are provided in shared module which is loaded when the app/test starts running, I would suggest leave the service constructor empty, and do a late initialization when the Bluetooth-related functionalities are really needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commit ccb1320 should resolve

await this.checkBluetoothDeviceConnection();

// TODO: find better solution for comparing 2 arrays with numbers
if (JSON.stringify(command) === JSON.stringify(this.shutdownCommand)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (JSON.stringify(command) === JSON.stringify(this.shutdownCommand)) {
import { isEqual } from 'lodash-es';
...
if (isEqual(command, this.shutdownCommand)) {

We already uses lodash in other places so the best way to compare array or objects is by using lodash.isEqual

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private readonly httpClient: HttpClient
) {}

// eslint-disable-next-line class-methods-use-this
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all the lint rule class-methods-use-this issues, I would suggest define these functions in a standalone file and export them, instead of defining them as GoProMediaService's class methods. See src/app/utils/url.ts for example (it is also a good place to put url-handling functions)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2f0ce31 should resolve

import { GoProBluetoothService } from './go-pro-bluetooth.service';
const Wifi: WifiPlugin = Plugins.Wifi as WifiPlugin;

const { Storage } = Plugins;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The App already has a PreferenceManager class which wraps the Storage plugin and makes values as subscriptables. Please use PreferenceManager directly instead of access Storage plugin directly here so that the App has a single uniform way to handle key-value storages.
You can check WebCryptoApiSignatureProvider for usage example for the PreferenceManager.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1688367 using PreferenceManager for WiFi

4e5d9a3 using PreferenceManager for BLE

However running locally npm run test.ci giving this error:

after commit 1688367

test logs
GoProWifiService should be created FAILED
	NullInjectorError: R3InjectorError(DynamicTestModule)[GoProWifiService -> PreferenceManager -> InjectionToken STORAGE_PLUGIN -> InjectionToken STORAGE_PLUGIN]: 
	  NullInjectorError: No provider for InjectionToken STORAGE_PLUGIN!
	error properties: Object({ ngTempTokenPath: null, ngTokenPath: [ 'GoProWifiService', 'PreferenceManager', 'InjectionToken STORAGE_PLUGIN', 'InjectionToken STORAGE_PLUGIN' ] })
	NullInjectorError: R3InjectorError(DynamicTestModule)[GoProWifiService -> PreferenceManager -> InjectionToken STORAGE_PLUGIN -> InjectionToken STORAGE_PLUGIN]: 
	  NullInjectorError: No provider for InjectionToken STORAGE_PLUGIN!
	    at NullInjector.get (http://localhost:9876/_karma_webpack_/vendor.js:74891:27)
	    at R3Injector.get (http://localhost:9876/_karma_webpack_/vendor.js:75058:33)
	    at R3Injector.get (http://localhost:9876/_karma_webpack_/vendor.js:75058:33)
	    at injectInjectorOnly (http://localhost:9876/_karma_webpack_/vendor.js:68541:33)
	    at ɵɵinject (http://localhost:9876/_karma_webpack_/vendor.js:68545:61)
	    at Object.PreferenceManager_Factory [as factory] (ng:///PreferenceManager/ɵfac.js:4:45)
	    at R3Injector.hydrate (http://localhost:9876/_karma_webpack_/vendor.js:75228:35)
	    at R3Injector.get (http://localhost:9876/_karma_webpack_/vendor.js:75047:33)
	    at injectInjectorOnly (http://localhost:9876/_karma_webpack_/vendor.js:68541:33)
	    at ɵɵinject (http://localhost:9876/_karma_webpack_/vendor.js:68545:61)
	Error: Expected undefined to be truthy.
	    at <Jasmine>
	    at UserContext.<anonymous> (http://localhost:9876/_karma_webpack_/main.js:1131:25)
	    at ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/polyfills.js:8285:26)
	    at ProxyZoneSpec.onInvoke (http://localhost:9876/_karma_webpack_/vendor.js:340077:39)

after commit 4e5d9a3

test logs
[31mChrome Headless 98.0.4758.80 (Mac OS 10.15.7) GoProBluetoothService should be created FAILED
	NullInjectorError: R3InjectorError(DynamicTestModule)[GoProBluetoothService -> PreferenceManager -> InjectionToken STORAGE_PLUGIN -> InjectionToken STORAGE_PLUGIN]: 
	  NullInjectorError: No provider for InjectionToken STORAGE_PLUGIN!
	error properties: Object({ ngTempTokenPath: null, ngTokenPath: [ 'GoProBluetoothService', 'PreferenceManager', 'InjectionToken STORAGE_PLUGIN', 'InjectionToken STORAGE_PLUGIN' ] })
	NullInjectorError: R3InjectorError(DynamicTestModule)[GoProBluetoothService -> PreferenceManager -> InjectionToken STORAGE_PLUGIN -> InjectionToken STORAGE_PLUGIN]: 
	  NullInjectorError: No provider for InjectionToken STORAGE_PLUGIN!
	    at NullInjector.get (http://localhost:9876/_karma_webpack_/vendor.js:74891:27)
	    at R3Injector.get (http://localhost:9876/_karma_webpack_/vendor.js:75058:33)
	    at R3Injector.get (http://localhost:9876/_karma_webpack_/vendor.js:75058:33)
	    at injectInjectorOnly (http://localhost:9876/_karma_webpack_/vendor.js:68541:33)
	    at ɵɵinject (http://localhost:9876/_karma_webpack_/vendor.js:68545:61)
	    at Object.PreferenceManager_Factory [as factory] (ng:///PreferenceManager/ɵfac.js:4:45)
	    at R3Injector.hydrate (http://localhost:9876/_karma_webpack_/vendor.js:75228:35)
	    at R3Injector.get (http://localhost:9876/_karma_webpack_/vendor.js:75047:33)
	    at injectInjectorOnly (http://localhost:9876/_karma_webpack_/vendor.js:68541:33)
	    at ɵɵinject (http://localhost:9876/_karma_webpack_/vendor.js:68545:61)
	Error: Expected undefined to be truthy.
	    at <Jasmine>
	    at UserContext.<anonymous> (http://localhost:9876/_karma_webpack_/main.js:1077:25)
	    at ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/polyfills.js:8285:26)
	    at ProxyZoneSpec.onInvoke (http://localhost:9876/_karma_webpack_/vendor.js:340077:39)

Copy link
Contributor

@shc261392 shc261392 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@shc261392 shc261392 merged commit 487e684 into numbersprotocol:feature/experiments/go-pro/beta/1.0 Mar 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants