-
Notifications
You must be signed in to change notification settings - Fork 16
Fix: some miscellaneous & tiny bugs #193
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
Conversation
Update: Fix the selection issue for guest users. Now they can also multi-select pods like other users. (pre-requirement for multi-pod copy by guests) |
ui/src/components/Canvas.tsx
Outdated
const role = useStore(store, (state) => state.role); | ||
const isGuest = useStore(store, (state) => state.isGuest()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two reasons pull me back from this change.
-
Here,
isGuest
is the result of calling a Zustand action functionstate.isGuest()
. I have never seen such usage before, and I doubt that it might be incompatible with zustand's ability to "Renders components only on changes". I.e.,isGuest
might not be able to trigger a re-render ifstore.role
changes. Thus, I don't think we want to use this pattern. -
Also, it adds two more actions (
isGuest
andisOwner
) in Zustand store (which are effectively global functions). We want to keep Zustand store lean, only those states and state mutators.
For reference, below is Zustand store's typical usage pattern: state and state mutators:
const useFishStore = create((set) => ({
salmon: 1,
tuna: 2,
deleteEverything: () => set({}, true), // clears the entire store, actions included
deleteTuna: () => set((state) => omit(state, ['tuna']), true),
}))
Back to our problem, we could define isGuest
and isOwner
as functions, and use isGuest(role)
here, e.g.,
// store/index.tsx or some utils.tsx
export const isGuest = (role) => role === RoleType.GUEST
// Code.tsx
import {isGuest} from ...
function Component() {
const role = useStore(..., state.role)
...
return <Box>{isGuest(role) && <Box>I'm guest</Box>}</Box>
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I would remove enum RoleType
and just use this (which is still type-safe):
// repoStateSlice.tsx
export interface RepoStateSlice {
...
role: "owner" | "guest" | "collaborator";
...
}
// Code.tsx
function Component() {
const role = useStore(..., state.role)
...
return <Box>{role === "guest" && <Box>I'm guest</Box>}</Box>
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure it must re-render when role changes because I set all the initial role as GUEST
in the beginning, and it re-enables editing when the repo loads successfully for non-guest users. It's a function call evaluated in real-time, not a function declaration.
I just feel it may be problematic to expose the explicit role info to other components. We just need to know it abstractly. I have two ideas to do that:
- Instead of setting
role
instore
, split it to two fieldsisGuest: boolean
andisOwner: boolean
. - Similar to your solution, but hide the actual
role
like:
// store/index.tsx or some utils.tsx
export const checkGuest = (role) => role === RoleType.GUEST
// Code.tsx
import {isGuest} from ...
function Component() {
const isGuest = useStore(..., checkGuest(state.role))
...
return <Box>{isGuest && <Box>I'm guest</Box>}</Box>
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Instead of setting
role
instore
, split it to two fieldsisGuest: boolean
andisOwner: boolean
.
This will leave space for bugs, e.g. we can set both isGuest
and isOwner
to true
.
- Similar to your solution, but hide the actual role like:
Sounds good, let's use this.
Update: I finally removed the There are still three known issues in this PR:
A possible solution: stop using if (Math.abs(node1.position.x-node2.position.x) > Number.EPSILON) {
...
}
onChange={(parameter) => {
if(isGuest && parameter.tr?.docChanged) return;
...
}} But I feel many features are really wired in |
It is because reactflow nodes have <Box sx={{userSelect: "text", cursor: "auto"}}>
...
<Remirror/>
...
</Box> Let's fix it in another PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, Xinyi!
For reference, PR #196 allows text selection in result block. |
richNode
editing &codeNode
copying for guest usersnodesMap
More details can be found in comments.
Suggestions:
canvas.tsx
can be moved intolib/utils.tsx
likedbtype2nodetype
to makecanvas.tsx
more clear.Other works on the way:
Space
orEnter
(see richtext pod moves as cursor moves in text #166)