-
-
Notifications
You must be signed in to change notification settings - Fork 827
DnD Ordered TagPanel #1653
DnD Ordered TagPanel #1653
Changes from 16 commits
8178496
82a95f0
a8a650c
7aa5dce
4af7def
35a108e
a9cc8eb
8f88995
7e1f1cd
65d8833
ee6df10
1251544
7255096
31a52c1
53e7232
8f07744
df88b71
991ea4e
aa91409
0b38bf5
8d2d3e6
a120335
3e532e3
60d8ebb
13925db
d5534a9
cc30b8f
5de0559
42c1f3c
a8b245d
f38690f
e1ea8f0
a653ece
ddf5dba
31ea092
fe6b7c0
950f591
6b02f59
629cd13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
Copyright 2017 Vector Creations Ltd | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { createPromiseActionCreator } from './actionCreators'; | ||
|
||
const GroupActions = {}; | ||
|
||
GroupActions.fetchJoinedGroups = createPromiseActionCreator( | ||
'GroupActions.fetchJoinedGroups', | ||
(matrixClient) => matrixClient.getJoinedGroups(), | ||
); | ||
|
||
export default GroupActions; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
Copyright 2017 Vector Creations Ltd | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { createMatrixActionCreator } from './actionCreators'; | ||
|
||
// Events emitted from the matrixClient that we want to dispatch as actions | ||
// via MatrixActionCreators. See createMatrixActionCreator. | ||
const REGISTERED_EVENTS = [ | ||
"accountData", | ||
]; | ||
|
||
export default { | ||
actionCreators: [], | ||
actionCreatorsStop: [], | ||
|
||
start(matrixClient) { | ||
this.actionCreators = REGISTERED_EVENTS.map((eventId) => | ||
createMatrixActionCreator(matrixClient, eventId), | ||
); | ||
this.actionCreatorsStop = this.actionCreators.map((ac) => ac()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like I'm missing something here. So an actioncreator is, aiui, a function which, when called, starts listening for a thing, and returns another function which will stop listening for that thing. so we fill There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OOB we decided to modify action creators so that they are all of the same structure and are either:
|
||
}, | ||
|
||
stop() { | ||
this.actionCreatorsStop.map((stop) => stop()); | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
Copyright 2017 Vector Creations Ltd | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import Analytics from '../Analytics'; | ||
import { createPromiseActionCreator } from './actionCreators'; | ||
import TagOrderStore from '../stores/TagOrderStore'; | ||
|
||
const TagOrderActions = {}; | ||
|
||
TagOrderActions.commitTagOrdering = createPromiseActionCreator( | ||
'TagOrderActions.commitTagOrdering', | ||
(matrixClient) => { | ||
Analytics.trackEvent('TagOrderActions', 'commitTagOrdering'); | ||
return matrixClient.setAccountData('im.vector.web.tag_ordering', { | ||
tags: TagOrderStore.getOrderedTags(), | ||
}); | ||
}, | ||
); | ||
|
||
export default TagOrderActions; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
Copyright 2017 Vector Creations Ltd | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import dis from '../dispatcher'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it not going to present a problem that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, we just lose the prevention of side-effects that flux employs. Are RoomView[Store] is screwed regardless. We're only screwed if any of our dispatches assume sync when they're not sync. |
||
|
||
/** | ||
* Create an action creator that will dispatch actions asynchronously that | ||
* indicate the current status of promise returned by the given function, fn. | ||
* @param {string} id the id to give the dispatched actions. This is given a | ||
* suffix determining whether it is pending, successful or | ||
* a failure. | ||
* @param {function} fn the function to call with arguments given to the | ||
* returned function. This function should return a Promise. | ||
* @returns {function} a function that dispatches asynchronous actions when called. | ||
*/ | ||
export function createPromiseActionCreator(id, fn) { | ||
return (...args) => { | ||
dis.dispatch({action: id + '.pending'}); | ||
fn(...args).then((result) => { | ||
dis.dispatch({action: id + '.success', result}); | ||
}).catch((err) => { | ||
dis.dispatch({action: id + '.failure', err}); | ||
}); | ||
}; | ||
} | ||
|
||
/** | ||
* Create an action creator that will listen to events of type eventId emitted | ||
* by matrixClient and dispatch a corresponding action of the following shape: | ||
* { | ||
* action: 'MatrixActions.' + eventId, | ||
* event: matrixEvent, | ||
* event_type: matrixEvent.getType(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we bother with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It simplifies the action handler slightly: case 'MatrixActions.accountData': {
if (payload.event_type !== 'im.vector.web.tag_ordering') break;
this._setState({
orderedTagsAccountData: payload.event_content ? payload.event_content.tags : null,
});
this._updateOrderedTags();
break;
} instead of putting What about just sending |
||
* event_content: matrixEvent.getContent(), | ||
* } | ||
* @param {MatrixClient} matrixClient the matrix client with which to register | ||
* a listener. | ||
* @param {string} eventId the ID of the event that hen emitted will cause the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🐔 |
||
* an action to be dispatched. | ||
* @returns {function} a function that, when called, will begin to listen to | ||
* dispatches from matrixClient. The result from that | ||
* function can be called to stop listening. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason the thing shouldn't start listening straight away? Then it could just return the stop function which is one less level of functions returning functions for me to keep track of. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only reason is that it wouldn't really be an Action Creator if you didn't have to call it to make it start dispatching things. |
||
*/ | ||
export function createMatrixActionCreator(matrixClient, eventId) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as per #riot-dev, I think that, for now at least, it's going to be clearer if you make this specific to accountData rather than trying to make it generic for all matrixClient-emitted events. |
||
const listener = (matrixEvent) => { | ||
dis.dispatch({ | ||
action: 'MatrixActions.' + eventId, | ||
event: matrixEvent, | ||
event_type: matrixEvent.getType(), | ||
event_content: matrixEvent.getContent(), | ||
}); | ||
}; | ||
return () => { | ||
matrixClient.on(eventId, listener); | ||
return () => { | ||
matrixClient.removeListener(eventId, listener); | ||
}; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ limitations under the License. | |
|
||
import * as Matrix from 'matrix-js-sdk'; | ||
import React from 'react'; | ||
import { DragDropContext } from 'react-dnd'; | ||
import HTML5Backend from 'react-dnd-html5-backend'; | ||
|
||
import { KeyCode, isOnlyCtrlOrCmdKeyEvent } from '../../Keyboard'; | ||
import Notifier from '../../Notifier'; | ||
|
@@ -38,7 +40,7 @@ import SettingsStore from "../../settings/SettingsStore"; | |
* | ||
* Components mounted below us can access the matrix client via the react context. | ||
*/ | ||
export default React.createClass({ | ||
const LoggedInView = React.createClass({ | ||
displayName: 'LoggedInView', | ||
|
||
propTypes: { | ||
|
@@ -344,3 +346,5 @@ export default React.createClass({ | |
); | ||
}, | ||
}); | ||
|
||
export default DragDropContext(HTML5Backend)(LoggedInView); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know little about react-dnd but I assume this still allows us to have other drag-n-drop contexts within it (ie. is it going to break the RoomTile DND?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The point of moving it to the root LoggedInView is such that we can actually do DnD wherever we please. The instructions said to wrap the entire app, using two contexts (on e.g. TagPanel and LeftPanel) causes bugs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok 👍 |
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.
New Vector, fwiw