Skip to content
View lessons Login

Launch sale! Get 30% OFF expires in 126:46:23

3d cartoon hands holding a phone

Unlock full course by purchasing a membership

Styling and Refinements

Styling and Refinements

We just have a few things to finish up in this lesson to polish off the application, these are:

  • Supplying the active user as an input to the message list component so we can provide different styles for the user’s own messages
  • Automatic scroll to bottom
  • General styling

Let’s get into it!

Active User Input

If you create a second account and add some more messages to the chat, you will notice that all of the messages have the same styling. Typically in a chat application you would have the users own messages appear on a different side of the screen.

activeUser = input.required<AuthUser>();
@if (activeUser(); as activeUser) {
<ion-avatar
class="animate-in-primary"
[slot]="message.author === activeUser.email ? 'start' : 'end'"
>
<img
src="https://api.dicebear.com/9.x/bottts/svg?seed={{
message.author.split('@')[0]
}}"
/>
</ion-avatar>
}

Now we are using the activeUser value to determine the slot for the avatar.

<app-message-list
[messages]="messageService.messages()"
[activeUser]="authService.user()"
/>

Add Automatic Scrolling

If we add a message, and there are already enough messages to fill the screen, we can’t actually see it until we manually scroll down. Also, if we log into the application we will be seeing the oldest messages at the top of the page until we manually scroll to the bottom.

To fix this, we will use one of the methods available on ion-content components.

The idea is that we will call the scrollTo method on the scrollContainer whenever our message list changes. This will cause the container to scroll to the bottom.

scrollContainer = viewChild.required(IonContent);
constructor() {
addIcons({ logOutOutline });
effect(() => {
if (this.messageService.messages().length && this.scrollContainer()) {
this.scrollContainer().scrollToBottom(200);
}
});
effect(() => {
if (!this.authService.user()) {
this.router.navigate(['auth', 'login']);
}
});
}

General Styling

Now we have just a few final style configurations to make.

ion-content {
--ion-background-color: var(--ion-color-primary);
}
ion-title img {
max-height: 39px;
margin-top: 9px;
filter: drop-shadow(2px 4px 6px var(--ion-color-primary-shade));
}
EXTENDED EXTENDED

Thanks for checking out the preview of this lesson!

You do not have the appropriate membership to view the full lesson. If you would like full access to this module you can view membership options (or log in if you are already have an appropriate membership).