@@ -8,14 +8,14 @@ import { MapSheetFieldsPage } from "./pages/MapSheetFields"
88import { Problem } from "./pages/Problem"
99import { SelectSheetPage } from "./pages/SelectSheet"
1010import {
11- getPluginContext ,
1211 type PluginContext ,
1312 type PluginContextUpdate ,
1413 syncSheet ,
1514 useFetchUserInfo ,
1615 useSheetQuery ,
1716 useSyncSheetMutation ,
1817} from "./sheets"
18+ import { showFieldMappingUI , showLoginUI } from "./ui"
1919import { assert , syncMethods } from "./utils"
2020
2121interface AppProps {
@@ -64,6 +64,8 @@ export function AuthenticatedApp({ pluginContext, setContext }: AuthenticatedApp
6464
6565 const { data : sheet , isPending : isSheetPending } = useSheetQuery ( spreadsheetId ?? "" , sheetTitle ?? "" )
6666
67+ const hasSheet = Boolean ( spreadsheetId && sheetTitle )
68+
6769 const syncMutation = useSyncSheetMutation ( {
6870 onSuccess : result => {
6971 logSyncResult ( result )
@@ -86,19 +88,45 @@ export function AuthenticatedApp({ pluginContext, setContext }: AuthenticatedApp
8688 } , [ isUserInfoError , isSelectSheetError , setContext ] )
8789
8890 useLayoutEffect ( ( ) => {
89- const width = sheetTitle !== null ? 360 : 320
90- const height = sheetTitle !== null ? 425 : 345
91-
92- void framer . showUI ( {
93- width,
94- height,
95- minWidth : width ,
96- minHeight : height ,
97- // Only allow resizing when mapping fields as the default size could not be enough.
98- // This will keep the given dimensions in the Select Sheet Screen.
99- resizable : sheetTitle !== null ,
100- } )
101- } , [ sheetTitle ] )
91+ const showUI = async ( ) => {
92+ try {
93+ if ( hasSheet ) {
94+ await showFieldMappingUI ( )
95+ } else {
96+ await showLoginUI ( )
97+ }
98+ } catch ( error ) {
99+ console . error ( error )
100+ framer . notify ( "Failed to open plugin. Check the logs for more details." , { variant : "error" } )
101+ }
102+ }
103+
104+ void showUI ( )
105+ } , [ sheetTitle , hasSheet , isSheetPending ] )
106+
107+ useEffect ( ( ) => {
108+ framer
109+ . setMenu ( [
110+ {
111+ label : `View ${ sheetTitle ?? "" } in Google Sheets` ,
112+ visible : Boolean ( spreadsheetId ) ,
113+ onAction : ( ) => {
114+ if ( ! spreadsheetId ) return
115+ window . open ( `https://docs.google.com/spreadsheets/d/${ spreadsheetId } /edit` , "_blank" )
116+ } ,
117+ } ,
118+ { type : "separator" } ,
119+ {
120+ label : "Log Out" ,
121+ onAction : ( ) => {
122+ void auth . logout ( )
123+ } ,
124+ } ,
125+ ] )
126+ . catch ( ( e : unknown ) => {
127+ console . error ( e )
128+ } )
129+ } , [ sheetTitle , spreadsheetId ] )
102130
103131 if ( ! spreadsheetId || sheetTitle === null ) {
104132 return (
@@ -185,7 +213,7 @@ export function App({ pluginContext }: AppProps) {
185213 } ) ,
186214 } )
187215
188- await framer . closePlugin ( )
216+ void framer . closePlugin ( )
189217 }
190218
191219 void task ( )
@@ -199,14 +227,7 @@ export function App({ pluginContext }: AppProps) {
199227 < p className = "text-content" >
200228 Your Google Account does not have access to the synced spreadsheet. Check your access and try again
201229 or{ " " }
202- < a
203- href = "#"
204- className = "text-sheets-green"
205- onClick = { ( ) => {
206- auth . logout ( )
207- void getPluginContext ( ) . then ( setContext )
208- } }
209- >
230+ < a href = "#" className = "text-sheets-green" onClick = { ( ) => void auth . logout ( ) } >
210231 log out
211232 </ a > { " " }
212233 and try a different account.
0 commit comments