mirror of
https://codeberg.org/emersion/gamja
synced 2025-03-12 23:43:42 +01:00
Sort buffers when inserting, not when rendering
This allows all state.buffers users to iterate over the list in the correct order.
This commit is contained in:
parent
ee8b40aae4
commit
6c93bd13d1
@ -64,6 +64,24 @@ function debounce(f, delay) {
|
||||
};
|
||||
}
|
||||
|
||||
function compareBuffers(a, b) {
|
||||
if (a.type == BufferType.SERVER) {
|
||||
return -1;
|
||||
}
|
||||
if (b.type == BufferType.SERVER) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (a.name > b.name) {
|
||||
return -1;
|
||||
}
|
||||
if (a.name < b.name) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
export default class App extends Component {
|
||||
client = null;
|
||||
state = {
|
||||
@ -178,8 +196,8 @@ export default class App extends Component {
|
||||
type = BufferType.NICK;
|
||||
}
|
||||
|
||||
var buffers = new Map(state.buffers);
|
||||
buffers.set(name, {
|
||||
var bufferList = Array.from(state.buffers.values());
|
||||
bufferList.push({
|
||||
name,
|
||||
type,
|
||||
serverInfo: null, // if server
|
||||
@ -190,6 +208,8 @@ export default class App extends Component {
|
||||
messages: [],
|
||||
unread: Unread.NONE,
|
||||
});
|
||||
bufferList = bufferList.sort(compareBuffers);
|
||||
var buffers = new Map(bufferList.map((buf) => [buf.name, buf]));
|
||||
return { buffers };
|
||||
});
|
||||
}
|
||||
|
@ -26,28 +26,11 @@ function BufferItem(props) {
|
||||
`;
|
||||
}
|
||||
|
||||
function compareBuffers(a, b) {
|
||||
if (a.type == BufferType.SERVER) {
|
||||
return -1;
|
||||
}
|
||||
if (b.type == BufferType.SERVER) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (a.name > b.name) {
|
||||
return -1;
|
||||
}
|
||||
if (a.name < b.name) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
export default function BufferList(props) {
|
||||
return html`
|
||||
<ul>
|
||||
${Array.from(props.buffers.values()).sort(compareBuffers).map(buf => html`
|
||||
${Array.from(props.buffers.values()).map((buf) => html`
|
||||
<${BufferItem} key=${buf.name} buffer=${buf} onClick=${() => props.onBufferClick(buf.name)} active=${props.activeBuffer == buf.name}/>
|
||||
`)}
|
||||
</ul>
|
||||
|
Loading…
x
Reference in New Issue
Block a user