Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigran-Harutyunyan committed Feb 15, 2024
1 parent e828a53 commit be39507
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 20 deletions.
6 changes: 6 additions & 0 deletions components/ActiveStatus.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script setup lang="ts">
import { useActiveChannel } from "@/composables/useActiveChannel";
const { pusherClient } = useNuxtApp();
useActiveChannel(pusherClient);
</script>
<template></template>
2 changes: 1 addition & 1 deletion components/conversations/ConversationList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ onUnmounted(() => {
)
"
>
<div class="px-5">
<div class="px-5 space-y-1">
<div class="flex justify-between mb-4 pt-4">
<div class="text-2xl font-bold text-neutral-800">Messages</div>
<slot />
Expand Down
2 changes: 1 addition & 1 deletion components/users/UsersList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { items } = defineProps<UserListProps>();
<aside
class="fixed inset-y-0 pb-20 lg:pb-0 lg:left-20 lg:w-80 lg:block overflow-y-auto border-r border-gray-200 block w-full left-0"
>
<div class="px-5">
<div class="px-5 space-y-1">
<div class="flex-col">
<div class="text-2xl font-bold text-neutral-800 py-4">People</div>
</div>
Expand Down
11 changes: 6 additions & 5 deletions composables/useActiveChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,26 @@ export const useActiveChannel = (pusherClient) => {
const activeChannel = ref<Channel | null>(null);

onMounted(() => {
let channel = activeChannel;

if (!channel.value) {
let channel = activeChannel.value;

if (!channel) {
channel = pusherClient.subscribe('presence-messenger');
activeChannel.value = channel;
}

channel.bind("pusher:subscription_succeeded", (members: Members) => {
channel?.bind("pusher:subscription_succeeded", (members: Members) => {
const initialMembers: string[] = [];

members.each((member: Record<string, any>) => initialMembers.push(member.id));
set(initialMembers);
});

channel.bind("pusher:member_added", (member: Record<string, any>) => {
channel?.bind("pusher:member_added", (member: Record<string, any>) => {
add(member.id)
});

channel.bind("pusher:member_removed", (member: Record<string, any>) => {
channel?.bind("pusher:member_removed", (member: Record<string, any>) => {
remove(member.id);
});
})
Expand Down
3 changes: 2 additions & 1 deletion layouts/conversations.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const { data: users } = useLazyAsyncData("users", () => $fetch("/api/users"), {
</script>

<template>
<ActiveStatus />
<GroupChatModal
v-if="users"
:users="users"
Expand All @@ -44,7 +45,7 @@ const { data: users } = useLazyAsyncData("users", () => $fetch("/api/users"), {

<div
:class="clsx('lg:pl-80 h-full lg:block', isOpen ? 'block' : 'hidden')"
v-show="!pending"
v-if="!pending"
>
<slot />
</div>
Expand Down
1 change: 1 addition & 0 deletions layouts/users.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { data: users } = useLazyAsyncData("users", () => $fetch("/api/users"), {
</script>

<template>
<ActiveStatus />
<Sidebar>
<UsersList :items="users" />
<div :class="clsx('lg:pl-80 h-full lg:block', isOpen ? 'block' : 'hidden')">
Expand Down
6 changes: 0 additions & 6 deletions pages/conversations/index.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
<script setup lang="ts">
import EmptyState from "@/components/EmptyState.vue";
import { useActiveChannel } from "@/composables/useActiveChannel";
definePageMeta({ middleware: "auth", layout: "conversations" });
useHead({
title: "Conversations | Messenger",
});
const { pusherClient } = useNuxtApp();
useActiveChannel(pusherClient);
</script>

<template>
Expand Down
6 changes: 0 additions & 6 deletions pages/users/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
import EmptyState from "@/components/EmptyState.vue";
definePageMeta({ middleware: "auth", layout: "users" });
import { useActiveChannel } from "@/composables/useActiveChannel";
const { pusherClient } = useNuxtApp();
useActiveChannel(pusherClient);
useHead({
title: "Users | Messenger",
});
Expand Down

0 comments on commit be39507

Please sign in to comment.