1- import { Button } from "@heroui/react" ;
1+ import { Button , Select , SelectItem } from "@heroui/react" ;
22import ModalWrapper from "./modal-wrapper" ;
33import { useSearchParams } from "next/navigation" ;
44import QRDisplay from "../misc/qr-display" ;
55import Tabs from "../misc/tabs" ;
66import { TabItem } from "@/lib/types" ;
7- import { useState } from "react" ;
7+ import { useEffect , useState } from "react" ;
88import Icon from "../misc/icon" ;
99import toast from "react-hot-toast" ;
10+ import { useAuth } from "@/lib/hooks/use-auth" ;
1011
1112export default function SharingModal ( {
1213 isOpen,
@@ -34,6 +35,37 @@ export default function SharingModal({
3435 tabItems [ 0 ] ,
3536 ) ;
3637
38+ const visibilityOptions = [ "public" , "unlisted" , "private" ] ;
39+ const [ selectedVisibility , setSelectedVisibility ] = useState <
40+ string | undefined
41+ > ( undefined ) ;
42+
43+ const { session } = useAuth ( ) ;
44+ const [ isDeveloper , setIsDeveloper ] = useState ( false ) ;
45+
46+ // Load app visibility
47+ useEffect ( ( ) => {
48+ async function getVisibility ( ) {
49+ if ( ! app ) return ;
50+
51+ const url = new URL ( `https://pulse-editor.com/api/extension/get` ) ;
52+ url . searchParams . append ( "app" , app ) ;
53+ url . searchParams . append ( "latest" , "true" ) ;
54+
55+ const res = await fetch ( url , {
56+ credentials : "include" ,
57+ } ) ;
58+
59+ const data : {
60+ visibility : string ;
61+ } [ ] = await res . json ( ) ;
62+ if ( data ) {
63+ const ext = data [ 0 ] ;
64+ setSelectedVisibility ( ext . visibility ) ;
65+ }
66+ }
67+ } , [ ] ) ;
68+
3769 return (
3870 < ModalWrapper
3971 isOpen = { isOpen }
@@ -42,39 +74,65 @@ export default function SharingModal({
4274 placement = { "center" }
4375 >
4476 < div className = "flex w-full flex-col items-center gap-2" >
45- < Tabs
46- tabItems = { tabItems }
47- selectedItem = { selectedTab }
48- setSelectedItem = { setSelectedTab }
49- />
50-
51- { selectedTab ?. name === tabItems [ 0 ] . name && (
52- < div className = "flex flex-col items-center gap-y-1" >
53- < p className = "text-content4-foreground text-sm" >
54- Share your workspace via this QR Code
55- </ p >
56- < QRDisplay url = { window . location . href } />
57- </ div >
77+ { app && (
78+ < Select
79+ label = "Visibility"
80+ placeholder = "Select visibility"
81+ onChange = { ( e ) => {
82+ setSelectedVisibility ( e . target . value ) ;
83+ } }
84+ isDisabled = { ! isDeveloper }
85+ >
86+ { visibilityOptions . map ( ( option ) => (
87+ < SelectItem key = { option } > { option } </ SelectItem >
88+ ) ) }
89+ </ Select >
5890 ) }
5991
60- { selectedTab ?. name === tabItems [ 1 ] . name && (
61- < div className = "flex flex-col items-center gap-y-1" >
62- < p className = "text-content4-foreground text-sm" >
63- Share your workspace via this URL
64- </ p >
92+ { ! selectedVisibility && app ? (
93+ < p > Select a visibility option to see sharing options.</ p >
94+ ) : selectedVisibility === "private" && app ? (
95+ < p > Your workspace is private.</ p >
96+ ) : (
97+ < >
98+ < Tabs
99+ tabItems = { tabItems }
100+ selectedItem = { selectedTab }
101+ setSelectedItem = { setSelectedTab }
102+ />
103+
104+ { selectedTab ?. name === tabItems [ 0 ] . name && (
105+ < div className = "flex flex-col items-center gap-y-1" >
106+ < p className = "text-content4-foreground text-sm" >
107+ Share your workspace via this QR Code
108+ </ p >
109+ < QRDisplay url = { window . location . href } />
110+ </ div >
111+ ) }
112+
113+ { selectedTab ?. name === tabItems [ 1 ] . name && (
114+ < div className = "flex flex-col items-center gap-y-1" >
115+ < p className = "text-content4-foreground text-sm" >
116+ Share your workspace via this URL
117+ </ p >
65118
66- < p className = "font-bold break-all" > { window . location . href } </ p >
67- < Button
68- color = "primary"
69- onPress = { ( ) => {
70- navigator . clipboard . writeText ( window . location . href ) ;
71- toast . success ( "URL copied to clipboard" ) ;
72- } }
73- >
74- < Icon name = "content_copy" className = "text-primary-foreground!" />
75- Copy
76- </ Button >
77- </ div >
119+ < p className = "font-bold break-all" > { window . location . href } </ p >
120+ < Button
121+ color = "primary"
122+ onPress = { ( ) => {
123+ navigator . clipboard . writeText ( window . location . href ) ;
124+ toast . success ( "URL copied to clipboard" ) ;
125+ } }
126+ >
127+ < Icon
128+ name = "content_copy"
129+ className = "text-primary-foreground!"
130+ />
131+ Copy
132+ </ Button >
133+ </ div >
134+ ) }
135+ </ >
78136 ) }
79137 </ div >
80138 </ ModalWrapper >
0 commit comments