This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 827
DnD Ordered TagPanel #1653
Merged
Merged
DnD Ordered TagPanel #1653
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
8178496
Implement Store for ordering tags in the tag panel
lukebarnard1 82a95f0
Simplify order_tag in TagOrderStore
lukebarnard1 a8a650c
Move TagTile to separate file, and make it dragable
lukebarnard1 7aa5dce
Move DragDropContext to wrap entire app
lukebarnard1 4af7def
Use AccountData im.vector.web.tag_ordering
lukebarnard1 35a108e
Simplify render of TagPanel - remove sorting
lukebarnard1 a9cc8eb
Remove redundant TagOrderStore.orderedTags setting
lukebarnard1 8f88995
Add analytics to TagOrderStore
lukebarnard1 7e1f1cd
Move DragDropContext to wrap LoggedInView
lukebarnard1 65d8833
Fix linting
lukebarnard1 ee6df10
Introduce action creators
lukebarnard1 1251544
Handle accountData events from TagOrderStore
lukebarnard1 7255096
Move 'commit_tags' to action creator
lukebarnard1 31a52c1
Fix bug with removing matrix listeners
lukebarnard1 53e7232
Linting
lukebarnard1 8f07744
Remove redundant MatrixChat
lukebarnard1 df88b71
Comment typo
lukebarnard1 991ea4e
Fix a few bugs with TagOrderStore:
lukebarnard1 aa91409
Return null if TagOrderStore is loading
lukebarnard1 0b38bf5
Do not allow ordering until TagOrderStore has loaded
lukebarnard1 8d2d3e6
Only commit a non-falsy tags list
lukebarnard1 a120335
Handle groups being joined and left
lukebarnard1 3e532e3
Use consistent indentation and break;s in TagOrderStore switch
lukebarnard1 60d8ebb
Refactor MatrixActions to something much easier to grok.
lukebarnard1 13925db
Refactor to allow dispatching of two kinds of Actions
lukebarnard1 d5534a9
Copyright
lukebarnard1 cc30b8f
Doc MatrixActionCreators properly
lukebarnard1 5de0559
Adjust actionCreators doc
lukebarnard1 42c1f3c
Fix incorrect bind
lukebarnard1 a8b245d
Add unmounted guard
lukebarnard1 f38690f
Doc orderedGroupTagProfiles
lukebarnard1 e1ea8f0
Copy state when initialisng, reset state when logging out
lukebarnard1 a653ece
Doc commitTagOrdering
lukebarnard1 ddf5dba
Doc fetchJoinedGroups
lukebarnard1 31ea092
Improve createAccountDataAction docs
lukebarnard1 fe6b7c0
Improve _addMatrixClientListener docs
lukebarnard1 950f591
Clarify more docs
lukebarnard1 6b02f59
Spelling
lukebarnard1 629cd13
Even better docs
lukebarnard1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
Copyright 2017 New Vector 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 { asyncAction } from './actionCreators'; | ||
|
||
const GroupActions = {}; | ||
|
||
/** | ||
* Creates an action thunk that will do an asynchronous request to fetch | ||
* the groups to which a user is joined. | ||
* | ||
* @param {MatrixClient} matrixClient the matrix client to query. | ||
* @returns {function} an action thunk that will dispatch actions | ||
* indicating the status of the request. | ||
* @see asyncAction | ||
*/ | ||
GroupActions.fetchJoinedGroups = function(matrixClient) { | ||
return asyncAction('GroupActions.fetchJoinedGroups', () => matrixClient.getJoinedGroups()); | ||
}; | ||
|
||
export default GroupActions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
Copyright 2017 New Vector 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'; | ||
|
||
// TODO: migrate from sync_state to MatrixActions.sync so that more js-sdk events | ||
// become dispatches in the same place. | ||
/** | ||
* Create a MatrixActions.sync action that represents a MatrixClient `sync` event, | ||
* each parameter mapping to a key-value in the action. | ||
* | ||
* @param {MatrixClient} matrixClient the matrix client | ||
* @param {string} state the current sync state. | ||
* @param {string} prevState the previous sync state. | ||
* @returns {Object} an action of type MatrixActions.sync. | ||
*/ | ||
function createSyncAction(matrixClient, state, prevState) { | ||
return { | ||
action: 'MatrixActions.sync', | ||
state, | ||
prevState, | ||
matrixClient, | ||
}; | ||
} | ||
|
||
/** | ||
* @typedef AccountDataAction | ||
* @type {Object} | ||
* @property {string} action 'MatrixActions.accountData'. | ||
* @property {MatrixEvent} event the MatrixEvent that triggered the dispatch. | ||
* @property {string} event_type the type of the MatrixEvent, e.g. "m.direct". | ||
* @property {Object} event_content the content of the MatrixEvent. | ||
*/ | ||
|
||
/** | ||
* Create a MatrixActions.accountData action that represents a MatrixClient `accountData` | ||
* matrix event. | ||
* | ||
* @param {MatrixClient} matrixClient the matrix client. | ||
* @param {MatrixEvent} accountDataEvent the account data event. | ||
* @returns {AccountDataAction} an action of type MatrixActions.accountData. | ||
*/ | ||
function createAccountDataAction(matrixClient, accountDataEvent) { | ||
return { | ||
action: 'MatrixActions.accountData', | ||
event: accountDataEvent, | ||
event_type: accountDataEvent.getType(), | ||
event_content: accountDataEvent.getContent(), | ||
}; | ||
} | ||
|
||
/** | ||
* This object is responsible for dispatching actions when certain events are emitted by | ||
* the given MatrixClient. | ||
*/ | ||
export default { | ||
// A list of callbacks to call to unregister all listeners added | ||
_matrixClientListenersStop: [], | ||
|
||
/** | ||
* Start listening to certain events from the MatrixClient and dispatch actions when | ||
* they are emitted. | ||
* @param {MatrixClient} matrixClient the MatrixClient to listen to events from | ||
*/ | ||
start(matrixClient) { | ||
this._addMatrixClientListener(matrixClient, 'sync', createSyncAction); | ||
this._addMatrixClientListener(matrixClient, 'accountData', createAccountDataAction); | ||
}, | ||
|
||
/** | ||
* Start listening to events of type eventName on matrixClient and when they are emitted, | ||
* dispatch an action created by the actionCreator function. | ||
* @param {MatrixClient} matrixClient a MatrixClient to register a listener with. | ||
* @param {string} eventName the event to listen to on MatrixClient. | ||
* @param {function} actionCreator a function that should return an action to dispatch | ||
* when given the MatrixClient as an argument as well as | ||
* arguments emitted in the MatrixClient event. | ||
*/ | ||
_addMatrixClientListener(matrixClient, eventName, actionCreator) { | ||
const listener = (...args) => { | ||
dis.dispatch(actionCreator(matrixClient, ...args)); | ||
}; | ||
matrixClient.on(eventName, listener); | ||
this._matrixClientListenersStop.push(() => { | ||
matrixClient.removeListener(eventName, listener); | ||
}); | ||
}, | ||
|
||
/** | ||
* Stop listening to events. | ||
*/ | ||
stop() { | ||
this._matrixClientListenersStop.forEach((stopListener) => stopListener()); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
Copyright 2017 New Vector 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 { asyncAction } from './actionCreators'; | ||
import TagOrderStore from '../stores/TagOrderStore'; | ||
|
||
const TagOrderActions = {}; | ||
|
||
/** | ||
* Creates an action thunk that will do an asynchronous request to | ||
* commit TagOrderStore.getOrderedTags() to account data and dispatch | ||
* actions to indicate the status of the request. | ||
* | ||
* @param {MatrixClient} matrixClient the matrix client to set the | ||
* account data on. | ||
* @returns {function} an action thunk that will dispatch actions | ||
* indicating the status of the request. | ||
* @see asyncAction | ||
*/ | ||
TagOrderActions.commitTagOrdering = function(matrixClient) { | ||
return asyncAction('TagOrderActions.commitTagOrdering', () => { | ||
// Only commit tags if the state is ready, i.e. not null | ||
const tags = TagOrderStore.getOrderedTags(); | ||
if (!tags) { | ||
return; | ||
} | ||
|
||
Analytics.trackEvent('TagOrderActions', 'commitTagOrdering'); | ||
return matrixClient.setAccountData('im.vector.web.tag_ordering', {tags}); | ||
}); | ||
}; | ||
|
||
export default TagOrderActions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
Copyright 2017 New Vector 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. | ||
*/ | ||
|
||
/** | ||
* Create an action thunk that will dispatch actions indicating the current | ||
* status of the Promise returned by 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 a function that returns a Promise. | ||
* @returns {function} an action thunk - a function that uses its single | ||
* argument as a dispatch function to dispatch the | ||
* following actions: | ||
* `${id}.pending` and either | ||
* `${id}.success` or | ||
* `${id}.failure`. | ||
*/ | ||
export function asyncAction(id, fn) { | ||
return (dispatch) => { | ||
dispatch({action: id + '.pending'}); | ||
fn().then((result) => { | ||
dispatch({action: id + '.success', result}); | ||
}).catch((err) => { | ||
dispatch({action: id + '.failure', err}); | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
ok 👍