Use MemberAvatar to generate image JSX. Split out entries from tab-complete logic
parent
618978d955
commit
0dbb8d5294
|
@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
var Entry = require("./TabCompleteEntries").Entry;
|
||||||
|
|
||||||
const DELAY_TIME_MS = 500;
|
const DELAY_TIME_MS = 500;
|
||||||
const KEY_TAB = 9;
|
const KEY_TAB = 9;
|
||||||
|
@ -40,7 +41,7 @@ class TabComplete {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {TabComplete.Entry[]} completeList
|
* @param {Entry[]} completeList
|
||||||
*/
|
*/
|
||||||
setCompletionList(completeList) {
|
setCompletionList(completeList) {
|
||||||
this.list = completeList;
|
this.list = completeList;
|
||||||
|
@ -74,7 +75,7 @@ class TabComplete {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Number} numAheadToPeek Return *up to* this many elements.
|
* @param {Number} numAheadToPeek Return *up to* this many elements.
|
||||||
* @return {TabComplete.Entry[]}
|
* @return {Entry[]}
|
||||||
*/
|
*/
|
||||||
peek(numAheadToPeek) {
|
peek(numAheadToPeek) {
|
||||||
if (this.matchedList.length === 0) {
|
if (this.matchedList.length === 0) {
|
||||||
|
@ -227,7 +228,7 @@ class TabComplete {
|
||||||
this.isFirstWord = group.length === this.originalText.length;
|
this.isFirstWord = group.length === this.originalText.length;
|
||||||
|
|
||||||
this.matchedList = [
|
this.matchedList = [
|
||||||
new TabComplete.Entry(group) // first entry is always the original partial
|
new Entry(group) // first entry is always the original partial
|
||||||
];
|
];
|
||||||
|
|
||||||
// find matching entries in the set of entries given to us
|
// find matching entries in the set of entries given to us
|
||||||
|
@ -247,10 +248,4 @@ class TabComplete {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TabComplete.Entry = function(text, imgUrl) {
|
|
||||||
this.text = text;
|
|
||||||
this.imgUrl = imgUrl;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = TabComplete;
|
module.exports = TabComplete;
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
/*
|
||||||
|
Copyright 2015 OpenMarket 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.
|
||||||
|
*/
|
||||||
|
var React = require("react");
|
||||||
|
var sdk = require("./index");
|
||||||
|
|
||||||
|
class Entry {
|
||||||
|
constructor(text) {
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {string} The text to display in this entry.
|
||||||
|
*/
|
||||||
|
getText() {
|
||||||
|
return this.text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {ReactClass} Raw JSX
|
||||||
|
*/
|
||||||
|
getImageJsx() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {?string} The unique key= prop for React dedupe
|
||||||
|
*/
|
||||||
|
getKey() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MemberEntry extends Entry {
|
||||||
|
constructor(member) {
|
||||||
|
super(member.name || member.userId);
|
||||||
|
this.member = member;
|
||||||
|
}
|
||||||
|
|
||||||
|
getImageJsx() {
|
||||||
|
var MemberAvatar = sdk.getComponent("views.avatars.MemberAvatar");
|
||||||
|
return (
|
||||||
|
<MemberAvatar member={this.member} width={24} height={24} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
getKey() {
|
||||||
|
return this.member.userId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.Entry = Entry;
|
||||||
|
module.exports.MemberEntry = MemberEntry;
|
|
@ -31,7 +31,7 @@ var MatrixClientPeg = require("../../../MatrixClientPeg");
|
||||||
var SlashCommands = require("../../../SlashCommands");
|
var SlashCommands = require("../../../SlashCommands");
|
||||||
var Modal = require("../../../Modal");
|
var Modal = require("../../../Modal");
|
||||||
var CallHandler = require('../../../CallHandler');
|
var CallHandler = require('../../../CallHandler');
|
||||||
var TabComplete = require("../../../TabComplete");
|
var MemberEntry = require("../../../TabCompleteEntries").MemberEntry;
|
||||||
var sdk = require('../../../index');
|
var sdk = require('../../../index');
|
||||||
|
|
||||||
var dis = require("../../../dispatcher");
|
var dis = require("../../../dispatcher");
|
||||||
|
@ -229,15 +229,7 @@ module.exports = React.createClass({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).map(function(m) {
|
}).map(function(m) {
|
||||||
var url = m.getAvatarUrl(
|
return new MemberEntry(m);
|
||||||
MatrixClientPeg.get().getHomeserverUrl(), 32, 32, "crop"
|
|
||||||
);
|
|
||||||
return new TabComplete.Entry(
|
|
||||||
m.name || m.userId,
|
|
||||||
// TODO: annoying that the JS SDK can return 0-len strings when
|
|
||||||
// it should be returning null.. can't use truthy constructs!
|
|
||||||
url && url.length > 0 ? url : null
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (this.props.tabComplete) {
|
if (this.props.tabComplete) {
|
||||||
|
|
|
@ -30,12 +30,9 @@ module.exports = React.createClass({
|
||||||
return (
|
return (
|
||||||
<div className="mx_TabCompleteBar">
|
<div className="mx_TabCompleteBar">
|
||||||
{this.props.entries.map(function(entry, i) {
|
{this.props.entries.map(function(entry, i) {
|
||||||
var image = (
|
|
||||||
entry.imgUrl ? <img src={entry.imgUrl} width="24" height="24"/> : null
|
|
||||||
);
|
|
||||||
return (
|
return (
|
||||||
<div key={i + ""} className="mx_TabCompleteBar_item">
|
<div key={entry.getKey() || i + ""} className="mx_TabCompleteBar_item">
|
||||||
{image}
|
{entry.getImageJsx()}
|
||||||
<span className="mx_TabCompleteBar_text">
|
<span className="mx_TabCompleteBar_text">
|
||||||
{entry.text}
|
{entry.text}
|
||||||
</span>
|
</span>
|
||||||
|
|
Loading…
Reference in New Issue