Browse Source

Fix editing folders

master
morethanwords 4 years ago
parent
commit
dde8d61b0e
  1. 36
      src/components/sidebarLeft/tabs/chatFolders.ts

36
src/components/sidebarLeft/tabs/chatFolders.ts

@ -32,10 +32,10 @@ export default class AppChatFoldersTab extends SliderSuperTab {
private stickerContainer: HTMLElement; private stickerContainer: HTMLElement;
private animation: RLottiePlayer; private animation: RLottiePlayer;
private filtersRendered: {[filterId: number]: HTMLElement} = {}; private filtersRendered: {[filterId: number]: Row} = {};
private loadAnimationPromise: Promise<void>; private loadAnimationPromise: Promise<void>;
private renderFolder(dialogFilter: DialogFilterSuggested | DialogFilter | MyDialogFilter, container?: HTMLElement, div?: HTMLElement) { private renderFolder(dialogFilter: DialogFilterSuggested | DialogFilter | MyDialogFilter, container?: HTMLElement, row?: Row) {
let filter: DialogFilter | MyDialogFilter; let filter: DialogFilter | MyDialogFilter;
let description = ''; let description = '';
let d: HTMLElement[] = []; let d: HTMLElement[] = [];
@ -58,7 +58,10 @@ export default class AppChatFoldersTab extends SliderSuperTab {
else if(pFlags.groups) k = 'FilterAllGroups'; else if(pFlags.groups) k = 'FilterAllGroups';
else if(pFlags.broadcasts) k = 'FilterAllChannels'; else if(pFlags.broadcasts) k = 'FilterAllChannels';
else if(pFlags.bots) k = 'FilterAllBots'; else if(pFlags.bots) k = 'FilterAllBots';
if(k) {
d.push(i18n(k)); d.push(i18n(k));
}
} else { } else {
const folder = appMessagesManager.dialogsStorage.getFolder(filter.id); const folder = appMessagesManager.dialogsStorage.getFolder(filter.id);
let chats = 0, channels = 0, groups = 0; let chats = 0, channels = 0, groups = 0;
@ -74,34 +77,39 @@ export default class AppChatFoldersTab extends SliderSuperTab {
} }
} }
if(!div) { let div: HTMLElement;
const row = new Row({ if(!row) {
row = new Row({
title: RichTextProcessor.wrapEmojiText(filter.title), title: RichTextProcessor.wrapEmojiText(filter.title),
subtitle: description, subtitle: description,
clickable: true clickable: true
}); });
if(d.length) { if(d.length) {
const arr = join(d); join(d).forEach(el => {
arr.forEach(el => {
row.subtitle.append(el); row.subtitle.append(el);
}); });
} }
div = row.container;
if(dialogFilter._ === 'dialogFilter') { if(dialogFilter._ === 'dialogFilter') {
const filterId = filter.id; const filterId = filter.id;
if(!this.filtersRendered.hasOwnProperty(filter.id)) { if(!this.filtersRendered.hasOwnProperty(filter.id)) {
attachClickEvent(div, () => { attachClickEvent(row.container, () => {
new AppEditFolderTab(this.slider).open(appMessagesManager.filtersStorage.filters[filterId]); new AppEditFolderTab(this.slider).open(appMessagesManager.filtersStorage.filters[filterId]);
}, {listenerSetter: this.listenerSetter}); }, {listenerSetter: this.listenerSetter});
} }
this.filtersRendered[filter.id] = div; this.filtersRendered[filter.id] = row;
} }
} else {
row.subtitle.textContent = '';
join(d).forEach(el => {
row.subtitle.append(el);
});
} }
div = row.container;
if((filter as MyDialogFilter).hasOwnProperty('orderIndex')) { if((filter as MyDialogFilter).hasOwnProperty('orderIndex')) {
// ! header will be at 0 index // ! header will be at 0 index
positionElementByIndex(div, div.parentElement || container, (filter as MyDialogFilter).orderIndex); positionElementByIndex(div, div.parentElement || container, (filter as MyDialogFilter).orderIndex);
@ -183,8 +191,8 @@ export default class AppChatFoldersTab extends SliderSuperTab {
} */ } */
this.getSuggestedFilters(); this.getSuggestedFilters();
this.filtersRendered[filter.id].remove(); this.filtersRendered[filter.id].container.remove();
delete this.filtersRendered[filter.id] delete this.filtersRendered[filter.id];
} }
onFiltersContainerUpdate(); onFiltersContainerUpdate();
@ -193,8 +201,8 @@ export default class AppChatFoldersTab extends SliderSuperTab {
this.listenerSetter.add(rootScope, 'filter_order', (e: BroadcastEvents['filter_order']) => { this.listenerSetter.add(rootScope, 'filter_order', (e: BroadcastEvents['filter_order']) => {
const order = e; const order = e;
order.forEach((filterId, idx) => { order.forEach((filterId, idx) => {
const div = this.filtersRendered[filterId]; const container = this.filtersRendered[filterId].container;
positionElementByIndex(div, div.parentElement, idx + 1); // ! + 1 due to header positionElementByIndex(container, container.parentElement, idx + 1); // ! + 1 due to header
}); });
}); });

Loading…
Cancel
Save