added active link to chat/channel

This commit is contained in:
Ren Amamiya 2023-04-17 09:02:17 +07:00
parent 15968db4a6
commit 1924310e41
2 changed files with 10 additions and 20 deletions

View File

@ -1,20 +1,15 @@
import { ActiveLink } from '@components/activeLink';
import { ImageWithFallback } from '@components/imageWithFallback';
import { DEFAULT_AVATAR } from '@stores/constants';
import { useRouter } from 'next/navigation';
export const ChannelListItem = ({ data }: { data: any }) => {
const router = useRouter();
const channel = JSON.parse(data.content);
const openChannel = (id: string) => {
router.push(`/channels/${id}`);
};
return (
<div
onClick={() => openChannel(data.eventId)}
<ActiveLink
href={`/channels/${data.eventId}`}
activeClassName="dark:bg-zinc-900 dark:text-zinc-100 hover:dark:bg-zinc-800"
className="inline-flex items-center gap-2 rounded-md px-2.5 py-1.5 hover:bg-zinc-900"
>
<div className="relative h-5 w-5 shrink-0 overflow-hidden rounded">
@ -28,6 +23,6 @@ export const ChannelListItem = ({ data }: { data: any }) => {
<div>
<h5 className="truncate text-sm font-medium text-zinc-400">{channel.name}</h5>
</div>
</div>
</ActiveLink>
);
};

View File

@ -1,3 +1,4 @@
import { ActiveLink } from '@components/activeLink';
import { ImageWithFallback } from '@components/imageWithFallback';
import { DEFAULT_AVATAR } from '@stores/constants';
@ -5,19 +6,13 @@ import { DEFAULT_AVATAR } from '@stores/constants';
import { useProfileMetadata } from '@utils/hooks/useProfileMetadata';
import { truncate } from '@utils/truncate';
import { useRouter } from 'next/navigation';
export const ChatListItem = ({ pubkey }: { pubkey: string }) => {
const router = useRouter();
const profile = useProfileMetadata(pubkey);
const openChat = () => {
router.push(`/chats/${pubkey}`);
};
return (
<div
onClick={() => openChat()}
<ActiveLink
href={`/chats/${pubkey}`}
activeClassName="dark:bg-zinc-900 dark:text-zinc-100 hover:dark:bg-zinc-800"
className="inline-flex items-center gap-2 rounded-md px-2.5 py-1.5 hover:bg-zinc-900"
>
<div className="relative h-5 w-5 shrink overflow-hidden rounded">
@ -33,6 +28,6 @@ export const ChatListItem = ({ pubkey }: { pubkey: string }) => {
{profile?.display_name || profile?.name || truncate(pubkey, 16, ' .... ')}
</h5>
</div>
</div>
</ActiveLink>
);
};