Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remember last workspace visited by user #271

Merged
merged 1 commit into from
Nov 29, 2024
Merged

Conversation

vieiralucas
Copy link
Member

No description provided.

workspaces.data.find((workspace) => workspace.ownerId === user.id) ??
workspaces.data[0]
if (workspace) {
router.replace(`/workspaces/${workspaces.data[0].id}/documents`)
Copy link
Member

Choose a reason for hiding this comment

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

Can't workspaces.data[0] be undefined, technically speaking? Shouldn't we have kept that length check above?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a bug, it should use workspace.id

Comment on lines +17 to +22
const workspace =
data.find(
(workspace) => workspace.id === session.data?.lastVisitedWorkspaceId
) ??
data.find((workspace) => workspace.ownerId === session.data?.id) ??
data[0]
Copy link
Member

Choose a reason for hiding this comment

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

Probably not something for this PR, but it's kind of annoying that we have to have very similar code here and in the session redirect.

Comment on lines +2 to +5
ALTER TABLE "User" ADD COLUMN "lastVisitedWorkspaceId" UUID;

-- AddForeignKey
ALTER TABLE "User" ADD CONSTRAINT "User_lastVisitedWorkspaceId_fkey" FOREIGN KEY ("lastVisitedWorkspaceId") REFERENCES "Workspace"("id") ON DELETE SET NULL ON UPDATE CASCADE;
Copy link
Member

Choose a reason for hiding this comment

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

Can we make this migration set the first value of lastVisitedWorkspaceId as the latest workspace this user created? If that doesn't exist, we could just set it to the earliest workspace.

Copy link
Member Author

Choose a reason for hiding this comment

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

The source code will default to one he is owner of

@vieiralucas vieiralucas merged commit 542724b into main Nov 29, 2024
2 checks passed
@vieiralucas vieiralucas deleted the remember-user-workspace branch November 29, 2024 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants