convert const function to function

This commit is contained in:
Ren Amamiya 2023-05-10 15:48:24 +07:00
parent ae5ff0c48f
commit 1a30c10806
32 changed files with 87 additions and 79 deletions

View File

@ -8,7 +8,16 @@
"endOfLine": "lf",
"bracketSpacing": true,
"bracketSameLine": false,
"importOrder": ["^@lume/(.*)$", "<THIRD_PARTY_MODULES>", "^[./]"],
"importOrder": [
"^@lume/(.*)$",
"^@app/(.*)$",
"^@shared/(.*)$",
"^@icons/(.*)$",
"^@stores/(.*)$",
"^@utils/(.*)$",
"<THIRD_PARTY_MODULES>",
"^[./]"
],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true,
"plugins": ["@trivago/prettier-plugin-sort-imports", "prettier-plugin-tailwindcss"],

View File

@ -1,7 +1,7 @@
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 { Tooltip } from '@lume/shared/tooltip';
import { channelMessagesAtom } from '@lume/stores/channel';
import { WRITEONLY_RELAYS } from '@lume/stores/constants';
import { dateToUnix } from '@lume/utils/getDate';

View File

@ -1,7 +1,7 @@
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 { Tooltip } from '@lume/shared/tooltip';
import { channelMessagesAtom } from '@lume/stores/channel';
import { WRITEONLY_RELAYS } from '@lume/stores/constants';
import { dateToUnix } from '@lume/utils/getDate';

View File

@ -1,5 +1,5 @@
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 { useSetAtom } from 'jotai';

View File

@ -1,6 +1,6 @@
import { CreateViewModal } from '@lume/app/daily/components/views/createModal';
export const Header = () => {
export function Header() {
return (
<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">
@ -42,4 +42,4 @@ export const Header = () => {
<CreateViewModal />
</div>
);
};
}

View File

@ -1,16 +1,10 @@
import CancelIcon from '@lume/shared/icons/cancel';
import PlusIcon from '@lume/shared/icons/plus';
//import { getNoteAuthors } from '@lume/utils/storage';
import { Dialog, Transition } from '@headlessui/react';
import { Fragment, useState } from 'react';
//import useSWR from 'swr';
//const fetcher = () => getNoteAuthors();
export const CreateViewModal = () => {
//const { data, error }: any = useSWR('authors', fetcher);
export function CreateViewModal() {
const [isOpen, setIsOpen] = useState(false);
const closeModal = () => {
@ -89,4 +83,4 @@ export const CreateViewModal = () => {
</Transition>
</>
);
};
}

View File

@ -9,7 +9,7 @@ import { isTagsIncludeID } from '@lume/utils/transform';
import { useMemo } from 'react';
export const NoteBase = ({ event }: { event: any }) => {
export function NoteBase({ event }: { event: any }) {
const content = useMemo(() => noteParser(event), [event]);
const checkParentID = isTagsIncludeID(event.parent_id, event.tags);
@ -34,4 +34,4 @@ export const NoteBase = ({ event }: { event: any }) => {
</div>
</NoteWrapper>
);
};
}

View File

@ -6,7 +6,7 @@ import VideoPreview from '@lume/app/note/components/preview/video';
import ReactMarkdown from 'react-markdown';
import remarkGfm from 'remark-gfm';
export const Kind1 = ({ content }: { content: any }) => {
export function Kind1({ content }: { content: any }) {
return (
<>
<ReactMarkdown
@ -28,4 +28,4 @@ export const Kind1 = ({ content }: { content: any }) => {
)}
</>
);
};
}

View File

@ -4,7 +4,7 @@ function isImage(url: string) {
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];
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" />}
</div>
);
};
}

View File

@ -1,11 +1,11 @@
import { useProfile } from '@lume/utils/hooks/useProfile';
import { shortenKey } from '@lume/utils/shortenKey';
export const MentionUser = (props: { children: any[] }) => {
export function MentionUser(props: { children: any[] }) {
const pubkey = props.children[0];
const { user } = useProfile(pubkey);
return (
<span className="cursor-pointer text-fuchsia-500">@{user?.name || user?.display_name || shortenKey(pubkey)}</span>
);
};
}

View File

