1
1
// import R from 'ramda'
2
2
3
- import { makeDebugger , $solver } from '../../utils'
3
+ import {
4
+ makeDebugger ,
5
+ asyncRes ,
6
+ asyncErr ,
7
+ $solver ,
8
+ dispatchEvent ,
9
+ TYPE ,
10
+ EVENT ,
11
+ ERR ,
12
+ } from '../../utils'
4
13
import SR71 from '../../utils/network/sr71'
5
14
15
+ import S from './schema'
16
+
6
17
const sr71$ = new SR71 ( )
7
18
let sub$ = null
8
19
@@ -12,6 +23,42 @@ const debug = makeDebugger('L:UserContent')
12
23
13
24
let store = null
14
25
26
+ export function followUser ( userId ) {
27
+ if ( ! store . isLogin ) {
28
+ store . authWarning ( )
29
+ }
30
+
31
+ sr71$ . mutate ( S . follow , { userId} )
32
+ }
33
+
34
+ export function undoFollowUser ( userId ) {
35
+ if ( ! store . isLogin ) {
36
+ store . authWarning ( )
37
+ }
38
+
39
+ sr71$ . mutate ( S . undoFollow , { userId} )
40
+ }
41
+
42
+ export function showFollowings ( user ) {
43
+ const type = TYPE . USER_LISTER_FOLLOWINGS
44
+ const data = {
45
+ id :user . id ,
46
+ brief :user . nickname ,
47
+ }
48
+
49
+ dispatchEvent ( EVENT . USER_LISTER_OPEN , { type, data} )
50
+ }
51
+
52
+ export function showFollowers ( user ) {
53
+ const type = TYPE . USER_LISTER_FOLLOWERS
54
+ const data = {
55
+ id :user . id ,
56
+ brief :user . nickname ,
57
+ }
58
+
59
+ dispatchEvent ( EVENT . USER_LISTER_OPEN , { type, data} )
60
+ }
61
+
15
62
export function tabChange ( activeThread ) {
16
63
store . markState ( { activeThread} )
17
64
store . markRoute ( { tab :activeThread } )
@@ -21,8 +68,35 @@ export function tabChange(activeThread) {
21
68
// Data & Error handlers
22
69
// ###############################
23
70
24
- const DataSolver = [ ]
25
- const ErrSolver = [ ]
71
+ const DataSolver = [
72
+ {
73
+ match :asyncRes ( 'follow' ) ,
74
+ action :( ) => {
75
+ debug ( 'follow done ' )
76
+ } ,
77
+ } ,
78
+ ]
79
+
80
+ const ErrSolver = [
81
+ {
82
+ match :asyncErr ( ERR . CRAPHQL ) ,
83
+ action :( { details} ) => {
84
+ debug ( 'ERR.CRAPHQL -->' , details )
85
+ } ,
86
+ } ,
87
+ {
88
+ match :asyncErr ( ERR . TIMEOUT ) ,
89
+ action :( { details} ) => {
90
+ debug ( 'ERR.TIMEOUT -->' , details )
91
+ } ,
92
+ } ,
93
+ {
94
+ match :asyncErr ( ERR . NETWORK ) ,
95
+ action :( { details} ) => {
96
+ debug ( 'ERR.NETWORK -->' , details )
97
+ } ,
98
+ } ,
99
+ ]
26
100
27
101
export function init ( _store ) {
28
102
if ( store ) return false