|
| 1 | +// import R from 'ramda' |
| 2 | + |
| 3 | +import{ |
| 4 | +makeDebugger, |
| 5 | +$solver, |
| 6 | +asyncRes, |
| 7 | +asyncErr, |
| 8 | +holdPage, |
| 9 | +unholdPage, |
| 10 | +ERR, |
| 11 | +EVENT, |
| 12 | +}from'../../utils' |
| 13 | +importSR71from'../../utils/network/sr71' |
| 14 | + |
| 15 | +importSfrom'./schema' |
| 16 | + |
| 17 | +constsr71$=newSR71({ |
| 18 | +resv_event:[EVENT.USER_LISTER_OPEN], |
| 19 | +}) |
| 20 | + |
| 21 | +letsub$=null |
| 22 | + |
| 23 | +/* eslint-disable no-unused-vars */ |
| 24 | +constdebug=makeDebugger('L:UserLister') |
| 25 | +/* eslint-enable no-unused-vars */ |
| 26 | + |
| 27 | +letstore=null |
| 28 | + |
| 29 | +exportfunctiononClose(){ |
| 30 | +store.markState({show:false}) |
| 31 | +unholdPage() |
| 32 | +} |
| 33 | + |
| 34 | +constloadUsers=()=>{ |
| 35 | +sr71$.query(S.pagedUsers,{filter:{page:1,size:20}}) |
| 36 | +} |
| 37 | + |
| 38 | +// ############################### |
| 39 | +// Data & Error handlers |
| 40 | +// ############################### |
| 41 | + |
| 42 | +constDataSolver=[ |
| 43 | +{ |
| 44 | +match:asyncRes(EVENT.USER_LISTER_OPEN), |
| 45 | +action:()=>{ |
| 46 | +loadUsers() |
| 47 | +store.markState({show:true}) |
| 48 | +holdPage() |
| 49 | +}, |
| 50 | +}, |
| 51 | +{ |
| 52 | +match:asyncRes('pagedUsers'), |
| 53 | +action:({ pagedUsers})=>store.markState({ pagedUsers}), |
| 54 | +}, |
| 55 | +] |
| 56 | +constErrSolver=[ |
| 57 | +{ |
| 58 | +match:asyncErr(ERR.CRAPHQL), |
| 59 | +action:({ details})=>{ |
| 60 | +debug('ERR.CRAPHQL -->',details) |
| 61 | +}, |
| 62 | +}, |
| 63 | +{ |
| 64 | +match:asyncErr(ERR.TIMEOUT), |
| 65 | +action:({ details})=>{ |
| 66 | +debug('ERR.TIMEOUT -->',details) |
| 67 | +}, |
| 68 | +}, |
| 69 | +{ |
| 70 | +match:asyncErr(ERR.NETWORK), |
| 71 | +action:({ details})=>{ |
| 72 | +debug('ERR.NETWORK -->',details) |
| 73 | +}, |
| 74 | +}, |
| 75 | +] |
| 76 | + |
| 77 | +exportfunctioninit(_store){ |
| 78 | +if(store)returnfalse |
| 79 | +store=_store |
| 80 | + |
| 81 | +debug(store) |
| 82 | +if(sub$)sub$.unsubscribe() |
| 83 | +sub$=sr71$.data().subscribe($solver(DataSolver,ErrSolver)) |
| 84 | +} |