Skip to content

Commit

Permalink
refactor(INJI-394): extract method for vcs ordering by pin status
Browse files Browse the repository at this point in the history
Signed-off-by: Kiruthika Jeyashankar <[email protected]>
  • Loading branch information
KiruthikaJeyashankar committed Dec 1, 2023
1 parent 641f303 commit e53405f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
6 changes: 2 additions & 4 deletions screens/Home/MyVcsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
ErrorMessageOverlay,
MessageOverlay,
} from '../../components/MessageOverlay';
import {groupBy} from '../../shared/javascript';
import {VcItemContainer} from '../../components/VC/VcItemContainer';
import {BannerNotification} from '../../components/BannerNotification';
import {
Expand All @@ -23,16 +22,15 @@ import {TelemetryConstants} from '../../shared/telemetry/TelemetryConstants';

import {Error} from '../../components/ui/Error';
import {useIsFocused} from '@react-navigation/native';
import {getVCsOrderedByPinStatus} from '../../shared/Utils';

export const MyVcsTab: React.FC<HomeScreenTabProps> = props => {
const {t} = useTranslation('MyVcsTab');
const controller = useMyVcsTab(props);
const storeErrorTranslationPath = 'errors.savingFailed';
const [pinned, unpinned] = groupBy(
const vcMetadataOrderedByPinStatus = getVCsOrderedByPinStatus(
controller.vcMetadatas,
vcMetadata => vcMetadata.isPinned,
);
const vcMetadataOrderedByPinStatus = pinned.concat(unpinned);

const getId = () => {
controller.DISMISS();
Expand Down
6 changes: 2 additions & 4 deletions screens/QrLogin/MyBindedVcs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ import {QrLoginRef} from '../../machines/QrLoginMachine';
import {Icon} from 'react-native-elements';
import {Modal} from '../../components/ui/Modal';
import {VcItemContainer} from '../../components/VC/VcItemContainer';
import {groupBy} from '../../shared/javascript';
import {getVCsOrderedByPinStatus} from '../../shared/Utils';

export const MyBindedVcs: React.FC<MyBindedVcsProps> = props => {
const controller = useQrLogin(props);
const {t} = useTranslation('QrLogin');
const [pinned, unpinned] = groupBy(
const shareableVcsMetadataOrderedByPinStatus = getVCsOrderedByPinStatus(
controller.shareableVcsMetadata,
vcMetadata => vcMetadata.isPinned,
);
const shareableVcsMetadataOrderedByPinStatus = pinned.concat(unpinned);

return (
<Modal
Expand Down
6 changes: 2 additions & 4 deletions screens/Scan/SendVcScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@ import {
sendImpressionEvent,
} from '../../shared/telemetry/TelemetryUtils';
import {TelemetryConstants} from '../../shared/telemetry/TelemetryConstants';
import {groupBy} from '../../shared/javascript';
import {getVCsOrderedByPinStatus} from '../../shared/Utils';

export const SendVcScreen: React.FC = () => {
const {t} = useTranslation('SendVcScreen');
const {appService} = useContext(GlobalContext);
const controller = useSendVcScreen();
const [pinned, unpinned] = groupBy(
const shareableVcsMetadataOrderedByPinStatus = getVCsOrderedByPinStatus(
controller.shareableVcsMetadata,
vcMetadata => vcMetadata.isPinned,
);
const shareableVcsMetadataOrderedByPinStatus = pinned.concat(unpinned);
let service;

if (shareableVcsMetadataOrderedByPinStatus?.length > 0) {
Expand Down
10 changes: 10 additions & 0 deletions shared/Utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {VCMetadata} from './VCMetadata';
import {groupBy} from './javascript';

export const getVCsOrderedByPinStatus = (vcMetadatas: VCMetadata[]) => {
const [pinned, unpinned] = groupBy(
vcMetadatas,
(vcMetadata: VCMetadata) => vcMetadata.isPinned,
);
return pinned.concat(unpinned);
};

0 comments on commit e53405f

Please sign in to comment.