@plteam/chat-ui
Version:
CUI Kit is a free and open-source library for creating AI assistant chat interfaces, built with React, Material UI, and TypeScript
18 lines (17 loc) • 662 B
JavaScript
import { ObservableReactValue } from '../utils/observers';
import { arrayPluck } from '../utils/arrayUtils/arrayPluck';
export class ThreadListGroupItem {
data;
threads = new ObservableReactValue([]);
constructor(data) {
this.data = data;
}
checkList = (threads, comparator) => {
const newIds = arrayPluck(threads, 'id').sort().join('-');
const currentIds = arrayPluck(this.threads.value, 'id').sort().join('-');
if (newIds !== currentIds) {
const compare = comparator ?? ((a, b) => b.time - a.time);
this.threads.value = [...threads].sort(compare);
}
};
}