@ -3,7 +3,7 @@ import { NoteRepostUser } from '@lume/app/note/components/user/repost';
import { NoteWrapper } from '@lume/app/note/components/wrapper';
import { getQuoteID } from '@lume/utils/transform';
export const NoteQuoteRepost = ({ event }: { event: any }) => {
export function NoteQuoteRepost({ event }: { event: any }) {
const rootID = getQuoteID(event.tags);
return (
@ -17,4 +17,4 @@ export const NoteQuoteRepost = ({ event }: { event: any }) => {
</div>
</NoteWrapper>
);
};
}

View File

@ -1,4 +1,4 @@
export const NoteSkeleton = () => {
export function NoteSkeleton() {
return (
<div className="flex h-min flex-col pb-3">
<div className="flex items-center gap-2.5">
@ -17,4 +17,4 @@ export const NoteSkeleton = () => {
</div>
</div>
);
};
}

View File

@ -8,7 +8,7 @@ import relativeTime from 'dayjs/plugin/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);
return (
@ -34,4 +34,4 @@ export const NoteDefaultUser = ({ pubkey, time }: { pubkey: string; time: number
</div>
</div>
);
};
}

View File

@ -7,7 +7,7 @@ import relativeTime from 'dayjs/plugin/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);
return (
@ -32,4 +32,4 @@ export const NoteRepostUser = ({ pubkey, time }: { pubkey: string; time: number
</div>
</div>
);
};
}

View File

@ -1,6 +1,6 @@
import { navigate } from 'vite-plugin-ssr/client/router';
export const NoteWrapper = ({
export function NoteWrapper({
children,
href,
className,
@ -8,7 +8,7 @@ export const NoteWrapper = ({
children: React.ReactNode;
href: string;
className: string;
}) => {
}) {
const openThread = (event: any, href: string) => {
const selection = window.getSelection();
if (selection.toString().length === 0) {
@ -23,4 +23,4 @@ export const NoteWrapper = ({
{children}
</div>
);
};
}

View File

@ -1,5 +1,5 @@
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 { QueryClient, QueryClientProvider } from '@tanstack/react-query';

View File

@ -4,7 +4,7 @@ import { open } from '@tauri-apps/api/dialog';
import { Body, fetch } from '@tauri-apps/api/http';
import { useState } from 'react';
export const AvatarUploader = ({ valueState }: { valueState: any }) => {
export function AvatarUploader({ valueState }: { valueState: any }) {
const [loading, setLoading] = useState(false);
const openFileDialog = async () => {
@ -72,4 +72,4 @@ export const AvatarUploader = ({ valueState }: { valueState: any }) => {
)}
</button>
);
};
}

View File

@ -9,7 +9,7 @@ import { Body, fetch } from '@tauri-apps/api/http';
import { useSetAtom } from 'jotai';
import { useState } from 'react';
export const ImagePicker = ({ type }: { type: string }) => {
export function ImagePicker({ type }: { type: string }) {
let atom;
switch (type) {
@ -93,4 +93,4 @@ export const ImagePicker = ({ type }: { type: string }) => {
)}
</button>
);
};
}

View File

@ -1,6 +1,6 @@
import { DEFAULT_AVATAR } from '@lume/stores/constants';
export const Image = (props) => {
export function Image(props) {
const addImageFallback = (event) => {
event.currentTarget.src = DEFAULT_AVATAR;
};
@ -8,4 +8,4 @@ export const Image = (props) => {
return (
<img {...props} loading="lazy" decoding="async" onError={addImageFallback} style={{ contentVisibility: 'auto' }} />
);
};
}

View File

@ -1,6 +1,6 @@
import { useNetworkStatus } from '@lume/utils/hooks/useNetworkStatus';
export const NetworkStatusIndicator = () => {
export function NetworkStatusIndicator() {
const isOnline = useNetworkStatus();
return (
@ -18,4 +18,4 @@ export const NetworkStatusIndicator = () => {
<p className="text-xs font-medium text-zinc-500">{isOnline ? 'Online' : 'Offline'}</p>
</div>
);
};
}

View File

@ -12,6 +12,6 @@ const pool = new RelayPool(FULL_RELAYS, {
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>;
}

View File

@ -1,7 +1,7 @@
import { autoUpdate, offset, shift, useFloating, useFocus, useHover, useInteractions } from '@floating-ui/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 { x, y, strategy, refs, context } = useFloating({

View File

@ -1,22 +1,22 @@
// 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());
daysAgo.setDate(date.getDate() - numOfDays);
return daysAgo;
};
}
// 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());
hoursAgo.setHours(date.getHours() - numOfHours);
return hoursAgo;
};
}
// convert date to unix timestamp
export const dateToUnix = (_date?: Date) => {
export function dateToUnix(_date?: Date) {
const date = _date || new Date();
return Math.floor(date.getTime() / 1000);
};
}

View File

@ -4,7 +4,7 @@ import useSWR from 'swr';
const fetcher = () => getActiveAccount();
export const useActiveAccount = () => {
export function useActiveAccount() {
const { data, error, isLoading } = useSWR('activeAcount', fetcher);
return {
@ -12,4 +12,4 @@ export const useActiveAccount = () => {
isLoading,
isError: error,
};
};
}

View File

@ -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 { data: cache, isLoading } = useSWR(['channel-cache-profile', id], fetcher);
@ -53,4 +53,4 @@ export const useChannelProfile = (id: string, channelPubkey: string) => {
} else {
return data;
}
};
}

View File

@ -1,7 +1,7 @@
import { nip04 } from 'nostr-tools';
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 extractSenderKey = useCallback(() => {
@ -25,4 +25,4 @@ export const useDecryptMessage = (userKey: string, userPriv: string, data: any)
}, [decrypt]);
return content ? content : null;
};
}

View File

@ -3,7 +3,7 @@ import { useEffect, useState } from 'react';
const getOnLineStatus = () =>
typeof navigator !== 'undefined' && typeof navigator.onLine === 'boolean' ? navigator.onLine : true;
export const useNetworkStatus = () => {
export function useNetworkStatus() {
const [status, setStatus] = useState(getOnLineStatus());
const setOnline = () => setStatus(true);
@ -20,4 +20,4 @@ export const useNetworkStatus = () => {
}, []);
return status;
};
}

