Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions src/renderer/src/routes/ProjectsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { remoteId, defaultWorkflow, useTeamWorkflowProcess } from '../crud';
import { UnsavedContext } from '../context/UnsavedContext';
import BigDialog from '../hoc/BigDialog';
import { StepEditor } from '../components/StepEditor';
import { useIsPapLike } from '../utils/useIsPapLike';

interface ProjectBoxProps extends BoxProps {
isMobile?: boolean;
Expand All @@ -32,14 +33,8 @@ export const ProjectsScreenInner: React.FC = () => {
const navigate = useMyNavigate();
const teamId = localStorage.getItem(localUserKey(LocalKey.team));
const ctx = React.useContext(TeamContext);
const {
teamProjects,
personalProjects,
personalTeam,
teams,
teamDirectoryReady,
isAdmin,
} = ctx.state;
const { teamProjects, personalProjects, personalTeam, teams, isAdmin } =
ctx.state;
const t: ICardsStrings = useSelector(cardsSelector, shallowEqual);
const { pathname } = useLocation();
const [plan] = useGlobal('plan');
Expand Down Expand Up @@ -74,11 +69,7 @@ export const ProjectsScreenInner: React.FC = () => {
}, []);

const isPersonal = teamId === personalTeam;
const isPapLike =
Boolean(personalTeam) &&
isPersonal &&
teams.length === 0 &&
teamDirectoryReady;
const isPapLike = useIsPapLike() && isPersonal;
const projects = React.useMemo(
() => (isPersonal ? personalProjects : teamId ? teamProjects(teamId) : []),
[isPersonal, personalProjects, teamId, teamProjects]
Expand Down
13 changes: 3 additions & 10 deletions src/renderer/src/routes/SwitchTeams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { useGlobal } from '../context/useGlobal';
import { useTeamActions } from '../components/Team/useTeamActions';
import { SharedContentCreatorDialog } from '../components/Team/SharedContentCreatorDialog';
import StickyRedirect from '../components/StickyRedirect';
import { useIsPapLike } from '../utils/useIsPapLike';

interface ISettingsButtonProps {
label: string;
Expand Down Expand Up @@ -404,16 +405,8 @@ export const SwitchTeamsGuard: React.FC<{ children: React.ReactNode }> = ({
children,
}) => {
const ctx = React.useContext(TeamContext);
const { teams, personalTeam, teamDirectoryReady } = ctx.state;
const [isOffline] = useGlobal('offline');
const [offlineOnly] = useGlobal('offlineOnly');
// When offline && !offlineOnly, getTeams() may be empty because shared teams
// without local projects are filtered out — not the same as true PAP-only.
const isPapLike =
Boolean(personalTeam) &&
teams.length === 0 &&
teamDirectoryReady &&
(!isOffline || offlineOnly);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gtryus Just want to flag that I am just removing the !isOffline part because it being true allows for an undesirable isPapLike=true

const { personalTeam } = ctx.state;
const isPapLike = useIsPapLike();

React.useEffect(() => {
if (!isPapLike || !personalTeam) return;
Expand Down
21 changes: 21 additions & 0 deletions src/renderer/src/utils/useIsPapLike.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import { TeamContext } from '../context/TeamContext';
import { useGlobal } from '../context/useGlobal';

/**
* True when the signed-in user is Work-Alone-Offline / PAP-like
*
* Detect "Work Alone Offline" via the `offlineOnly` global — `teams.length
* === 0` alone is not enough as it is also true for a normal user who simply hasn't joined a team yet.
* And not `!offline` (an online first-time user is online but still needs Switch
* Teams / Add Team). `offlineOnly` is set at login for users with no remoteId
* (see Access.tsx) and is the single reliable signal.
*/
export const useIsPapLike = (): boolean => {
const ctx = React.useContext(TeamContext);
const { teams, personalTeam, teamDirectoryReady } = ctx.state;
const [offlineOnly] = useGlobal('offlineOnly');
return Boolean(
personalTeam && teams.length === 0 && teamDirectoryReady && offlineOnly
);
};
Loading