Skip to content

Commit

Permalink
Merge pull request #43 from idpass/fix-12-selectable-vids
Browse files Browse the repository at this point in the history
Filter shareable VIDs
  • Loading branch information
kneckinator authored Mar 2, 2022
2 parents 21e681f + ee6010d commit 09c8ed1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
6 changes: 6 additions & 0 deletions machines/vid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ export function selectMyVids(state: State) {
return state.context.myVids;
}

export function selectShareableVids(state: State) {
return state.context.myVids.filter(
(vidKey) => state.context.vids[vidKey]?.credential != null
);
}

export function selectReceivedVids(state: State) {
return state.context.receivedVids;
}
Expand Down
17 changes: 15 additions & 2 deletions machines/vidItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const vidItemMachine = model.createMachine(
{
cond: 'hasCredential',
target: 'idle',
actions: ['setCredential'],
actions: ['setCredential', 'updateVid'],
},
{
target: 'checkingServerData',
Expand Down Expand Up @@ -109,7 +109,12 @@ export const vidItemMachine = model.createMachine(
},
CREDENTIAL_DOWNLOADED: {
target: '#idle',
actions: ['setCredential', 'storeContext', 'logDownloaded'],
actions: [
'setCredential',
'storeContext',
'updateVid',
'logDownloaded',
],
},
},
},
Expand Down Expand Up @@ -140,6 +145,14 @@ export const vidItemMachine = model.createMachine(
},
{
actions: {
updateVid: send(
(context) => {
const { serviceRefs, ...vid } = context;
return { type: 'VID_DOWNLOADED', vid };
},
{ to: (context) => context.serviceRefs.vid }
),

requestVidContext: send(
(context) => ({
type: 'GET_VID_ITEM',
Expand Down
6 changes: 3 additions & 3 deletions screens/Scan/ScanScreenController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
selectStatusMessage,
} from '../../machines/scan';
import { selectVidLabel } from '../../machines/settings';
import { selectMyVids } from '../../machines/vid';
import { selectShareableVids } from '../../machines/vid';
import { MainRouteProps } from '../../routes/main';
import { GlobalContext } from '../../shared/GlobalContext';

Expand All @@ -19,7 +19,7 @@ export function useScanScreen({ navigation }: MainRouteProps) {
const settingsService = appService.children.get('settings');
const vidService = appService.children.get('vid');

const myVids = useSelector(vidService, selectMyVids);
const shareableVids = useSelector(vidService, selectShareableVids);
const isInvalid = useSelector(scanService, selectInvalid);

useEffect(() => {
Expand Down Expand Up @@ -55,7 +55,7 @@ export function useScanScreen({ navigation }: MainRouteProps) {
},

isInvalid,
isEmpty: !myVids.length,
isEmpty: !shareableVids.length,
isScanning: useSelector(scanService, selectScanning),
isReviewing: useSelector(scanService, selectReviewing),
isLocationDenied: useSelector(scanService, selectLocationDenied),
Expand Down
4 changes: 2 additions & 2 deletions screens/Scan/SendVidModalController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
selectVidName,
} from '../../machines/scan';
import { selectVidLabel } from '../../machines/settings';
import { selectMyVids } from '../../machines/vid';
import { selectShareableVids } from '../../machines/vid';
import { GlobalContext } from '../../shared/GlobalContext';
import { VID } from '../../types/vid';

Expand All @@ -26,7 +26,7 @@ export function useSendVidModal() {
reason: useSelector(scanService, selectReason),
vidName: useSelector(scanService, selectVidName),
vidLabel: useSelector(settingsService, selectVidLabel),
vidKeys: useSelector(vidService, selectMyVids),
vidKeys: useSelector(vidService, selectShareableVids),

isSelectingVid: useSelector(scanService, selectSelectingVid),
isSendingVid: useSelector(scanService, selectSendingVid),
Expand Down

0 comments on commit 09c8ed1

Please sign in to comment.