()
| 96 | } | null; |
| 97 | |
| 98 | export function useWorkspaceDialogs() { |
| 99 | const [recentMobileRemoteWorkspacePaths, setRecentMobileRemoteWorkspacePaths] = useState< |
| 100 | string[] |
| 101 | >(() => loadRecentRemoteWorkspacePaths()); |
| 102 | const [mobileRemoteWorkspacePathPrompt, setMobileRemoteWorkspacePathPrompt] = |
| 103 | useState<MobileRemoteWorkspacePathPromptState>(null); |
| 104 | const mobileRemoteWorkspacePathResolveRef = useRef<((paths: string[]) => void) | null>( |
| 105 | null, |
| 106 | ); |
| 107 | |
| 108 | const resolveMobileRemoteWorkspacePathRequest = useCallback((paths: string[]) => { |
| 109 | const resolve = mobileRemoteWorkspacePathResolveRef.current; |
| 110 | mobileRemoteWorkspacePathResolveRef.current = null; |
| 111 | if (resolve) { |
| 112 | resolve(paths); |
| 113 | } |
| 114 | }, []); |
| 115 | |
| 116 | const requestMobileRemoteWorkspacePaths = useCallback(() => { |
| 117 | if (mobileRemoteWorkspacePathResolveRef.current) { |
| 118 | resolveMobileRemoteWorkspacePathRequest([]); |
| 119 | } |
| 120 | |
| 121 | setMobileRemoteWorkspacePathPrompt({ |
| 122 | value: "", |
| 123 | error: null, |
| 124 | recentPaths: recentMobileRemoteWorkspacePaths, |
| 125 | }); |
| 126 | |
| 127 | return new Promise<string[]>((resolve) => { |
| 128 | mobileRemoteWorkspacePathResolveRef.current = resolve; |
| 129 | }); |
| 130 | }, [recentMobileRemoteWorkspacePaths, resolveMobileRemoteWorkspacePathRequest]); |
| 131 | |
| 132 | const updateMobileRemoteWorkspacePathInput = useCallback((value: string) => { |
| 133 | setMobileRemoteWorkspacePathPrompt((prev) => |
| 134 | prev |
| 135 | ? { |
| 136 | ...prev, |
| 137 | value, |
| 138 | error: null, |
| 139 | } |
| 140 | : prev, |
| 141 | ); |
| 142 | }, []); |
| 143 | |
| 144 | const cancelMobileRemoteWorkspacePathPrompt = useCallback(() => { |
| 145 | setMobileRemoteWorkspacePathPrompt(null); |
| 146 | resolveMobileRemoteWorkspacePathRequest([]); |
| 147 | }, [resolveMobileRemoteWorkspacePathRequest]); |
| 148 | |
| 149 | const appendMobileRemoteWorkspacePathFromRecent = useCallback((path: string) => { |
| 150 | setMobileRemoteWorkspacePathPrompt((prev) => |
| 151 | prev |
| 152 | ? { |
| 153 | ...prev, |
| 154 | value: appendPathIfMissing(prev.value, path), |
| 155 | error: null, |
no test coverage detected