better structure
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import MutedItem from '@lume/app/channel/components/mutedItem';
|
||||
import MuteIcon from '@lume/shared/icons/mute';
|
||||
import MutedItem from '@app/channel/components/mutedItem';
|
||||
|
||||
import MuteIcon from '@icons/mute';
|
||||
|
||||
import { Popover, Transition } from '@headlessui/react';
|
||||
import { Fragment } from 'react';
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import { AvatarUploader } from '@lume/shared/avatarUploader';
|
||||
import CancelIcon from '@lume/shared/icons/cancel';
|
||||
import PlusIcon from '@lume/shared/icons/plus';
|
||||
import { Image } from '@lume/shared/image';
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import { DEFAULT_AVATAR, WRITEONLY_RELAYS } from '@lume/stores/constants';
|
||||
import { dateToUnix } from '@lume/utils/getDate';
|
||||
import { useActiveAccount } from '@lume/utils/hooks/useActiveAccount';
|
||||
import { createChannel } from '@lume/utils/storage';
|
||||
import { AvatarUploader } from '@shared/avatarUploader';
|
||||
import { Image } from '@shared/image';
|
||||
import { RelayContext } from '@shared/relayProvider';
|
||||
|
||||
import CancelIcon from '@icons/cancel';
|
||||
import PlusIcon from '@icons/plus';
|
||||
|
||||
import { DEFAULT_AVATAR, WRITEONLY_RELAYS } from '@stores/constants';
|
||||
|
||||
import { dateToUnix } from '@utils/date';
|
||||
import { useActiveAccount } from '@utils/hooks/useActiveAccount';
|
||||
import { createChannel } from '@utils/storage';
|
||||
|
||||
import { Dialog, Transition } from '@headlessui/react';
|
||||
import { getEventHash, signEvent } from 'nostr-tools';
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useChannelProfile } from '@lume/utils/hooks/useChannelProfile';
|
||||
import { usePageContext } from '@lume/utils/hooks/usePageContext';
|
||||
import { useChannelProfile } from '@app/channel/hooks/useChannelProfile';
|
||||
|
||||
import { usePageContext } from '@utils/hooks/usePageContext';
|
||||
|
||||
import { twMerge } from 'tailwind-merge';
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import ChannelCreateModal from '@lume/app/channel/components/createModal';
|
||||
import ChannelsListItem from '@lume/app/channel/components/item';
|
||||
import { getChannels } from '@lume/utils/storage';
|
||||
import ChannelCreateModal from '@app/channel/components/createModal';
|
||||
import ChannelsListItem from '@app/channel/components/item';
|
||||
|
||||
import { getChannels } from '@utils/storage';
|
||||
|
||||
import useSWR from 'swr';
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import MiniMember from '@lume/app/channel/components/miniMember';
|
||||
import { channelMembersAtom } from '@lume/stores/channel';
|
||||
import MiniMember from '@app/channel/components/miniMember';
|
||||
|
||||
import { channelMembersAtom } from '@stores/channel';
|
||||
|
||||
import { useAtomValue } from 'jotai';
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import ChannelMessageItem from '@lume/app/channel/components/messages/item';
|
||||
import { sortedChannelMessagesAtom } from '@lume/stores/channel';
|
||||
import { hoursAgo } from '@lume/utils/getDate';
|
||||
import ChannelMessageItem from '@app/channel/components/messages/item';
|
||||
|
||||
import { sortedChannelMessagesAtom } from '@stores/channel';
|
||||
|
||||
import { getHourAgo } from '@utils/date';
|
||||
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { useCallback, useRef } from 'react';
|
||||
@@ -39,7 +41,7 @@ export default function ChannelMessageList() {
|
||||
</div>
|
||||
<div className="relative flex justify-center">
|
||||
<div className="inline-flex items-center gap-x-1.5 rounded-full bg-zinc-900 px-3 py-1.5 text-xs font-medium text-zinc-400 shadow-sm ring-1 ring-inset ring-zinc-800">
|
||||
{hoursAgo(24, now.current).toLocaleDateString('en-US', {
|
||||
{getHourAgo(24, now.current).toLocaleDateString('en-US', {
|
||||
weekday: 'long',
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
import UserReply from '@lume/app/channel/components/messages/userReply';
|
||||
import { ImagePicker } from '@lume/shared/form/imagePicker';
|
||||
import CancelIcon from '@lume/shared/icons/cancel';
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import { channelContentAtom, channelReplyAtom } from '@lume/stores/channel';
|
||||
import { WRITEONLY_RELAYS } from '@lume/stores/constants';
|
||||
import { dateToUnix } from '@lume/utils/getDate';
|
||||
import { useActiveAccount } from '@lume/utils/hooks/useActiveAccount';
|
||||
import UserReply from '@app/channel/components/messages/userReply';
|
||||
|
||||
import { ImagePicker } from '@shared/form/imagePicker';
|
||||
import { RelayContext } from '@shared/relayProvider';
|
||||
|
||||
import CancelIcon from '@icons/cancel';
|
||||
|
||||
import { channelContentAtom, channelReplyAtom } from '@stores/channel';
|
||||
import { WRITEONLY_RELAYS } from '@stores/constants';
|
||||
|
||||
import { dateToUnix } from '@utils/date';
|
||||
import { useActiveAccount } from '@utils/hooks/useActiveAccount';
|
||||
|
||||
import { useAtom, useAtomValue } from 'jotai';
|
||||
import { useResetAtom } from 'jotai/utils';
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import CancelIcon from '@lume/shared/icons/cancel';
|
||||
import HideIcon from '@lume/shared/icons/hide';
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import { Tooltip } from '@lume/shared/tooltip';
|
||||
import { channelMessagesAtom } from '@lume/stores/channel';
|
||||
import { WRITEONLY_RELAYS } from '@lume/stores/constants';
|
||||
import { dateToUnix } from '@lume/utils/getDate';
|
||||
import { useActiveAccount } from '@lume/utils/hooks/useActiveAccount';
|
||||
import { RelayContext } from '@shared/relayProvider';
|
||||
import { Tooltip } from '@shared/tooltip';
|
||||
|
||||
import CancelIcon from '@icons/cancel';
|
||||
import HideIcon from '@icons/hide';
|
||||
|
||||
import { channelMessagesAtom } from '@stores/channel';
|
||||
import { WRITEONLY_RELAYS } from '@stores/constants';
|
||||
|
||||
import { dateToUnix } from '@utils/date';
|
||||
import { useActiveAccount } from '@utils/hooks/useActiveAccount';
|
||||
|
||||
import { Dialog, Transition } from '@headlessui/react';
|
||||
import { useAtom } from 'jotai';
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import MessageHideButton from '@lume/app/channel/components/messages/hideButton';
|
||||
import MessageMuteButton from '@lume/app/channel/components/messages/muteButton';
|
||||
import MessageReplyButton from '@lume/app/channel/components/messages/replyButton';
|
||||
import ChannelMessageUser from '@lume/app/channel/components/messages/user';
|
||||
import { noteParser } from '@lume/utils/parser';
|
||||
import MessageHideButton from '@app/channel/components/messages/hideButton';
|
||||
import MessageMuteButton from '@app/channel/components/messages/muteButton';
|
||||
import MessageReplyButton from '@app/channel/components/messages/replyButton';
|
||||
import ChannelMessageUser from '@app/channel/components/messages/user';
|
||||
|
||||
import { noteParser } from '@utils/parser';
|
||||
|
||||
import { useMemo } from 'react';
|
||||
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import CancelIcon from '@lume/shared/icons/cancel';
|
||||
import MuteIcon from '@lume/shared/icons/mute';
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import { Tooltip } from '@lume/shared/tooltip';
|
||||
import { channelMessagesAtom } from '@lume/stores/channel';
|
||||
import { WRITEONLY_RELAYS } from '@lume/stores/constants';
|
||||
import { dateToUnix } from '@lume/utils/getDate';
|
||||
import { useActiveAccount } from '@lume/utils/hooks/useActiveAccount';
|
||||
import { RelayContext } from '@shared/relayProvider';
|
||||
import { Tooltip } from '@shared/tooltip';
|
||||
|
||||
import CancelIcon from '@icons/cancel';
|
||||
import MuteIcon from '@icons/mute';
|
||||
|
||||
import { channelMessagesAtom } from '@stores/channel';
|
||||
import { WRITEONLY_RELAYS } from '@stores/constants';
|
||||
|
||||
import { dateToUnix } from '@utils/date';
|
||||
import { useActiveAccount } from '@utils/hooks/useActiveAccount';
|
||||
|
||||
import { Dialog, Transition } from '@headlessui/react';
|
||||
import { useAtom } from 'jotai';
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import ReplyMessageIcon from '@lume/shared/icons/replyMessage';
|
||||
import { Tooltip } from '@lume/shared/tooltip';
|
||||
import { channelReplyAtom } from '@lume/stores/channel';
|
||||
import { Tooltip } from '@shared/tooltip';
|
||||
|
||||
import ReplyMessageIcon from '@icons/replyMessage';
|
||||
|
||||
import { channelReplyAtom } from '@stores/channel';
|
||||
|
||||
import { useSetAtom } from 'jotai';
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { Image } from '@lume/shared/image';
|
||||
import { DEFAULT_AVATAR, IMGPROXY_URL } from '@lume/stores/constants';
|
||||
import { useProfile } from '@lume/utils/hooks/useProfile';
|
||||
import { shortenKey } from '@lume/utils/shortenKey';
|
||||
import { Image } from '@shared/image';
|
||||
|
||||
import { DEFAULT_AVATAR, IMGPROXY_URL } from '@stores/constants';
|
||||
|
||||
import { useProfile } from '@utils/hooks/useProfile';
|
||||
import { shortenKey } from '@utils/shortenKey';
|
||||
|
||||
import dayjs from 'dayjs';
|
||||
import relativeTime from 'dayjs/plugin/relativeTime';
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { Image } from '@lume/shared/image';
|
||||
import { DEFAULT_AVATAR, IMGPROXY_URL } from '@lume/stores/constants';
|
||||
import { useProfile } from '@lume/utils/hooks/useProfile';
|
||||
import { shortenKey } from '@lume/utils/shortenKey';
|
||||
import { Image } from '@shared/image';
|
||||
|
||||
import { DEFAULT_AVATAR, IMGPROXY_URL } from '@stores/constants';
|
||||
|
||||
import { useProfile } from '@utils/hooks/useProfile';
|
||||
import { shortenKey } from '@utils/shortenKey';
|
||||
|
||||
export default function UserReply({ pubkey }: { pubkey: string }) {
|
||||
const { user, isError, isLoading } = useProfile(pubkey);
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import CopyIcon from '@lume/shared/icons/copy';
|
||||
import { Image } from '@lume/shared/image';
|
||||
import { DEFAULT_AVATAR } from '@lume/stores/constants';
|
||||
import { useChannelProfile } from '@lume/utils/hooks/useChannelProfile';
|
||||
import { useChannelProfile } from '@app/channel/hooks/useChannelProfile';
|
||||
|
||||
import { Image } from '@shared/image';
|
||||
|
||||
import CopyIcon from '@icons/copy';
|
||||
|
||||
import { DEFAULT_AVATAR } from '@stores/constants';
|
||||
|
||||
import { nip19 } from 'nostr-tools';
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { Image } from '@lume/shared/image';
|
||||
import { DEFAULT_AVATAR } from '@lume/stores/constants';
|
||||
import { useProfile } from '@lume/utils/hooks/useProfile';
|
||||
import { Image } from '@shared/image';
|
||||
|
||||
import { DEFAULT_AVATAR } from '@stores/constants';
|
||||
|
||||
import { useProfile } from '@utils/hooks/useProfile';
|
||||
|
||||
export default function MiniMember({ pubkey }: { pubkey: string }) {
|
||||
const { user, isError, isLoading } = useProfile(pubkey);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { Image } from '@lume/shared/image';
|
||||
import { DEFAULT_AVATAR } from '@lume/stores/constants';
|
||||
import { useProfile } from '@lume/utils/hooks/useProfile';
|
||||
import { shortenKey } from '@lume/utils/shortenKey';
|
||||
import { Image } from '@shared/image';
|
||||
|
||||
import { DEFAULT_AVATAR } from '@stores/constants';
|
||||
|
||||
import { useProfile } from '@utils/hooks/useProfile';
|
||||
import { shortenKey } from '@utils/shortenKey';
|
||||
|
||||
import { useState } from 'react';
|
||||
|
||||
@@ -10,7 +12,7 @@ export default function MutedItem({ data }: { data: any }) {
|
||||
const [status, setStatus] = useState(data.status);
|
||||
|
||||
const unmute = async () => {
|
||||
const { updateItemInBlacklist } = await import('@lume/utils/storage');
|
||||
const { updateItemInBlacklist } = await import('@utils/storage');
|
||||
const res = await updateItemInBlacklist(data.content, 0);
|
||||
if (res) {
|
||||
setStatus(0);
|
||||
@@ -18,7 +20,7 @@ export default function MutedItem({ data }: { data: any }) {
|
||||
};
|
||||
|
||||
const mute = async () => {
|
||||
const { updateItemInBlacklist } = await import('@lume/utils/storage');
|
||||
const { updateItemInBlacklist } = await import('@utils/storage');
|
||||
const res = await updateItemInBlacklist(data.content, 1);
|
||||
if (res) {
|
||||
setStatus(1);
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import { AvatarUploader } from '@lume/shared/avatarUploader';
|
||||
import CancelIcon from '@lume/shared/icons/cancel';
|
||||
import EditIcon from '@lume/shared/icons/edit';
|
||||
import { Image } from '@lume/shared/image';
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import { DEFAULT_AVATAR, WRITEONLY_RELAYS } from '@lume/stores/constants';
|
||||
import { dateToUnix } from '@lume/utils/getDate';
|
||||
import { useActiveAccount } from '@lume/utils/hooks/useActiveAccount';
|
||||
import { getChannel, updateChannelMetadata } from '@lume/utils/storage';
|
||||
import { AvatarUploader } from '@shared/avatarUploader';
|
||||
import { Image } from '@shared/image';
|
||||
import { RelayContext } from '@shared/relayProvider';
|
||||
|
||||
import CancelIcon from '@icons/cancel';
|
||||
import EditIcon from '@icons/edit';
|
||||
|
||||
import { DEFAULT_AVATAR, WRITEONLY_RELAYS } from '@stores/constants';
|
||||
|
||||
import { dateToUnix } from '@utils/date';
|
||||
import { useActiveAccount } from '@utils/hooks/useActiveAccount';
|
||||
import { getChannel, updateChannelMetadata } from '@utils/storage';
|
||||
|
||||
import { Dialog, Transition } from '@headlessui/react';
|
||||
import { getEventHash, signEvent } from 'nostr-tools';
|
||||
|
||||
58
src/app/channel/hooks/useChannelProfile.tsx
Normal file
58
src/app/channel/hooks/useChannelProfile.tsx
Normal file
@@ -0,0 +1,58 @@
|
||||
import { RelayContext } from '@shared/relayProvider';
|
||||
|
||||
import { READONLY_RELAYS } from '@stores/constants';
|
||||
|
||||
import { getChannel } from '@utils/storage';
|
||||
|
||||
import { useContext } from 'react';
|
||||
import useSWR from 'swr';
|
||||
import useSWRSubscription from 'swr/subscription';
|
||||
|
||||
const fetcher = async ([, id]) => {
|
||||
const result = await getChannel(id);
|
||||
if (result) {
|
||||
return JSON.parse(result.metadata);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export function useChannelProfile(id: string, channelPubkey: string) {
|
||||
const pool: any = useContext(RelayContext);
|
||||
|
||||
const { data: cache, isLoading } = useSWR(['channel-cache-profile', id], fetcher);
|
||||
const { data, error } = useSWRSubscription(
|
||||
!isLoading && cache ? ['channel-profile', id] : null,
|
||||
([, key], { next }) => {
|
||||
// subscribe to channel
|
||||
const unsubscribe = pool.subscribe(
|
||||
[
|
||||
{
|
||||
'#e': [key],
|
||||
authors: [channelPubkey],
|
||||
kinds: [41],
|
||||
},
|
||||
],
|
||||
READONLY_RELAYS,
|
||||
(event: { content: string }) => {
|
||||
next(null, JSON.parse(event.content));
|
||||
},
|
||||
undefined,
|
||||
undefined,
|
||||
{
|
||||
unsubscribeOnEose: true,
|
||||
}
|
||||
);
|
||||
|
||||
return () => {
|
||||
unsubscribe();
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
if (!data || error) {
|
||||
return cache;
|
||||
} else {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import AppHeader from '@lume/shared/appHeader';
|
||||
import MultiAccounts from '@lume/shared/multiAccounts';
|
||||
import Navigation from '@lume/shared/navigation';
|
||||
import AppHeader from '@shared/appHeader';
|
||||
import MultiAccounts from '@shared/multiAccounts';
|
||||
import Navigation from '@shared/navigation';
|
||||
|
||||
export function LayoutChannel({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
import ChannelBlackList from '@lume/app/channel/components/blacklist';
|
||||
import ChannelMembers from '@lume/app/channel/components/members';
|
||||
import ChannelMessageForm from '@lume/app/channel/components/messages/form';
|
||||
import ChannelMetadata from '@lume/app/channel/components/metadata';
|
||||
import ChannelUpdateModal from '@lume/app/channel/components/updateModal';
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import { channelMessagesAtom, channelReplyAtom } from '@lume/stores/channel';
|
||||
import { READONLY_RELAYS } from '@lume/stores/constants';
|
||||
import { dateToUnix, hoursAgo } from '@lume/utils/getDate';
|
||||
import { useActiveAccount } from '@lume/utils/hooks/useActiveAccount';
|
||||
import { usePageContext } from '@lume/utils/hooks/usePageContext';
|
||||
import { getActiveBlacklist, getBlacklist } from '@lume/utils/storage';
|
||||
import { arrayObjToPureArr } from '@lume/utils/transform';
|
||||
import ChannelBlackList from '@app/channel/components/blacklist';
|
||||
import ChannelMembers from '@app/channel/components/members';
|
||||
import ChannelMessageForm from '@app/channel/components/messages/form';
|
||||
import ChannelMetadata from '@app/channel/components/metadata';
|
||||
import ChannelUpdateModal from '@app/channel/components/updateModal';
|
||||
|
||||
import { RelayContext } from '@shared/relayProvider';
|
||||
|
||||
import { channelMessagesAtom, channelReplyAtom } from '@stores/channel';
|
||||
import { READONLY_RELAYS } from '@stores/constants';
|
||||
|
||||
import { dateToUnix, getHourAgo } from '@utils/date';
|
||||
import { useActiveAccount } from '@utils/hooks/useActiveAccount';
|
||||
import { usePageContext } from '@utils/hooks/usePageContext';
|
||||
import { getActiveBlacklist, getBlacklist } from '@utils/storage';
|
||||
import { arrayObjToPureArr } from '@utils/transform';
|
||||
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { useResetAtom } from 'jotai/utils';
|
||||
@@ -30,7 +33,7 @@ const fetchHided = async ([, id]) => {
|
||||
return array;
|
||||
};
|
||||
|
||||
const ChannelMessageList = lazy(() => import('@lume/app/channel/components/messageList'));
|
||||
const ChannelMessageList = lazy(() => import('@app/channel/components/messageList'));
|
||||
|
||||
export function Page() {
|
||||
const pool: any = useContext(RelayContext);
|
||||
@@ -57,7 +60,7 @@ export function Page() {
|
||||
{
|
||||
'#e': [key],
|
||||
kinds: [42],
|
||||
since: dateToUnix(hoursAgo(24, now.current)),
|
||||
since: dateToUnix(getHourAgo(24, now.current)),
|
||||
limit: 20,
|
||||
},
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user