cmd/upspin-ui: don't attempt to show user's tree without dir endpoint

If a user elects not to nominate a DirServer then obviously they have no
tree; just display augie@upspin.io/ in both panels instead.

Change-Id: Ica4b43a76c8778e295fb864b38ce606df6f3df3e
Reviewed-on: https://upspin-review.googlesource.com/15940
Reviewed-by: Eric Grosse <grosse@gmail.com>
Reviewed-by: Rob Pike <r@golang.org>
diff --git a/cmd/upspin-ui/main.go b/cmd/upspin-ui/main.go
index c179639..1d244da 100644
--- a/cmd/upspin-ui/main.go
+++ b/cmd/upspin-ui/main.go
@@ -38,6 +38,8 @@
 	_ "upspin.io/transports"
 )
 
+const defaultPath = "augie@upspin.io/" // Show this tree on startup.
+
 func main() {
 	httpAddr := flag.String("http", "localhost:8000", "HTTP listen `address` (must be loopback)")
 	versionFlag := flag.Bool("version", false, "print version string and exit")
@@ -192,15 +194,28 @@
 		if err != nil {
 			errString = err.Error()
 		}
-		var user string
+		var (
+			user        upspin.UserName
+			left, right upspin.PathName
+		)
 		if cfg != nil {
-			user = string(cfg.UserName())
+			user = cfg.UserName()
+			right = defaultPath
+			// If the user has a directory endpoint then open to
+			// their tree. Otherwise, open both panels to augie.
+			if cfg.DirEndpoint().Transport == upspin.Remote {
+				left = upspin.PathName(user + "/")
+			} else {
+				left = right
+			}
 		}
 		resp = struct {
-			Startup  *startupResponse
-			UserName string
-			Error    string
-		}{sResp, user, errString}
+			Startup   *startupResponse
+			UserName  upspin.UserName
+			LeftPath  upspin.PathName
+			RightPath upspin.PathName
+			Error     string
+		}{sResp, user, left, right, errString}
 	case "list":
 		path := upspin.PathName(r.FormValue("path"))
 		des, err := s.cli.Glob(upspin.AllFilesGlob(path))
diff --git a/cmd/upspin-ui/static/script.js b/cmd/upspin-ui/static/script.js
index 4d7aed6..3d1545a 100644
--- a/cmd/upspin-ui/static/script.js
+++ b/cmd/upspin-ui/static/script.js
@@ -770,7 +770,7 @@
 		});
 	}
 
-	function startBrowsers() {
+	function startBrowsers(leftPath, rightPath) {
 		var browser1, browser2;
 		var parentEl = $(".up-browser-parent");
 		var methods = {
@@ -788,8 +788,8 @@
 			copyDestination: function() { return browser1.path },
 			refreshDestination: function() { browser1.refresh(); }
 		}, methods));
-		browser1.navigate(page.username);
-		browser2.navigate("augie@upspin.io");
+		browser1.navigate(leftPath);
+		browser2.navigate(rightPath);
 	}
 
 	// Obtain a request key.
@@ -814,7 +814,7 @@
 		// user name and launch the browsers.
 		page.username = data.UserName;
 		$("#headerUsername").text(page.username);
-		startBrowsers();
+		startBrowsers(data.LeftPath, data.RightPath);
 	});
 }