@@ -23,7 +23,7 @@ import { Loading, Refresh } from "../icons";
2323import { db } from "../../common/db" ;
2424import { writeText } from "clipboard-polyfill" ;
2525import { showToast } from "../../utils/toast" ;
26- import { EV , EVENTS , hosts , MonographAnalytics } from "@notesnook/core" ;
26+ import { EV , EVENTS , hosts } from "@notesnook/core" ;
2727import { useStore } from "../../stores/monograph-store" ;
2828import { Note } from "@notesnook/core" ;
2929import { strings } from "@notesnook/intl" ;
@@ -64,6 +64,9 @@ function PublishView(props: PublishViewProps) {
6464 if ( ! monographAnalytics ?. isAllowed || ! monograph ) return { totalViews : 0 } ;
6565 return await db . monographs . analytics ( monograph ?. id ) ;
6666 } , [ monograph ?. id , monographAnalytics ] ) ;
67+ const publishUrl = usePromise ( async ( ) => {
68+ return await db . monographs . publishUrl ( note . id ) ;
69+ } , [ monograph ?. id , monograph ?. publishUrl ] ) ;
6770
6871 useEffect ( ( ) => {
6972 const fileDownloadedEvent = EV . subscribe (
@@ -95,23 +98,27 @@ function PublishView(props: PublishViewProps) {
9598 variant = "text.body"
9699 as = "a"
97100 target = "_blank"
98- href = { ` ${ hosts . MONOGRAPH_HOST } / ${ monograph ?. id } ` }
101+ href = { publishUrl . status === "fulfilled" ? publishUrl . value : "#" }
99102 sx = { {
100103 textOverflow : "ellipsis" ,
101104 whiteSpace : "nowrap" ,
102105 textDecoration : "none" ,
103106 overflow : "hidden" ,
104- px : 1
107+ px : 1 ,
108+ opacity : publishUrl . status === "fulfilled" ? 1 : 0.8
105109 } }
106110 >
107- { ` ${ hosts . MONOGRAPH_HOST } / ${ monograph ?. id } ` }
111+ { publishUrl . status === "fulfilled" ? publishUrl . value : "" }
108112 </ Link >
109113 < Button
110114 variant = "secondary"
111115 className = "copyPublishLink"
112116 sx = { { flexShrink : 0 , m : 0 } }
117+ disabled = { publishUrl . status !== "fulfilled" }
113118 onClick = { ( ) => {
114- writeText ( `${ hosts . MONOGRAPH_HOST } /${ monograph ?. id } ` ) ;
119+ if ( publishUrl . status !== "fulfilled" ) return ;
120+
121+ writeText ( publishUrl . value ) ;
115122 } }
116123 >
117124 { strings . copy ( ) }
@@ -425,6 +432,7 @@ type ResolvedMonograph = {
425432 selfDestruct : boolean ;
426433 publishedAt ?: number ;
427434 password ?: string ;
435+ publishUrl ?: string ;
428436} ;
429437
430438async function resolveMonograph (
@@ -435,6 +443,7 @@ async function resolveMonograph(
435443 return {
436444 id : monographId ,
437445 selfDestruct : ! ! monograph . selfDestruct ,
446+ publishUrl : monograph . publishUrl ,
438447 publishedAt : monograph . datePublished ,
439448 password : monograph . password
440449 ? await db . monographs . decryptPassword ( monograph . password )
0 commit comments