mirror of
https://github.com/luminous-devs/lume.git
synced 2024-09-18 11:13:30 +00:00
convert const function to function
This commit is contained in:
parent
ae5ff0c48f
commit
1a30c10806
11
.prettierrc
11
.prettierrc
@ -8,7 +8,16 @@
|
|||||||
"endOfLine": "lf",
|
"endOfLine": "lf",
|
||||||
"bracketSpacing": true,
|
"bracketSpacing": true,
|
||||||
"bracketSameLine": false,
|
"bracketSameLine": false,
|
||||||
"importOrder": ["^@lume/(.*)$", "<THIRD_PARTY_MODULES>", "^[./]"],
|
"importOrder": [
|
||||||
|
"^@lume/(.*)$",
|
||||||
|
"^@app/(.*)$",
|
||||||
|
"^@shared/(.*)$",
|
||||||
|
"^@icons/(.*)$",
|
||||||
|
"^@stores/(.*)$",
|
||||||
|
"^@utils/(.*)$",
|
||||||
|
"<THIRD_PARTY_MODULES>",
|
||||||
|
"^[./]"
|
||||||
|
],
|
||||||
"importOrderSeparation": true,
|
"importOrderSeparation": true,
|
||||||
"importOrderSortSpecifiers": true,
|
"importOrderSortSpecifiers": true,
|
||||||
"plugins": ["@trivago/prettier-plugin-sort-imports", "prettier-plugin-tailwindcss"],
|
"plugins": ["@trivago/prettier-plugin-sort-imports", "prettier-plugin-tailwindcss"],
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import CancelIcon from '@lume/shared/icons/cancel';
|
import CancelIcon from '@lume/shared/icons/cancel';
|
||||||
import HideIcon from '@lume/shared/icons/hide';
|
import HideIcon from '@lume/shared/icons/hide';
|
||||||
import { RelayContext } from '@lume/shared/relayProvider';
|
import { RelayContext } from '@lume/shared/relayProvider';
|
||||||
import Tooltip from '@lume/shared/tooltip';
|
import { Tooltip } from '@lume/shared/tooltip';
|
||||||
import { channelMessagesAtom } from '@lume/stores/channel';
|
import { channelMessagesAtom } from '@lume/stores/channel';
|
||||||
import { WRITEONLY_RELAYS } from '@lume/stores/constants';
|
import { WRITEONLY_RELAYS } from '@lume/stores/constants';
|
||||||
import { dateToUnix } from '@lume/utils/getDate';
|
import { dateToUnix } from '@lume/utils/getDate';
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import CancelIcon from '@lume/shared/icons/cancel';
|
import CancelIcon from '@lume/shared/icons/cancel';
|
||||||
import MuteIcon from '@lume/shared/icons/mute';
|
import MuteIcon from '@lume/shared/icons/mute';
|
||||||
import { RelayContext } from '@lume/shared/relayProvider';
|
import { RelayContext } from '@lume/shared/relayProvider';
|
||||||
import Tooltip from '@lume/shared/tooltip';
|
import { Tooltip } from '@lume/shared/tooltip';
|
||||||
import { channelMessagesAtom } from '@lume/stores/channel';
|
import { channelMessagesAtom } from '@lume/stores/channel';
|
||||||
import { WRITEONLY_RELAYS } from '@lume/stores/constants';
|
import { WRITEONLY_RELAYS } from '@lume/stores/constants';
|
||||||
import { dateToUnix } from '@lume/utils/getDate';
|
import { dateToUnix } from '@lume/utils/getDate';
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import ReplyMessageIcon from '@lume/shared/icons/replyMessage';
|
import ReplyMessageIcon from '@lume/shared/icons/replyMessage';
|
||||||
import Tooltip from '@lume/shared/tooltip';
|
import { Tooltip } from '@lume/shared/tooltip';
|
||||||
import { channelReplyAtom } from '@lume/stores/channel';
|
import { channelReplyAtom } from '@lume/stores/channel';
|
||||||
|
|
||||||
import { useSetAtom } from 'jotai';
|
import { useSetAtom } from 'jotai';
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { CreateViewModal } from '@lume/app/daily/components/views/createModal';
|
import { CreateViewModal } from '@lume/app/daily/components/views/createModal';
|
||||||
|
|
||||||
export const Header = () => {
|
export function Header() {
|
||||||
return (
|
return (
|
||||||
<div className="flex w-full gap-4">
|
<div className="flex w-full gap-4">
|
||||||
<button className="from-zinc-90 inline-flex h-11 items-center overflow-hidden border-b border-fuchsia-500 hover:bg-zinc-900">
|
<button className="from-zinc-90 inline-flex h-11 items-center overflow-hidden border-b border-fuchsia-500 hover:bg-zinc-900">
|
||||||
@ -42,4 +42,4 @@ export const Header = () => {
|
|||||||
<CreateViewModal />
|
<CreateViewModal />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
@ -1,16 +1,10 @@
|
|||||||
import CancelIcon from '@lume/shared/icons/cancel';
|
import CancelIcon from '@lume/shared/icons/cancel';
|
||||||
import PlusIcon from '@lume/shared/icons/plus';
|
import PlusIcon from '@lume/shared/icons/plus';
|
||||||
|
|
||||||
//import { getNoteAuthors } from '@lume/utils/storage';
|
|
||||||
import { Dialog, Transition } from '@headlessui/react';
|
import { Dialog, Transition } from '@headlessui/react';
|
||||||
import { Fragment, useState } from 'react';
|
import { Fragment, useState } from 'react';
|
||||||
|
|
||||||
//import useSWR from 'swr';
|
export function CreateViewModal() {
|
||||||
|
|
||||||
//const fetcher = () => getNoteAuthors();
|
|
||||||
|
|
||||||
export const CreateViewModal = () => {
|
|
||||||
//const { data, error }: any = useSWR('authors', fetcher);
|
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
|
||||||
const closeModal = () => {
|
const closeModal = () => {
|
||||||
@ -89,4 +83,4 @@ export const CreateViewModal = () => {
|
|||||||
</Transition>
|
</Transition>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
@ -9,7 +9,7 @@ import { isTagsIncludeID } from '@lume/utils/transform';
|
|||||||
|
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
|
|
||||||
export const NoteBase = ({ event }: { event: any }) => {
|
export function NoteBase({ event }: { event: any }) {
|
||||||
const content = useMemo(() => noteParser(event), [event]);
|
const content = useMemo(() => noteParser(event), [event]);
|
||||||
const checkParentID = isTagsIncludeID(event.parent_id, event.tags);
|
const checkParentID = isTagsIncludeID(event.parent_id, event.tags);
|
||||||
|
|
||||||
@ -34,4 +34,4 @@ export const NoteBase = ({ event }: { event: any }) => {
|
|||||||
</div>
|
</div>
|
||||||
</NoteWrapper>
|
</NoteWrapper>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
@ -6,7 +6,7 @@ import VideoPreview from '@lume/app/note/components/preview/video';
|
|||||||
import ReactMarkdown from 'react-markdown';
|
import ReactMarkdown from 'react-markdown';
|
||||||
import remarkGfm from 'remark-gfm';
|
import remarkGfm from 'remark-gfm';
|
||||||
|
|
||||||
export const Kind1 = ({ content }: { content: any }) => {
|
export function Kind1({ content }: { content: any }) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ReactMarkdown
|
<ReactMarkdown
|
||||||
@ -28,4 +28,4 @@ export const Kind1 = ({ content }: { content: any }) => {
|
|||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
@ -4,7 +4,7 @@ function isImage(url: string) {
|
|||||||
return /\.(jpg|jpeg|gif|png|webp|avif)$/.test(url);
|
return /\.(jpg|jpeg|gif|png|webp|avif)$/.test(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Kind1063 = ({ metadata }: { metadata: string[] }) => {
|
export function Kind1063({ metadata }: { metadata: string[] }) {
|
||||||
const url = metadata[0][1];
|
const url = metadata[0][1];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -12,4 +12,4 @@ export const Kind1063 = ({ metadata }: { metadata: string[] }) => {
|
|||||||
{isImage(url) && <Image src={url} alt="image" className="h-auto w-full rounded-lg object-cover" />}
|
{isImage(url) && <Image src={url} alt="image" className="h-auto w-full rounded-lg object-cover" />}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { useProfile } from '@lume/utils/hooks/useProfile';
|
import { useProfile } from '@lume/utils/hooks/useProfile';
|
||||||
import { shortenKey } from '@lume/utils/shortenKey';
|
import { shortenKey } from '@lume/utils/shortenKey';
|
||||||
|
|
||||||
export const MentionUser = (props: { children: any[] }) => {
|
export function MentionUser(props: { children: any[] }) {
|
||||||
const pubkey = props.children[0];
|
const pubkey = props.children[0];
|
||||||
const { user } = useProfile(pubkey);
|
const { user } = useProfile(pubkey);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className="cursor-pointer text-fuchsia-500">@{user?.name || user?.display_name || shortenKey(pubkey)}</span>
|
<span className="cursor-pointer text-fuchsia-500">@{user?.name || user?.display_name || shortenKey(pubkey)}</span>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
@ -3,7 +3,7 @@ import { NoteRepostUser } from '@lume/app/note/components/user/repost';
|
|||||||
import { NoteWrapper } from '@lume/app/note/components/wrapper';
|
import { NoteWrapper } from '@lume/app/note/components/wrapper';
|
||||||
import { getQuoteID } from '@lume/utils/transform';
|
import { getQuoteID } from '@lume/utils/transform';
|
||||||
|
|
||||||
export const NoteQuoteRepost = ({ event }: { event: any }) => {
|
export function NoteQuoteRepost({ event }: { event: any }) {
|
||||||
const rootID = getQuoteID(event.tags);
|
const rootID = getQuoteID(event.tags);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -17,4 +17,4 @@ export const NoteQuoteRepost = ({ event }: { event: any }) => {
|
|||||||
</div>
|
</div>
|
||||||
</NoteWrapper>
|
</NoteWrapper>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export const NoteSkeleton = () => {
|
export function NoteSkeleton() {
|
||||||
return (
|
return (
|
||||||
<div className="flex h-min flex-col pb-3">
|
<div className="flex h-min flex-col pb-3">
|
||||||
<div className="flex items-center gap-2.5">
|
<div className="flex items-center gap-2.5">
|
||||||
@ -17,4 +17,4 @@ export const NoteSkeleton = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
@ -8,7 +8,7 @@ import relativeTime from 'dayjs/plugin/relativeTime';
|
|||||||
|
|
||||||
dayjs.extend(relativeTime);
|
dayjs.extend(relativeTime);
|
||||||
|
|
||||||
export const NoteDefaultUser = ({ pubkey, time }: { pubkey: string; time: number }) => {
|
export function NoteDefaultUser({ pubkey, time }: { pubkey: string; time: number }) {
|
||||||
const { user } = useProfile(pubkey);
|
const { user } = useProfile(pubkey);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -34,4 +34,4 @@ export const NoteDefaultUser = ({ pubkey, time }: { pubkey: string; time: number
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
@ -7,7 +7,7 @@ import relativeTime from 'dayjs/plugin/relativeTime';
|
|||||||
|
|
||||||
dayjs.extend(relativeTime);
|
dayjs.extend(relativeTime);
|
||||||
|
|
||||||
export const NoteRepostUser = ({ pubkey, time }: { pubkey: string; time: number }) => {
|
export function NoteRepostUser({ pubkey, time }: { pubkey: string; time: number }) {
|
||||||
const { user } = useProfile(pubkey);
|
const { user } = useProfile(pubkey);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -32,4 +32,4 @@ export const NoteRepostUser = ({ pubkey, time }: { pubkey: string; time: number
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { navigate } from 'vite-plugin-ssr/client/router';
|
import { navigate } from 'vite-plugin-ssr/client/router';
|
||||||
|
|
||||||
export const NoteWrapper = ({
|
export function NoteWrapper({
|
||||||
children,
|
children,
|
||||||
href,
|
href,
|
||||||
className,
|
className,
|
||||||
@ -8,7 +8,7 @@ export const NoteWrapper = ({
|
|||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
href: string;
|
href: string;
|
||||||
className: string;
|
className: string;
|
||||||
}) => {
|
}) {
|
||||||
const openThread = (event: any, href: string) => {
|
const openThread = (event: any, href: string) => {
|
||||||
const selection = window.getSelection();
|
const selection = window.getSelection();
|
||||||
if (selection.toString().length === 0) {
|
if (selection.toString().length === 0) {
|
||||||
@ -23,4 +23,4 @@ export const NoteWrapper = ({
|
|||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { PageContext } from '@lume/renderer/types';
|
import { PageContext } from '@lume/renderer/types';
|
||||||
import RelayProvider from '@lume/shared/relayProvider';
|
import { RelayProvider } from '@lume/shared/relayProvider';
|
||||||
import { PageContextProvider } from '@lume/utils/hooks/usePageContext';
|
import { PageContextProvider } from '@lume/utils/hooks/usePageContext';
|
||||||
|
|
||||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||||
|
@ -4,7 +4,7 @@ import { open } from '@tauri-apps/api/dialog';
|
|||||||
import { Body, fetch } from '@tauri-apps/api/http';
|
import { Body, fetch } from '@tauri-apps/api/http';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
|
||||||
export const AvatarUploader = ({ valueState }: { valueState: any }) => {
|
export function AvatarUploader({ valueState }: { valueState: any }) {
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
const openFileDialog = async () => {
|
const openFileDialog = async () => {
|
||||||
@ -72,4 +72,4 @@ export const AvatarUploader = ({ valueState }: { valueState: any }) => {
|
|||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
@ -9,7 +9,7 @@ import { Body, fetch } from '@tauri-apps/api/http';
|
|||||||
import { useSetAtom } from 'jotai';
|
import { useSetAtom } from 'jotai';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
|
||||||
export const ImagePicker = ({ type }: { type: string }) => {
|
export function ImagePicker({ type }: { type: string }) {
|
||||||
let atom;
|
let atom;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@ -93,4 +93,4 @@ export const ImagePicker = ({ type }: { type: string }) => {
|
|||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { DEFAULT_AVATAR } from '@lume/stores/constants';
|
import { DEFAULT_AVATAR } from '@lume/stores/constants';
|
||||||
|
|
||||||
export const Image = (props) => {
|
export function Image(props) {
|
||||||
const addImageFallback = (event) => {
|
const addImageFallback = (event) => {
|
||||||
event.currentTarget.src = DEFAULT_AVATAR;
|
event.currentTarget.src = DEFAULT_AVATAR;
|
||||||
};
|
};
|
||||||
@ -8,4 +8,4 @@ export const Image = (props) => {
|
|||||||
return (
|
return (
|
||||||
<img {...props} loading="lazy" decoding="async" onError={addImageFallback} style={{ contentVisibility: 'auto' }} />
|
<img {...props} loading="lazy" decoding="async" onError={addImageFallback} style={{ contentVisibility: 'auto' }} />
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { useNetworkStatus } from '@lume/utils/hooks/useNetworkStatus';
|
import { useNetworkStatus } from '@lume/utils/hooks/useNetworkStatus';
|
||||||
|
|
||||||
export const NetworkStatusIndicator = () => {
|
export function NetworkStatusIndicator() {
|
||||||
const isOnline = useNetworkStatus();
|
const isOnline = useNetworkStatus();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -18,4 +18,4 @@ export const NetworkStatusIndicator = () => {
|
|||||||
<p className="text-xs font-medium text-zinc-500">{isOnline ? 'Online' : 'Offline'}</p>
|
<p className="text-xs font-medium text-zinc-500">{isOnline ? 'Online' : 'Offline'}</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
@ -12,6 +12,6 @@ const pool = new RelayPool(FULL_RELAYS, {
|
|||||||
logSubscriptions: false,
|
logSubscriptions: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default function RelayProvider({ children }: { children: React.ReactNode }) {
|
export function RelayProvider({ children }: { children: React.ReactNode }) {
|
||||||
return <RelayContext.Provider value={pool}>{children}</RelayContext.Provider>;
|
return <RelayContext.Provider value={pool}>{children}</RelayContext.Provider>;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { autoUpdate, offset, shift, useFloating, useFocus, useHover, useInteractions } from '@floating-ui/react';
|
import { autoUpdate, offset, shift, useFloating, useFocus, useHover, useInteractions } from '@floating-ui/react';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
|
||||||
export default function Tooltip({ children, message }: { children: React.ReactNode; message: string }) {
|
export function Tooltip({ children, message }: { children: React.ReactNode; message: string }) {
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
|
||||||
const { x, y, strategy, refs, context } = useFloating({
|
const { x, y, strategy, refs, context } = useFloating({
|
||||||
|
@ -1,22 +1,22 @@
|
|||||||
// get X days ago with user provided date
|
// get X days ago with user provided date
|
||||||
export const daysAgo = (numOfDays, date = new Date()) => {
|
export function daysAgo(numOfDays, date = new Date()) {
|
||||||
const daysAgo = new Date(date.getTime());
|
const daysAgo = new Date(date.getTime());
|
||||||
daysAgo.setDate(date.getDate() - numOfDays);
|
daysAgo.setDate(date.getDate() - numOfDays);
|
||||||
|
|
||||||
return daysAgo;
|
return daysAgo;
|
||||||
};
|
}
|
||||||
|
|
||||||
// get X hours ago with user provided date
|
// get X hours ago with user provided date
|
||||||
export const hoursAgo = (numOfHours, date = new Date()) => {
|
export function hoursAgo(numOfHours, date = new Date()) {
|
||||||
const hoursAgo = new Date(date.getTime());
|
const hoursAgo = new Date(date.getTime());
|
||||||
hoursAgo.setHours(date.getHours() - numOfHours);
|
hoursAgo.setHours(date.getHours() - numOfHours);
|
||||||
|
|
||||||
return hoursAgo;
|
return hoursAgo;
|
||||||
};
|
}
|
||||||
|
|
||||||
// convert date to unix timestamp
|
// convert date to unix timestamp
|
||||||
export const dateToUnix = (_date?: Date) => {
|
export function dateToUnix(_date?: Date) {
|
||||||
const date = _date || new Date();
|
const date = _date || new Date();
|
||||||
|
|
||||||
return Math.floor(date.getTime() / 1000);
|
return Math.floor(date.getTime() / 1000);
|
||||||
};
|
}
|
||||||
|
@ -4,7 +4,7 @@ import useSWR from 'swr';
|
|||||||
|
|
||||||
const fetcher = () => getActiveAccount();
|
const fetcher = () => getActiveAccount();
|
||||||
|
|
||||||
export const useActiveAccount = () => {
|
export function useActiveAccount() {
|
||||||
const { data, error, isLoading } = useSWR('activeAcount', fetcher);
|
const { data, error, isLoading } = useSWR('activeAcount', fetcher);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -12,4 +12,4 @@ export const useActiveAccount = () => {
|
|||||||
isLoading,
|
isLoading,
|
||||||
isError: error,
|
isError: error,
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
@ -15,7 +15,7 @@ const fetcher = async ([, id]) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useChannelProfile = (id: string, channelPubkey: string) => {
|
export function useChannelProfile(id: string, channelPubkey: string) {
|
||||||
const pool: any = useContext(RelayContext);
|
const pool: any = useContext(RelayContext);
|
||||||
|
|
||||||
const { data: cache, isLoading } = useSWR(['channel-cache-profile', id], fetcher);
|
const { data: cache, isLoading } = useSWR(['channel-cache-profile', id], fetcher);
|
||||||
@ -53,4 +53,4 @@ export const useChannelProfile = (id: string, channelPubkey: string) => {
|
|||||||
} else {
|
} else {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { nip04 } from 'nostr-tools';
|
import { nip04 } from 'nostr-tools';
|
||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
|
|
||||||
export const useDecryptMessage = (userKey: string, userPriv: string, data: any) => {
|
export function useDecryptMessage(userKey: string, userPriv: string, data: any) {
|
||||||
const [content, setContent] = useState(null);
|
const [content, setContent] = useState(null);
|
||||||
|
|
||||||
const extractSenderKey = useCallback(() => {
|
const extractSenderKey = useCallback(() => {
|
||||||
@ -25,4 +25,4 @@ export const useDecryptMessage = (userKey: string, userPriv: string, data: any)
|
|||||||
}, [decrypt]);
|
}, [decrypt]);
|
||||||
|
|
||||||
return content ? content : null;
|
return content ? content : null;
|
||||||
};
|
}
|
||||||
|
@ -3,7 +3,7 @@ import { useEffect, useState } from 'react';
|
|||||||
const getOnLineStatus = () =>
|
const getOnLineStatus = () =>
|
||||||
typeof navigator !== 'undefined' && typeof navigator.onLine === 'boolean' ? navigator.onLine : true;
|
typeof navigator !== 'undefined' && typeof navigator.onLine === 'boolean' ? navigator.onLine : true;
|
||||||
|
|
||||||
export const useNetworkStatus = () => {
|
export function useNetworkStatus() {
|
||||||
const [status, setStatus] = useState(getOnLineStatus());
|
const [status, setStatus] = useState(getOnLineStatus());
|
||||||
|
|
||||||
const setOnline = () => setStatus(true);
|
const setOnline = () => setStatus(true);
|
||||||
@ -20,4 +20,4 @@ export const useNetworkStatus = () => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
};
|
}
|
||||||
|
@ -22,7 +22,7 @@ const fetcher = async (pubkey: string) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useProfile = (pubkey: string) => {
|
export function useProfile(pubkey: string) {
|
||||||
const { data, error, isLoading } = useSWR(pubkey, fetcher);
|
const { data, error, isLoading } = useSWR(pubkey, fetcher);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -30,4 +30,4 @@ export const useProfile = (pubkey: string) => {
|
|||||||
isLoading,
|
isLoading,
|
||||||
isError: error,
|
isError: error,
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
@ -5,7 +5,7 @@ const getURLs = new RegExp(
|
|||||||
'gmi'
|
'gmi'
|
||||||
);
|
);
|
||||||
|
|
||||||
export const noteParser = (event: Event) => {
|
export function noteParser(event: Event) {
|
||||||
const references = parseReferences(event);
|
const references = parseReferences(event);
|
||||||
const content: { original: string; parsed: any; notes: string[]; images: string[]; videos: string[] } = {
|
const content: { original: string; parsed: any; notes: string[]; images: string[]; videos: string[] } = {
|
||||||
original: event.content,
|
original: event.content,
|
||||||
@ -54,4 +54,4 @@ export const noteParser = (event: Event) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
};
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { nip19 } from 'nostr-tools';
|
import { nip19 } from 'nostr-tools';
|
||||||
|
|
||||||
export const shortenKey = (pubkey: string) => {
|
export function shortenKey(pubkey: string) {
|
||||||
const npub = nip19.npubEncode(pubkey);
|
const npub = nip19.npubEncode(pubkey);
|
||||||
return npub.substring(0, 16).concat('...');
|
return npub.substring(0, 16).concat('...');
|
||||||
};
|
}
|
||||||
|
@ -1,37 +1,37 @@
|
|||||||
import destr from 'destr';
|
import destr from 'destr';
|
||||||
|
|
||||||
// convert NIP-02 to array of pubkey
|
// convert NIP-02 to array of pubkey
|
||||||
export const nip02ToArray = (tags: any) => {
|
export function nip02ToArray(tags: any) {
|
||||||
const arr = [];
|
const arr = [];
|
||||||
tags.forEach((item) => {
|
tags.forEach((item) => {
|
||||||
arr.push(item[1]);
|
arr.push(item[1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
return arr;
|
return arr;
|
||||||
};
|
}
|
||||||
|
|
||||||
// convert array to NIP-02 tag list
|
// convert array to NIP-02 tag list
|
||||||
export const arrayToNIP02 = (arr: string[]) => {
|
export function arrayToNIP02(arr: string[]) {
|
||||||
const nip02_arr = [];
|
const nip02_arr = [];
|
||||||
arr.forEach((item) => {
|
arr.forEach((item) => {
|
||||||
nip02_arr.push(['p', item]);
|
nip02_arr.push(['p', item]);
|
||||||
});
|
});
|
||||||
|
|
||||||
return nip02_arr;
|
return nip02_arr;
|
||||||
};
|
}
|
||||||
|
|
||||||
// convert array object to pure array
|
// convert array object to pure array
|
||||||
export const arrayObjToPureArr = (arr: any) => {
|
export function arrayObjToPureArr(arr: any) {
|
||||||
const pure_arr = [];
|
const pure_arr = [];
|
||||||
arr.forEach((item) => {
|
arr.forEach((item) => {
|
||||||
pure_arr.push(item.content);
|
pure_arr.push(item.content);
|
||||||
});
|
});
|
||||||
|
|
||||||
return pure_arr;
|
return pure_arr;
|
||||||
};
|
}
|
||||||
|
|
||||||
// get parent id from event tags
|
// get parent id from event tags
|
||||||
export const getParentID = (arr: string[], fallback: string) => {
|
export function getParentID(arr: string[], fallback: string) {
|
||||||
const tags = destr(arr);
|
const tags = destr(arr);
|
||||||
let parentID = fallback;
|
let parentID = fallback;
|
||||||
|
|
||||||
@ -48,10 +48,10 @@ export const getParentID = (arr: string[], fallback: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return parentID;
|
return parentID;
|
||||||
};
|
}
|
||||||
|
|
||||||
// check id present in event tags
|
// check id present in event tags
|
||||||
export const isTagsIncludeID = (id: string, arr: string[]) => {
|
export function isTagsIncludeID(id: string, arr: string[]) {
|
||||||
const tags = destr(arr);
|
const tags = destr(arr);
|
||||||
|
|
||||||
if (tags.length > 0) {
|
if (tags.length > 0) {
|
||||||
@ -61,10 +61,10 @@ export const isTagsIncludeID = (id: string, arr: string[]) => {
|
|||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// get parent id from event tags
|
// get parent id from event tags
|
||||||
export const getQuoteID = (arr: string[]) => {
|
export function getQuoteID(arr: string[]) {
|
||||||
const tags = destr(arr);
|
const tags = destr(arr);
|
||||||
let quoteID = null;
|
let quoteID = null;
|
||||||
|
|
||||||
@ -81,13 +81,13 @@ export const getQuoteID = (arr: string[]) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return quoteID;
|
return quoteID;
|
||||||
};
|
}
|
||||||
|
|
||||||
// sort events by timestamp
|
// sort events by timestamp
|
||||||
export const sortEvents = (arr: any) => {
|
export function sortEvents(arr: any) {
|
||||||
arr.sort((a, b) => {
|
arr.sort((a, b) => {
|
||||||
return a.created_at - b.created_at;
|
return a.created_at - b.created_at;
|
||||||
});
|
});
|
||||||
|
|
||||||
return arr;
|
return arr;
|
||||||
};
|
}
|
||||||
|
@ -2,7 +2,12 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"baseUrl": "./",
|
"baseUrl": "./",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@lume/*": ["src/*"]
|
"@lume/*": ["src/*"],
|
||||||
|
"@app/*": ["src/app/*"],
|
||||||
|
"@shared/*": ["src/shared/*"],
|
||||||
|
"@icons/*": ["src/shared/icons/*"],
|
||||||
|
"@stores/*": ["src/stores/*"],
|
||||||
|
"@utils/*": ["src/utils/*"]
|
||||||
},
|
},
|
||||||
"types": ["vidstack/globals"],
|
"types": ["vidstack/globals"],
|
||||||
"target": "es2017",
|
"target": "es2017",
|
||||||
|
Loading…
Reference in New Issue
Block a user