Skip to content

Commit

Permalink
Merge branch 'dev' into empty-scrollbar-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
stavares843 authored Dec 31, 2024
2 parents fae6d97 + acce6b0 commit 9f7bb7b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 19 deletions.
3 changes: 1 addition & 2 deletions src/lib/components/Polling.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
export let rate: number = 5000
let currentInterval = 100
let activeChat = get(Store.state.activeChat)
async function poll() {
// add processes here.
updateTypingIndicators()
Expand All @@ -24,7 +23,7 @@
}
async function updateTypingIndicators() {
UIStore.updateTypingIndicators(activeChat)
UIStore.updateTypingIndicators()
}
onMount(() => {
Expand Down
37 changes: 37 additions & 0 deletions src/lib/components/profile/ProfilePictureMany.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
export let users: User[]
export let size: Size = Size.Medium
export let forceSize: boolean = false
export let typing = false
const dispatch = createEventDispatcher()
Expand Down Expand Up @@ -38,6 +39,9 @@
<ProfilePicture hook="profile-picture-many-single-pic" id={user.key} size={getSize(i)} image={user.profile.photo.image} status={user.profile.status} noIndicator />
{/if}
{/each}
{#if typing}
<div class="typing-indicator"></div>
{/if}
<div class="count">
<Icon icon={Shape.Users} size={Size.Smaller} alt />
<Text hook="profile-picture-many-length" size={Size.Smaller} appearance={Appearance.Alt}>
Expand Down Expand Up @@ -88,5 +92,38 @@
z-index: 1;
}
}
.typing-indicator {
position: absolute;
z-index: 1;
top: 0;
left: 0;
width: 100%;
min-width: 100%;
height: 100%;
min-height: 100%;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
border-top: var(--border-width-more) solid var(--alt-color);
border-right: var(--border-width-more) solid var(--alt-color);
border-bottom: var(--border-width-more) solid var(--alt-color);
border-left: var(--border-width-more) solid var(--color);
transform: translateZ(0);
animation: circle-loader-spin 1s infinite;
@keyframes circle-loader-spin {
0% {
transform: rotate(-70deg);
}
50% {
transform: rotate(170deg);
}
100% {
transform: rotate(-70deg);
}
}
}
}
</style>
26 changes: 10 additions & 16 deletions src/lib/state/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,23 +170,17 @@ class Store {
}, 0)
}

updateTypingIndicators(chat: Chat) {
let update = chat.typing_indicator.size !== 0
chat.typing_indicator.update()
if (update) {
this.state.chats.update(chats => chats.map(c => (c.id === chat.id ? { ...c, typing_indicator: chat.typing_indicator } : c)))

MainStore.state.activeChat.update(c => {
if (c.id === chat.id) {
return {
...c,
typing_indicator: chat.typing_indicator,
}
}
return c
})
chat.typing_indicator.update()
updateTypingIndicators() {
let chats = get(this.state.chats)
let updated = false
for (let chat of chats) {
if (chat.typing_indicator.update()) updated = true
}
if (updated) {
this.state.chats.set(chats)
}
let active = get(MainStore.state.activeChat)
if (active.typing_indicator.update()) MainStore.state.activeChat.set(active)
}

useEmoji(emoji: string) {
Expand Down
3 changes: 2 additions & 1 deletion src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export class TypingIndicator {
* @returns True if something changed
*/
update(): boolean {
if (this.size === 0) return false
let time = new Date()
time.setSeconds(time.getSeconds() - 5)
let it = Object.entries(this.typingIndicator)
Expand All @@ -242,7 +243,7 @@ export class TypingIndicator {
obj[id] = date
return obj
}, {})
this._size = updated.length > 0 ? 1 : 0
this._size = updated.length
return old_len != this._size
}

Expand Down

0 comments on commit 9f7bb7b

Please sign in to comment.