@@ -46,7 +46,7 @@ const ShareOptions = ({ context, id }: ShareOptionsProps) => {
46
46
const [ isLoading , setIsLoading ] = useState ( false )
47
47
const { makeNotePrivate, makeNotePublic, isPublic } = useApi ( )
48
48
// const { makeNamespacePublic, makeNamespacePrivate } = useNamespaceApi()
49
- const { isNamespacePublic, makeNamespacePublic } = useNamespaces ( )
49
+ const { getNamespaceOfNodeid , isNamespacePublic, makeNamespacePublic } = useNamespaces ( )
50
50
51
51
const publicUrl = useMemo ( ( ) => {
52
52
if ( context === 'note' ) {
@@ -56,6 +56,16 @@ const ShareOptions = ({ context, id }: ShareOptionsProps) => {
56
56
}
57
57
} , [ id , isPublic , context , isNamespacePublic ] )
58
58
59
+ const noteNamespacePublicLink = useMemo ( ( ) => {
60
+ if ( context === 'note' ) {
61
+ const namespace = getNamespaceOfNodeid ( id )
62
+ return namespace && isNamespacePublic ( namespace . id )
63
+ ? apiURLs . namespaces . getPublicURLofNote ( namespace . id , id )
64
+ : undefined
65
+ }
66
+ return undefined
67
+ } , [ id , context ] )
68
+
59
69
// Helper function to set loading
60
70
const tryError = async ( fn : ( ) => Promise < void > ) => {
61
71
try {
@@ -106,26 +116,46 @@ const ShareOptions = ({ context, id }: ShareOptionsProps) => {
106
116
< div style = { { display : 'flex' , flex : 1 , alignItems : 'center' } } >
107
117
< MexIcon color = { theme . colors . primary } icon = { globalLine } fontSize = { 24 } margin = "0 1rem 0 0" />
108
118
< div style = { { gap : '1' , userSelect : 'none' } } >
109
- < CardTitle > Make this { context } public?</ CardTitle >
110
- < ItemDesc > Publish and share the link with everyone!</ ItemDesc >
119
+ { context === 'note' && noteNamespacePublicLink ? (
120
+ < >
121
+ < CardTitle > This note is in a public space.</ CardTitle >
122
+ < ItemDesc > Share the public space link</ ItemDesc >
123
+ </ >
124
+ ) : (
125
+ < >
126
+ < CardTitle > Make this { context } public?</ CardTitle >
127
+ < ItemDesc > Publish and share the link with everyone!</ ItemDesc >
128
+ </ >
129
+ ) }
111
130
</ div >
112
131
</ div >
113
132
< div style = { { display : 'flex' , alignItems : 'center' } } >
114
133
< span style = { { marginRight : '.5rem' } } >
115
- { publicUrl && (
116
- < CopyButton text = { publicUrl } size = "20px" beforeCopyTooltip = "Copy link" afterCopyTooltip = "Link copied!" />
134
+ { noteNamespacePublicLink ? (
135
+ < CopyButton
136
+ text = { noteNamespacePublicLink }
137
+ size = "20px"
138
+ beforeCopyTooltip = "Copy link"
139
+ afterCopyTooltip = "Link copied!"
140
+ />
141
+ ) : (
142
+ publicUrl && (
143
+ < CopyButton text = { publicUrl } size = "20px" beforeCopyTooltip = "Copy link" afterCopyTooltip = "Link copied!" />
144
+ )
117
145
) }
118
146
</ span >
119
147
{ isLoading ? (
120
148
< Loading dots = { 3 } transparent />
121
149
) : (
122
- < ToggleButton
123
- id = "toggle-public"
124
- value = { ! ! publicUrl }
125
- size = "sm"
126
- onChange = { flipPublicAccess }
127
- checked = { ! ! publicUrl }
128
- />
150
+ noteNamespacePublicLink === undefined && (
151
+ < ToggleButton
152
+ id = "toggle-public"
153
+ value = { ! ! publicUrl }
154
+ size = "sm"
155
+ onChange = { flipPublicAccess }
156
+ checked = { ! ! publicUrl }
157
+ />
158
+ )
129
159
) }
130
160
</ div >
131
161
</ Container >
0 commit comments