1
- import React from 'react'
1
+ import React , { useMemo } from 'react'
2
2
import { StreamPermission } from '@streamr/sdk'
3
3
import styled from 'styled-components'
4
4
import { address0 } from '~/consts'
@@ -7,8 +7,9 @@ import { MEDIUM } from '~/shared/utils/styled'
7
7
import { StreamDraft } from '~/stores/streamDraft'
8
8
9
9
enum StreamType {
10
- Public = 'public ' ,
10
+ PublicSubscribe = 'publicSubscribe ' ,
11
11
Private = 'private' ,
12
+ PublicPubSub = 'publicPubSub' ,
12
13
}
13
14
14
15
type Props = {
@@ -20,17 +21,30 @@ export function StreamTypeSelector({ disabled }: Props) {
20
21
21
22
const bits = StreamDraft . useEntity ( { hot : true } ) ?. permissions [ address0 ] ?? null
22
23
23
- const streamType = bits ? StreamType . Public : StreamType . Private
24
+ const streamType = useMemo ( ( ) => {
25
+ if ( ! bits ) {
26
+ return StreamType . Private
27
+ }
28
+
29
+ switch ( bits ) {
30
+ case Bits [ StreamPermission . SUBSCRIBE ] :
31
+ return StreamType . PublicSubscribe
32
+ case Bits [ StreamPermission . SUBSCRIBE ] | Bits [ StreamPermission . PUBLISH ] :
33
+ return StreamType . PublicPubSub
34
+ default :
35
+ return StreamType . Private
36
+ }
37
+ } , [ bits ] )
24
38
25
39
return (
26
40
< Container >
27
41
< Item >
28
- < RadioContainer htmlFor = "public " >
42
+ < RadioContainer htmlFor = "publicSubscribe " >
29
43
< Radio
30
- id = "public "
44
+ id = "publicSubscribe "
31
45
type = "radio"
32
46
name = "streamType"
33
- checked = { streamType === StreamType . Public }
47
+ checked = { streamType === StreamType . PublicSubscribe }
34
48
onChange = { ( ) => {
35
49
update ( ( entity ) => {
36
50
entity . permissions [ address0 ] =
@@ -40,8 +54,8 @@ export function StreamTypeSelector({ disabled }: Props) {
40
54
disabled = { disabled }
41
55
/>
42
56
< div >
43
- < Title > Public stream </ Title >
44
- < Description > Anyone can subscribe to the stream</ Description >
57
+ < Title > Public subscribe </ Title >
58
+ < Description > Anyone can read/ subscribe to the stream</ Description >
45
59
</ div >
46
60
</ RadioContainer >
47
61
</ Item >
@@ -64,14 +78,36 @@ export function StreamTypeSelector({ disabled }: Props) {
64
78
disabled = { disabled }
65
79
/>
66
80
< div >
67
- < Title > Private stream </ Title >
81
+ < Title > Private subscribe </ Title >
68
82
< Description >
69
- Only Ethereum accounts listed below can subscribe to the
83
+ Only Ethereum accounts listed below can read/ subscribe to the
70
84
stream.
71
85
</ Description >
72
86
</ div >
73
87
</ RadioContainer >
74
88
</ Item >
89
+ < Item >
90
+ < RadioContainer htmlFor = "publicPubSub" >
91
+ < Radio
92
+ id = "publicPubSub"
93
+ type = "radio"
94
+ name = "streamType"
95
+ checked = { streamType === StreamType . PublicPubSub }
96
+ onChange = { ( ) => {
97
+ update ( ( entity ) => {
98
+ entity . permissions [ address0 ] =
99
+ Bits [ StreamPermission . SUBSCRIBE ] |
100
+ Bits [ StreamPermission . PUBLISH ]
101
+ } )
102
+ } }
103
+ disabled = { disabled }
104
+ />
105
+ < div >
106
+ < Title > Public publish & subscribe </ Title >
107
+ < Description > Anyone can write/publish to the stream</ Description >
108
+ </ div >
109
+ </ RadioContainer >
110
+ </ Item >
75
111
</ Container >
76
112
)
77
113
}
0 commit comments