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

All the features work as Components as well as feature and provide support of default/multi export #27

Merged
merged 28 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b2a2a6d
added initial code network connection
Apr 12, 2024
a005fb4
removed console
Apr 25, 2024
73def56
added globalThis wwith navigator
Apr 30, 2024
1cb5b78
renamed function
Apr 30, 2024
cb74039
added online offline component
Apr 30, 2024
a85052a
added readme file
Apr 30, 2024
7320edd
refactor(locateme): added locateme as a service
opensrc0 Apr 30, 2024
17ac63c
Merge branch 'main' of github.com:opensrc0/fe-pilot
opensrc0 Apr 30, 2024
c00834c
(fect): Removed space from template in boilerplate
opensrc0 May 3, 2024
fe2b5e5
(fect): Updated react version to 18.3.1 from 18.2.0
opensrc0 May 3, 2024
6ee5445
reverted code
May 6, 2024
09de465
Merge remote-tracking branch 'upstream/main' into feature_networkConn…
May 6, 2024
7d41487
refactored code
May 7, 2024
683d255
(fect): Refector Text to speech and provided the support as a service…
opensrc0 May 15, 2024
3559d20
resolved all the comments
May 16, 2024
bfda0ff
changes as per feedback
May 16, 2024
bb82941
(fect): Refector Text to speech and provided the support as a service…
opensrc0 May 16, 2024
084efb1
(fect): Refector Voice Recognition and provided the support as a ser…
opensrc0 May 16, 2024
c8b016b
(fect): Refector Text to speech child component, now supporting defau…
opensrc0 May 16, 2024
4d93d88
(fect): Refector export default and multi export in child component o…
opensrc0 May 16, 2024
388e3df
(fect): added id's in scanner child cmponent
opensrc0 May 16, 2024
1f568de
added via props in Scanner Image Upload
opensrc0 May 18, 2024
26108ef
(fect): Added new component called snapScanner
opensrc0 May 18, 2024
ed56e1d
(refector): Added new component called snapScanner
opensrc0 May 18, 2024
82302b1
Merge branch 'main' into feature_networkConnection
opensrc0 May 18, 2024
66f51b5
Merge pull request #26 from swarajgolu/feature_networkConnection
opensrc0 May 18, 2024
0d85aa7
(refector): Updated react latest version
opensrc0 May 18, 2024
064cb70
Merge branch 'main' of github.com:opensrc0/fe-pilot
opensrc0 May 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"react/jsx-fragments": ["off" ],
"react/jsx-props-no-spreading": ["off"],
"func-names": ["off"],
"no-restricted-exports": ["off"]
"no-restricted-exports": ["off"],
"import/no-named-as-default": 0,
"react/require-default-props": ["off"]
},
"parserOptions": {
"ecmaVersion":"latest"
Expand Down
2 changes: 2 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ import Share from 'fe-pilot/Share';
> 00. :white_check_mark:   [FaceDetector](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/FaceDetector/README.md)
> 00. :white_check_mark:   [LiveLocation](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/LiveLocationTracking/README.md)
> 00. :white_check_mark:   [LocateMe](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/LocateMe/README.md)
> 00. :white_check_mark:   [NetworkConnection](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/NetworkConnection/README.md)
> 00. :white_check_mark:   [PhoneBook](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/PhoneBook/README.md)
> 00. :white_check_mark:   [Scanner](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/Scanner/README.md)
> 00. :white_check_mark:   [Share](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/Share/README.md)
> 00. :white_check_mark:   [SnapScanner](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/SnapScanner/README.md)
> 00. :white_check_mark:   [TextToSpeech](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/TextToSpeech/README.md)
> 00. :white_check_mark:   [VoiceRecognition](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/VoiceRecognition/README.md)
> 00. :white_check_mark:   [Vibrate](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/Vibrate/README.md)
Expand Down
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,16 @@ import Share from 'fe-pilot/Share';
4. :white_check_mark:   [FaceDetector](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/FaceDetector/README.md)
5. :white_check_mark:   [LiveLocation](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/LiveLocationTracking/README.md)
6. :white_check_mark:   [LocateMe](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/LocateMe/README.md)
7. :white_check_mark:   [PhoneBook](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/PhoneBook/README.md)
8. :white_check_mark:   [Scanner](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/Scanner/README.md)
9. :white_check_mark:   [Share](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/Share/README.md)
10. :white_check_mark:   [TextToSpeech](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/TextToSpeech/README.md)
11. :white_check_mark:   [VoiceRecognition](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/VoiceRecognition/README.md)
12. :white_check_mark:   [Vibrate](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/Vibrate/README.md)
13. :white_check_mark:   [WakeLock](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/WakeLock/README.md)
14. :white_check_mark:   [WhatsappShare](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/WhatsappShare/README.md)
7. :white_check_mark:   [NetworkConnection](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/NetworkConnection/README.md)
8. :white_check_mark:   [PhoneBook](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/PhoneBook/README.md)
9. :white_check_mark:   [Scanner](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/Scanner/README.md)
10. :white_check_mark:   [Share](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/Share/README.md)
11. :white_check_mark:   [SnapScanner](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/SnapScanner/README.md)
12. :white_check_mark:   [TextToSpeech](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/TextToSpeech/README.md)
13. :white_check_mark:   [VoiceRecognition](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/VoiceRecognition/README.md)
14. :white_check_mark:   [Vibrate](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/Vibrate/README.md)
15. :white_check_mark:   [WakeLock](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/WakeLock/README.md)
16. :white_check_mark:   [WhatsappShare](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/WhatsappShare/README.md)
</details>

## Online Editor Templates
Expand Down
2 changes: 1 addition & 1 deletion __app/component/CopyToClipboard/CopyToClipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const failureMsgDefault = {
error: 'Unable To Copy',
};

const isBrowserSupport = () => globalThis?.navigator?.clipboard;
const isBrowserSupport = () => globalThis.navigator?.clipboard;

const copyToClipboard = ({
successCb = () => {},
Expand Down
85 changes: 49 additions & 36 deletions __app/component/LocateMe/LocateMe.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect } from 'react';
import PropTypes from 'prop-types';
import Wrapper from '../Wrapper/Wrapper';
import { handleSuccess, handleError, handleLoading } from '../services/handlerService';
import Wrapper from '../Wrapper/Wrapper';
import dependentJsService from '../services/dependentJsService';

const failureMsgDefault = {
Expand All @@ -14,6 +14,10 @@ const failureMsgDefault = {
error: '',
};

const isBrowserSupport = () => globalThis.navigator?.geolocation
&& globalThis.navigator?.permissions?.query
&& globalThis.navigator?.geolocation?.getCurrentPosition;

const checkPermitByBrowser = async (failureMsg, failureCb) => {
try {
const permissions = await navigator.permissions.query({ name: 'geolocation' });
Expand Down Expand Up @@ -83,23 +87,24 @@ const onSuccss = async (
handleSuccess({ msgType: 'SUCCESSFUL', msg: successMsg, successCb, data: zipcode });
};

const onFailure = async (failureCb, error, failureMsg) => handleError({ msgType: 'ERROR', msg: failureMsg.error || JSON.stringify(error), failureCb });

function LocateMe({
successCb,
failureCb,
successMsg,
failureMsg: failureMsgProps,
loadingCb,
children,
isProdKey,
googleKey,
}) {
const onFailure = async (failureCb, error, failureMsg) => handleError({ msgType: 'ERROR', msg: failureMsg.error || error, failureCb });

const locateMe = ({
successCb = () => {},
failureCb = () => {},
loadingCb = () => {},
successMsg = 'Located Successfully!!',
failureMsg: failureMsgProps = { ...failureMsgDefault },
isProdKey = true,
googleKey = '',
} = {}) => {
const failureMsg = { ...failureMsgDefault, ...failureMsgProps };

const onClick = async () => {
if (LocateMe.isBrowserSupport()) {
const init = async () => {
if (isBrowserSupport()) {
handleLoading({ loadingCb });

// Your Code will start from here
const isPermitByBrowser = await checkPermitByBrowser(failureMsg, failureCb);
const isScriptInBrowser = await checkScriptInBrowser(
failureMsg,
Expand All @@ -120,12 +125,25 @@ function LocateMe({
onFailure(failureCb, error, failureMsg);
});
}
// Your Code will end here
} else {
return handleError({ msgType: 'UN_SUPPORTED_FEATURE', msg: failureMsg.unSupported, failureCb });
}
return true;
};

init();
};

function LocateMe({
children,
successCb,
failureCb,
loadingCb,
successMsg,
failureMsg,
...props
}) {
useEffect(() => {
globalThis.console.error = (...arg) => {
if (arg[0] && arg[0]?.indexOf('https://developers.google.com/maps/documentation/javascript/error-messages') !== -1) {
Expand All @@ -138,36 +156,31 @@ function LocateMe({
};
}, []);

return (
React.Children.map(children || 'Use my current location', (child) => React.cloneElement(typeof child === 'string' ? <span>{child}</span> : child, {
onClick,
}))
);
return React.Children.map(children || 'LocateMe', (child) => React.cloneElement(typeof child === 'string' ? <span>{child}</span> : child, {
onClick: () => locateMe({
successCb,
failureCb,
loadingCb,
successMsg,
failureMsg,
...props,
}),
}));
}

LocateMe.isBrowserSupport = () => navigator.geolocation
&& navigator?.permissions?.query
&& navigator?.geolocation?.getCurrentPosition
&& true;

LocateMe.propTypes = {
showForever: PropTypes.bool,
successCb: PropTypes.func,
failureCb: PropTypes.func,
loadingCb: PropTypes.func,
successMsg: PropTypes.string,
failureMsg: PropTypes.object,
isProdKey: PropTypes.bool,
googleKey: PropTypes.string.isRequired,
googleKey: PropTypes.string,
};

LocateMe.defaultProps = {
successCb: () => {},
failureCb: () => {},
loadingCb: () => {},
successMsg: 'Located Successfully',
failureMsg: { ...failureMsgDefault },
isProdKey: true,
googleKey: '',
};
const WLocateMe = Wrapper(LocateMe, isBrowserSupport);

export { locateMe, WLocateMe as LocateMe };

export default Wrapper(LocateMe);
export default WLocateMe;
7 changes: 2 additions & 5 deletions __app/component/LocateMe/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
import LocateMe from './LocateMe';

export { LocateMe };

export default LocateMe;
export * from './LocateMe';
export { default } from './LocateMe';
108 changes: 108 additions & 0 deletions __app/component/NetworkConnection/NetworkConnection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import {
handleSuccess,
handleError,
handleLoading,
} from '../services/handlerService';
import Wrapper from '../Wrapper/Wrapper';

const failureMsgDefault = {
unSupported: 'NetworkConnection is not supporting in your device',
error: 'Unable to fetch details from NetworkConnection',
};

const isBrowserSupport = () => globalThis?.navigator?.onLine || false;

const networkConnection = ({
successCb = () => {},
failureCb = () => {},
loadingCb = () => {},
successMsg = 'NetworkConnection details fetch Successfully!',
failureMsg: failureMsgProps = { ...failureMsgDefault },
} = {}) => {
const failureMsg = { ...failureMsgDefault, ...failureMsgProps };

const init = () => {
if (isBrowserSupport() === true || isBrowserSupport() === false) {
handleLoading({ loadingCb });

handleSuccess({
msgType: 'SUCCESSFUL',
msg: successMsg,
successCb,
data: {
online: isBrowserSupport(),
connectionDetail: globalThis?.navigator?.connection,
},
});
} else {
return handleError({
msgType: 'UN_SUPPORTED_FEATURE',
msg: failureMsg.unSupported,
failureCb,
});
}
return true;
};

init();
};

function NetworkConnection({
children,
successCb,
failureCb,
loadingCb,
successMsg,
failureMsg,
}) {
const [isOnline, setIsOnline] = useState(isBrowserSupport());

const onlineOfflineHandler = () => {
setIsOnline(isBrowserSupport());
networkConnection(successCb, failureCb, loadingCb, successMsg, failureMsg);
};

const networkChangeHandler = () => {
if (!isBrowserSupport()) return;

networkConnection(successCb, failureCb, loadingCb, successMsg, failureMsg);
};

useEffect(() => {
networkConnection(successCb, failureCb, loadingCb, successMsg, failureMsg);

globalThis.addEventListener('online', onlineOfflineHandler);
globalThis.addEventListener('offline', onlineOfflineHandler);
globalThis?.navigator.connection.addEventListener('change', networkChangeHandler);

return () => {
globalThis.removeEventListener('online', onlineOfflineHandler);
globalThis.removeEventListener('offline', onlineOfflineHandler);
globalThis.navigator.connection.removeEventListener('change', networkChangeHandler);
};
}, []);

return React.Children.map(children || 'NetworkConnection', (child) => React.cloneElement(
typeof child === 'string' ? <span>{child}</span> : child,
{
isOnline,
},
));
}

NetworkConnection.propTypes = {
showForever: PropTypes.bool,
successCb: PropTypes.func,
failureCb: PropTypes.func,
loadingCb: PropTypes.func,
successMsg: PropTypes.string,
failureMsg: PropTypes.object,
};

const WNetworkConnection = Wrapper(NetworkConnection, isBrowserSupport);

export { networkConnection, WNetworkConnection as NetworkConnection };

export default WNetworkConnection;
7 changes: 7 additions & 0 deletions __app/component/NetworkConnection/Offline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';

function Offline({ children, isOnline }) {
return !isOnline && React.Children.map(children || 'Online', (child) => React.cloneElement(typeof child === 'string' ? <span>{child}</span> : child));
}

export default Offline;
7 changes: 7 additions & 0 deletions __app/component/NetworkConnection/Online.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';

function Online({ children, isOnline }) {
return isOnline && React.Children.map(children || 'Online', (child) => React.cloneElement(typeof child === 'string' ? <span>{child}</span> : child));
}

export default Online;
30 changes: 30 additions & 0 deletions __app/component/NetworkConnection/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

# Network Connection

A Network Connection Component returns online status and also information about the system's connection in terms of general connection type (e.g., 'Wi-Fi, 'cellular', etc.). Which can be used to select high-definition content or low-definition content based on the user's connection.


## Usage/Examples

```javascript
import { NetworkConnection, Online, Offline} from 'fe-pilot/NetworkConnection';

const success = (response) => {
console.log(response, " success response")
}

const failure = (response) => {
console.log(response, " failure response")
}

return (
<NetworkConnection successCb={success} failureCb={failure}>
<Online>Online</Online>
<Offline>
<div>Pass custom Html to be displayed when appeared offline</div>
</Offline>
</NetworkConnection>
);
}
```

7 changes: 7 additions & 0 deletions __app/component/NetworkConnection/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { NetworkConnection } from './NetworkConnection';
import Online from './Online';
import Offline from './Offline';

export { NetworkConnection, Online, Offline };

export default NetworkConnection;
2 changes: 1 addition & 1 deletion __app/component/PhoneBook/PhoneBook.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const failureMsgDefault = {
error: 'Unable to fetch details from PhoneBook',
};

const isBrowserSupport = () => globalThis?.navigator?.contacts && globalThis?.ContactsManage;
const isBrowserSupport = () => globalThis.navigator?.contacts && globalThis.ContactsManage;

const phoneBook = ({
successCb = () => {},
Expand Down
Loading
Loading