Skip to content

Commit df2751d

Browse files
mfisher87arjxn-py
andauthored
Restore follow mode (#812)
* Attempt to fix follow The idea is that we'd pass in a custom icon renderer function to the UsersItem component. Our custom function is based on the old code prior to [PR #723](#723). I really don't know what I'm doing here. ToolbarWidget isn't a react component, so I don't know how to manage state! Perhaps we don't need to keep track of state at all, we just need to update the model and let the model keep track of it. Co-authored-by: Arjun Verma <[email protected]> * bring back follow mode * pointer and border for user item --------- Co-authored-by: Arjun Verma <[email protected]>
1 parent d5b1ee9 commit df2751d

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

packages/base/src/toolbar/widget.tsx

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import { UsersItem } from '@jupyter/collaboration';
2-
import { IJGISExternalCommand, JupyterGISModel } from '@jupytergis/schema';
1+
import { UsersItem, DefaultIconRenderer } from '@jupyter/collaboration';
2+
import {
3+
IUserData,
4+
IJGISExternalCommand,
5+
JupyterGISModel,
6+
} from '@jupytergis/schema';
37
import { CommandToolbarButton } from '@jupyterlab/apputils';
48
import {
59
MenuSvg,
@@ -32,10 +36,41 @@ export class Separator extends Widget {
3236
}
3337
}
3438

39+
function createUserIconRenderer(model: JupyterGISModel) {
40+
let selectedUserId: number | undefined;
41+
42+
return (props: { user: IUserData }): JSX.Element => {
43+
const { user } = props;
44+
const isSelected = user.userId === selectedUserId;
45+
const className = isSelected ? 'selected' : '';
46+
47+
const onClick = () => {
48+
if (user.userId === selectedUserId) {
49+
selectedUserId = undefined;
50+
model.setUserToFollow(undefined);
51+
} else {
52+
selectedUserId = user.userId;
53+
model.setUserToFollow(user.userId);
54+
}
55+
};
56+
57+
return (
58+
<DefaultIconRenderer
59+
user={user}
60+
onClick={onClick}
61+
className={className}
62+
/>
63+
);
64+
};
65+
}
66+
3567
export class ToolbarWidget extends ReactiveToolbar {
68+
private _model: JupyterGISModel;
69+
3670
constructor(options: ToolbarWidget.IOptions) {
3771
super();
3872

73+
this._model = options.model;
3974
this.addClass('jGIS-toolbar-widget');
4075

4176
if (options.commands) {
@@ -138,9 +173,12 @@ export class ToolbarWidget extends ReactiveToolbar {
138173
this.addItem('spacer', ReactiveToolbar.createSpacerItem());
139174

140175
// Users
176+
const iconRenderer = createUserIconRenderer(this._model);
141177
this.addItem(
142178
'users',
143-
ReactWidget.create(<UsersItem model={options.model} />),
179+
ReactWidget.create(
180+
<UsersItem model={this._model} iconRenderer={iconRenderer} />,
181+
),
144182
);
145183
}
146184
}

python/jupytergis_lab/style/base.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,3 +830,13 @@ div.jGIS-toolbar-widget > div.jp-Toolbar-item:last-child {
830830
border-bottom: 2px solid var(--jp-brand-color1);
831831
font-weight: 500;
832832
}
833+
834+
.jp-toolbar-users-item > .lm-MenuBar-itemIcon {
835+
cursor: pointer !important;
836+
border: 2px solid transparent;
837+
border-radius: 50%;
838+
}
839+
840+
.jp-toolbar-users-item > .lm-MenuBar-itemIcon.selected {
841+
border-color: var(--jp-brand-color1);
842+
}

0 commit comments

Comments
 (0)