@@ -2,28 +2,32 @@ import ob from 'urbit-ob';
22
33import { ensurePatFormat } from 'form/formatters';
44
5−// looks into the window context to find a "flow command", an object indicating
6−// if bridge is to be used for one specific flow.
7−// expects to find objects of the following shape, varying by kind:
5+// looks into the GET parameters and attempts to construct a "flow" object,
6+// which would indicate bridge is to be used for one specific flow.
7+// expects to find any of the following sets of parameters, varying by kind.
88//
9−// { kind: 'invite',
10−// as: '~ship', // who to send the invite as
11−// ship: '~ship', // what planet to send as the invite
12−// email: 'ex@amp.le' // email to send the invite code to
13−// }
9+// ? kind = invite
10+// & as = ~ship // who to send the invite as
11+// & ship = ~ship // what planet to send as the invite
12+// & email = ex@amp.le // email to send the invite code to
1413//
15−// you may optionally include .success() and .failure(reason) callbacks.
1614
1715const COMMANDS = {
1816 INVITE: 'invite',
1917};
2018
2119const useFlowCommand = () => {
22− let flow = window.flow;
20+ let flow = {};
21+ window.location.search
22+ .substr(1)
23+ .split('&')
24+ .forEach(arg => {
25+ if ('' === arg) return;
26+ const pam = arg.split('=');
27+ flow[pam[0]] = pam.length <= 1 ? true : decodeURIComponent(pam[1]);
28+ });
2329
2430 if (typeof flow === 'object') {
25− flow.success = flow.success || (() => {});
26− flow.failure = flow.failure || (() => {});
2731 switch (flow.kind) {
2832 case COMMANDS.INVITE:
2933 flow.as = ensurePatFormat(flow.as);
@@ -36,6 +40,8 @@ const useFlowCommand = () => {
3640 //
3741 default:
3842 console.log('unrecognized kind of flow:', flow.kind);
43+ // eslint-disable-next-line no-fallthrough
44+ case undefined:
3945 flow = null;
4046 break;
4147 }