Skip to content

Commit 311a606

Browse files
authored
Fix public share links (#234)
#234
1 parent 6f4ddd8 commit 311a606

File tree

5 files changed

+62
-14
lines changed

5 files changed

+62
-14
lines changed

.changeset/rich-actors-confess.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'mexit-webapp': patch
3+
---
4+
5+
Fix share note link of public space

.changeset/smooth-mice-mate.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'mexit-webapp': patch
3+
---
4+
5+
Fix public share links

apps/webapp/src/Components/EditorInfobar/ShareOptions.tsx

+42-12
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const ShareOptions = ({ context, id }: ShareOptionsProps) => {
4646
const [isLoading, setIsLoading] = useState(false)
4747
const { makeNotePrivate, makeNotePublic, isPublic } = useApi()
4848
// const { makeNamespacePublic, makeNamespacePrivate } = useNamespaceApi()
49-
const { isNamespacePublic, makeNamespacePublic } = useNamespaces()
49+
const { getNamespaceOfNodeid, isNamespacePublic, makeNamespacePublic } = useNamespaces()
5050

5151
const publicUrl = useMemo(() => {
5252
if (context === 'note') {
@@ -56,6 +56,16 @@ const ShareOptions = ({ context, id }: ShareOptionsProps) => {
5656
}
5757
}, [id, isPublic, context, isNamespacePublic])
5858

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+
5969
// Helper function to set loading
6070
const tryError = async (fn: () => Promise<void>) => {
6171
try {
@@ -106,26 +116,46 @@ const ShareOptions = ({ context, id }: ShareOptionsProps) => {
106116
<div style={{ display: 'flex', flex: 1, alignItems: 'center' }}>
107117
<MexIcon color={theme.colors.primary} icon={globalLine} fontSize={24} margin="0 1rem 0 0" />
108118
<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+
)}
111130
</div>
112131
</div>
113132
<div style={{ display: 'flex', alignItems: 'center' }}>
114133
<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+
)
117145
)}
118146
</span>
119147
{isLoading ? (
120148
<Loading dots={3} transparent />
121149
) : (
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+
)
129159
)}
130160
</div>
131161
</Container>

apps/webapp/src/Views/PublicNamespaceView.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function PublicNamespaceView() {
1313
const [showLoader, setShowLoader] = useState(true)
1414
const { setNamespace, setILinks, setCurrentNode } = usePublicNodeStore()
1515
const namespaceID = useParams().namespaceID
16+
const noteID = useParams().nodeId
1617
const navigate = useNavigate()
1718
const { getPublicNamespaceAPI } = useNamespaceApi()
1819

@@ -30,7 +31,12 @@ function PublicNamespaceView() {
3031
updatedAt: response.updatedAt
3132
})
3233

33-
const firstNode = response.nodeHierarchy[0]
34+
// Use noteID in path params if found, otherwise open the first note in hierarchy
35+
const firstNode = noteID
36+
? response.nodeHierarchy.find((node: any) => node.nodeid === noteID) ?? response.nodeHierarchy[0]
37+
: response.nodeHierarchy[0]
38+
39+
// mog('firstNode', { firstNode, noteID })
3440

3541
setILinks(response.nodeHierarchy)
3642
navigate(`node/${firstNode.nodeid}`)

libs/core/src/Utils/routes.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ export const apiURLs = {
9696
share: `${MEXIT_BACKEND_URL_BASE}/namespace/share`,
9797
getUsersOfShared: (id: string) => `${MEXIT_BACKEND_URL_BASE}/namespace/shared/${id}/users`,
9898

99-
getPublicURL: (id: string) => `${MEXIT_FRONTEND_URL_BASE}/share/namespace/${id}`
99+
getPublicURL: (id: string) => `${MEXIT_FRONTEND_URL_BASE}/share/namespace/${id}`,
100+
getPublicURLofNote: (namespaceid: string, noteid: string) =>
101+
`${MEXIT_FRONTEND_URL_BASE}/share/namespace/${namespaceid}/node/${noteid}`
100102
},
101103

102104
// Link Shortener URLs

0 commit comments

Comments
 (0)