Skip to content

Commit

Permalink
[dashboard] keep team selection
Browse files Browse the repository at this point in the history
  • Loading branch information
svenefftinge committed Sep 26, 2022
1 parent 6c9f601 commit c7247d5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
4 changes: 2 additions & 2 deletions components/dashboard/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Redirect, Route, Switch } from "react-router";

import { Login } from "./Login";
import { UserContext } from "./user-context";
import { TeamsContext } from "./teams/teams-context";
import { getSelectedTeamSlug, TeamsContext } from "./teams/teams-context";
import { ThemeContext } from "./theme-context";
import { getGitpodService } from "./service/service";
import { shouldSeeWhatsNew, WhatsNew } from "./whatsnew/WhatsNew";
Expand Down Expand Up @@ -179,7 +179,7 @@ function App() {
const isRoot = window.location.pathname === "/" && hash === "";
if (isRoot) {
try {
const teamSlug = localStorage.getItem("team-selection");
const teamSlug = getSelectedTeamSlug();
if (teams.some((t) => t.slug === teamSlug)) {
history.push(`/t/${teamSlug}`);
}
Expand Down
14 changes: 4 additions & 10 deletions components/dashboard/src/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { countries } from "countries-list";
import gitpodIcon from "./icons/gitpod.svg";
import { getGitpodService, gitpodHostUrl } from "./service/service";
import { UserContext } from "./user-context";
import { TeamsContext, getCurrentTeam } from "./teams/teams-context";
import { TeamsContext, getCurrentTeam, setSelectedTeamSlug, getSelectedTeamSlug } from "./teams/teams-context";
import getSettingsMenu from "./settings/settings-menu";
import { getAdminMenu } from "./admin/admin-menu";
import ContextMenu from "./components/ContextMenu";
Expand Down Expand Up @@ -92,13 +92,6 @@ export default function Menu() {

const userFullName = user?.fullName || user?.name || "...";

{
// updating last team selection
try {
localStorage.setItem("team-selection", team ? team.slug : "");
} catch {}
}

// Hide most of the top menu when in a full-page form.
const isMinimalUI = inResource(location.pathname, ["new", "teams/new", "open"]);
const isWorkspacesUI = inResource(location.pathname, ["workspaces"]);
Expand Down Expand Up @@ -300,7 +293,8 @@ export default function Menu() {
<span className="">Personal Account</span>
</div>
),
active: !team,
onClick: () => setSelectedTeamSlug(""),
active: getSelectedTeamSlug() === "",
separator: true,
link: "/projects",
},
Expand All @@ -321,7 +315,7 @@ export default function Menu() {
</span>
</div>
),
active: team && team.id === t.id,
active: getSelectedTeamSlug() === t.slug,
separator: true,
link: `/t/${t.slug}`,
}))
Expand Down
15 changes: 14 additions & 1 deletion components/dashboard/src/teams/teams-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,18 @@ export function getCurrentTeam(location: Location<any>, teams?: Team[]): Team |
if (!slug || !teams) {
return;
}
return teams.find((t) => t.slug === slug);
const team = teams.find((t) => t.slug === slug);
if (!team) {
return;
}
setSelectedTeamSlug(team.slug);
return team;
}

export function getSelectedTeamSlug(): string {
return localStorage.getItem("team-selection") || "";
}

export function setSelectedTeamSlug(teamSlug?: string): void {
return localStorage.setItem("team-selection", teamSlug || "");
}

0 comments on commit c7247d5

Please sign in to comment.