Skip to content

Commit

Permalink
🍿 Add icons, WeakMap usage
Browse files Browse the repository at this point in the history
  • Loading branch information
RuzikNF committed Jul 23, 2020
1 parent 3df192e commit 3f680ec
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
Binary file added assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/icons/home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/components/DMPanel/DMPanelUsersList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ViewOptions } from '../../views/ViewOptions';
export class DMPanelUsersList extends QScrollArea {
root = new QWidget();
widgets = new QBoxLayout(Direction.TopToBottom);
channels = new Map<DMChannel, UserButton>();
channels = new WeakMap<DMChannel, UserButton>();
active?: UserButton;

constructor() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/GuildPanel/ChannelButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class ChannelButton extends DChannelButton {
private chlabel = new QLabel();
private pound = new QPixmap(join(__dirname, './assets/icons/pound.png'));

constructor(parent: any) {
constructor(parent?: any) {
super(parent);
this.initComponent();
this.addEventListener(WidgetEventTypes.HoverEnter, () => this.setHovered(true));
Expand Down
17 changes: 9 additions & 8 deletions src/components/GuildPanel/ChannelsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class ChannelsList extends QScrollArea {
guild?: Guild;
root = new QWidget();
widgets = new QBoxLayout(Direction.TopToBottom);
channels = new Map<Channel, ChannelButton | QLabel>();
channels = new WeakMap<Channel, ChannelButton/* | QLabel*/>();
active?: ChannelButton;

constructor() {
Expand Down Expand Up @@ -63,17 +63,18 @@ export class ChannelsList extends QScrollArea {
.filter(c => ['text'/*, 'category'*/].includes(c.type))
.filter(c => (c.permissionsFor(client.user) as Permissions).has('VIEW_CHANNEL'))
.sort((a, b) => a.position - b.position)
.array() as (TextChannel | CategoryChannel)[])
if(channels.every(c => this.channels.has(c))) {
.array() as (TextChannel/* | CategoryChannel*/)[])
/* if(channels.every(c => this.channels.has(c))) {
channels.forEach((channel, i) => {
const widget = this.channels.get(channel) as QWidget;
console.log('cache', channel, widget)
this.widgets.insertWidget(i, widget)
});
return;
}
} */
channels.forEach((channel, i) => {
if(channel.type === 'text') {
const btn = new ChannelButton(this);
// if(channel.type === 'text') {
const btn = new ChannelButton();
btn.loadChannel(channel as TextChannel);
btn.setMinimumSize(0, 32);
btn.setMaximumSize(MAX_QSIZE, 32);
Expand All @@ -83,14 +84,14 @@ export class ChannelsList extends QScrollArea {
this.channels.set(channel, btn);
this.widgets.insertWidget(i, btn);
return btn;
} else {
/* } else {
const label = new QLabel(this);
label.setText(channel.name);
label.setObjectName('CategoryHeader');
this.channels.set(channel, label);
this.widgets.insertWidget(i, label);
return label;
}
}*/
});
}
}
4 changes: 1 addition & 3 deletions src/components/GuildsList/GuildsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class GuildsList extends QScrollArea {
layout = new QBoxLayout(Direction.TopToBottom);
private container = new QWidget();
private mpBtn = new QPushButton();
private guilds = new Map<Guild, QLabel>();
private guilds = new WeakMap<Guild, QLabel>();
private active?: QPushButton | QLabel;

constructor() {
Expand Down Expand Up @@ -64,7 +64,6 @@ export class GuildsList extends QScrollArea {
this.mpBtn.setFixedSize(48, 48 + 10);
this.mpBtn.setCursor(new QCursor(CursorShape.PointingHandCursor));
this.mpBtn.setProperty('toolTip', 'Direct Messages');
this.mpBtn.setProperty('active', 'true');
this.mpBtn.addEventListener('clicked', () => app.emit('switchView', 'dm'));

this.container.layout?.addWidget(this.mpBtn);
Expand Down Expand Up @@ -114,7 +113,6 @@ export class GuildsList extends QScrollArea {
}
async loadGuilds() {
const { client } = app;
this.guilds.clear();
this.initContainer();

const guilds = client.guilds
Expand Down
2 changes: 1 addition & 1 deletion src/components/MessagesPanel/MessagesPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class MessagesPanel extends QScrollArea {
private channel?: Channel;
private rootControls = new QBoxLayout(Direction.BottomToTop);
private root = new QWidget();
private cache = new Map<Channel, Message[]>();
private cache = new WeakMap<Channel, Message[]>();
private cancelToken?: CancelToken;

constructor() {
Expand Down
3 changes: 2 additions & 1 deletion src/windows/RootWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class RootWindow extends QMainWindow {
this.setStyleSheet(stylesheet);
}
protected loadIcon() {
const icon = new QIcon(path.resolve(__dirname, "./assets/icons/logo.png"));
const icon = new QIcon(path.resolve(__dirname, "./assets/icon.png"));
this.setWindowIcon(icon);
}

Expand All @@ -65,6 +65,7 @@ export class RootWindow extends QMainWindow {
try {
await app.client.login(account.token || 's');
this.setWindowTitle(`Discord-Qt • ${app.client.user.username}#${app.client.user.discriminator}`);
app.emit('switchView', 'dm');
return true;
} catch(e) {
console.log(e);
Expand Down

0 comments on commit 3f680ec

Please sign in to comment.