View File

@ -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);
return {
@ -30,4 +30,4 @@ export const useProfile = (pubkey: string) => {
isLoading,
isError: error,
};
};
}

View File

@ -5,7 +5,7 @@ const getURLs = new RegExp(
'gmi'
);
export const noteParser = (event: Event) => {
export function noteParser(event: Event) {
const references = parseReferences(event);
const content: { original: string; parsed: any; notes: string[]; images: string[]; videos: string[] } = {
original: event.content,
@ -54,4 +54,4 @@ export const noteParser = (event: Event) => {
});
return content;
};
}

View File

@ -1,6 +1,6 @@
import { nip19 } from 'nostr-tools';
export const shortenKey = (pubkey: string) => {
export function shortenKey(pubkey: string) {
const npub = nip19.npubEncode(pubkey);
return npub.substring(0, 16).concat('...');
};
}

View File

@ -1,37 +1,37 @@
import destr from 'destr';
// convert NIP-02 to array of pubkey
export const nip02ToArray = (tags: any) => {
export function nip02ToArray(tags: any) {
const arr = [];
tags.forEach((item) => {
arr.push(item[1]);
});
return arr;
};
}
// convert array to NIP-02 tag list
export const arrayToNIP02 = (arr: string[]) => {
export function arrayToNIP02(arr: string[]) {
const nip02_arr = [];
arr.forEach((item) => {
nip02_arr.push(['p', item]);
});
return nip02_arr;
};
}
// convert array object to pure array
export const arrayObjToPureArr = (arr: any) => {
export function arrayObjToPureArr(arr: any) {
const pure_arr = [];
arr.forEach((item) => {
pure_arr.push(item.content);
});
return pure_arr;
};
}
// get parent id from event tags
export const getParentID = (arr: string[], fallback: string) => {
export function getParentID(arr: string[], fallback: string) {
const tags = destr(arr);
let parentID = fallback;
@ -48,10 +48,10 @@ export const getParentID = (arr: string[], fallback: string) => {
}
return parentID;
};
}
// check id present in event tags
export const isTagsIncludeID = (id: string, arr: string[]) => {
export function isTagsIncludeID(id: string, arr: string[]) {
const tags = destr(arr);
if (tags.length > 0) {
@ -61,10 +61,10 @@ export const isTagsIncludeID = (id: string, arr: string[]) => {
} else {
return false;
}
};
}
// get parent id from event tags
export const getQuoteID = (arr: string[]) => {
export function getQuoteID(arr: string[]) {
const tags = destr(arr);
let quoteID = null;
@ -81,13 +81,13 @@ export const getQuoteID = (arr: string[]) => {
}
return quoteID;
};
}
// sort events by timestamp
export const sortEvents = (arr: any) => {
export function sortEvents(arr: any) {
arr.sort((a, b) => {
return a.created_at - b.created_at;
});
return arr;
};
}

View File

@ -2,7 +2,12 @@
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@lume/*": ["src/*"]
"@lume/*": ["src/*"],
"@app/*": ["src/app/*"],
"@shared/*": ["src/shared/*"],
"@icons/*": ["src/shared/icons/*"],
"@stores/*": ["src/stores/*"],
"@utils/*": ["src/utils/*"]
},
"types": ["vidstack/globals"],
"target": "es2017",