Skip to content

Commit 5636f81

Browse files
authored
Merge pull request #1962 from streamr-dev/FRONT-1526-public-stream
[FRONT-1526] Add public publish & subscribe option for stream edit page
2 parents 91c0484 + 0f9791e commit 5636f81

File tree

1 file changed

+46
-10
lines changed

1 file changed

+46
-10
lines changed

src/pages/AbstractStreamEditPage/AccessControlSection/StreamTypeSelector.tsx

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react'
1+
import React, { useMemo } from 'react'
22
import { StreamPermission } from '@streamr/sdk'
33
import styled from 'styled-components'
44
import { address0 } from '~/consts'
@@ -7,8 +7,9 @@ import { MEDIUM } from '~/shared/utils/styled'
77
import { StreamDraft } from '~/stores/streamDraft'
88

99
enum StreamType {
10-
Public = 'public',
10+
PublicSubscribe = 'publicSubscribe',
1111
Private = 'private',
12+
PublicPubSub = 'publicPubSub',
1213
}
1314

1415
type Props = {
@@ -20,17 +21,30 @@ export function StreamTypeSelector({ disabled }: Props) {
2021

2122
const bits = StreamDraft.useEntity({ hot: true })?.permissions[address0] ?? null
2223

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])
2438

2539
return (
2640
<Container>
2741
<Item>
28-
<RadioContainer htmlFor="public">
42+
<RadioContainer htmlFor="publicSubscribe">
2943
<Radio
30-
id="public"
44+
id="publicSubscribe"
3145
type="radio"
3246
name="streamType"
33-
checked={streamType === StreamType.Public}
47+
checked={streamType === StreamType.PublicSubscribe}
3448
onChange={() => {
3549
update((entity) => {
3650
entity.permissions[address0] =
@@ -40,8 +54,8 @@ export function StreamTypeSelector({ disabled }: Props) {
4054
disabled={disabled}
4155
/>
4256
<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>
4559
</div>
4660
</RadioContainer>
4761
</Item>
@@ -64,14 +78,36 @@ export function StreamTypeSelector({ disabled }: Props) {
6478
disabled={disabled}
6579
/>
6680
<div>
67-
<Title>Private stream</Title>
81+
<Title>Private subscribe</Title>
6882
<Description>
69-
Only Ethereum accounts listed below can subscribe to the
83+
Only Ethereum accounts listed below can read/subscribe to the
7084
stream.
7185
</Description>
7286
</div>
7387
</RadioContainer>
7488
</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>
75111
</Container>
76112
)
77113
}

0 commit comments

Comments
 (0)