refactor: remove lodash
This commit is contained in:
parent
3103b994a1
commit
d59e0c9f36
@ -20,7 +20,6 @@
|
||||
"emoji-mart": "^5.5.2",
|
||||
"flag-icons": "^6.11.0",
|
||||
"hls.js": "^1.4.6",
|
||||
"lodash": "^4.17.21",
|
||||
"marked": "^9.1.2",
|
||||
"qr-code-styling": "^1.6.0-rc.1",
|
||||
"react": "^18.2.0",
|
||||
@ -74,8 +73,6 @@
|
||||
"@formatjs/cli": "^6.1.3",
|
||||
"@formatjs/ts-transformer": "^3.13.3",
|
||||
"@testing-library/dom": "^9.3.1",
|
||||
"@types/lodash": "^4.14.195",
|
||||
"@types/lodash.uniqby": "^4.7.7",
|
||||
"@types/node": "^20.10.3",
|
||||
"@types/react": "^18.2.21",
|
||||
"@types/react-dom": "^18.2.7",
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { isEmpty } from "lodash";
|
||||
import { forwardRef, lazy, Suspense } from "react";
|
||||
import { ExternalLink } from "../external-link";
|
||||
import { NewCard } from ".";
|
||||
@ -9,6 +8,10 @@ interface CardPreviewProps extends NewCard {
|
||||
style: object;
|
||||
}
|
||||
|
||||
function isEmpty(s: string | undefined) {
|
||||
return s === undefined || s.trim().length > 0;
|
||||
}
|
||||
|
||||
export const CardPreview = forwardRef<HTMLDivElement, CardPreviewProps>(({ style, title, link, image, content }: CardPreviewProps, ref) => {
|
||||
const isImageOnly = !isEmpty(image) && isEmpty(content) && isEmpty(title);
|
||||
return (
|
||||
|
@ -2,12 +2,10 @@ import "./textarea.css";
|
||||
import { useContext } from "react";
|
||||
import ReactTextareaAutocomplete, { TriggerType } from "@webscopeio/react-textarea-autocomplete";
|
||||
import "@webscopeio/react-textarea-autocomplete/style.css";
|
||||
import uniqWith from "lodash/uniqWith";
|
||||
import isEqual from "lodash/isEqual";
|
||||
|
||||
import { hexToBech32 } from "@snort/shared";
|
||||
import { SnortContext } from "@snort/system-react";
|
||||
import { MetadataCache, NostrPrefix, UserProfileCache } from "@snort/system";
|
||||
import { CachedMetadata, NostrPrefix, UserProfileCache } from "@snort/system";
|
||||
|
||||
import { Emoji } from "./emoji";
|
||||
import { Avatar } from "./avatar";
|
||||
@ -29,7 +27,7 @@ const EmojiItem = ({ entity: { name, url } }: { entity: EmojiItemProps }) => {
|
||||
);
|
||||
};
|
||||
|
||||
const UserItem = (metadata: MetadataCache) => {
|
||||
const UserItem = (metadata: CachedMetadata) => {
|
||||
const { pubkey, display_name, ...rest } = metadata;
|
||||
return (
|
||||
<div key={pubkey} className="user-item">
|
||||
@ -44,7 +42,7 @@ type TextareaProps = { emojis: EmojiTag[] } & React.TextareaHTMLAttributes<HTMLT
|
||||
export function Textarea({ emojis, ...props }: TextareaProps) {
|
||||
const system = useContext(SnortContext);
|
||||
const userDataProvider = async (token: string) => {
|
||||
const cache = system.ProfileLoader.Cache;
|
||||
const cache = system.profileLoader.cache;
|
||||
if (cache instanceof UserProfileCache) {
|
||||
return await cache.search(token);
|
||||
}
|
||||
@ -59,7 +57,7 @@ export function Textarea({ emojis, ...props }: TextareaProps) {
|
||||
};
|
||||
})
|
||||
.filter(({ name }) => name.toLowerCase().includes(token.toLowerCase()));
|
||||
return uniqWith(results, isEqual).slice(0, 5);
|
||||
return results.slice(0, 5);
|
||||
};
|
||||
|
||||
const trigger = {
|
||||
@ -71,7 +69,7 @@ export function Textarea({ emojis, ...props }: TextareaProps) {
|
||||
"@": {
|
||||
afterWhitespace: true,
|
||||
dataProvider: userDataProvider,
|
||||
component: (props: { entity: MetadataCache }) => <UserItem {...props.entity} />,
|
||||
component: (props: { entity: CachedMetadata }) => <UserItem {...props.entity} />,
|
||||
output: (item: { pubkey: string }) => `@${hexToBech32(NostrPrefix.PublicKey, item.pubkey)}`,
|
||||
},
|
||||
} as TriggerType<string | object>;
|
||||
|
@ -12,9 +12,9 @@ import { ZapAlertItem } from "./widgets/zaps";
|
||||
import { TopZappersWidget } from "./widgets/top-zappers";
|
||||
import { Views } from "./widgets/views";
|
||||
import { Music } from "./widgets/music";
|
||||
import groupBy from "lodash/groupBy";
|
||||
import { hexToBech32 } from "@snort/shared";
|
||||
import { DefaultButton } from "@/element/buttons";
|
||||
import { groupBy } from "@/utils";
|
||||
|
||||
interface ZapAlertConfigurationProps {
|
||||
npub: string;
|
||||
|
@ -154,3 +154,12 @@ export function trackEvent(
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function groupBy<T>(val: Array<T>, selector: (a: T) => string | number): Record<string, Array<T>> {
|
||||
return val.reduce((acc, v) => {
|
||||
const key = selector(v);
|
||||
acc[key] ??= [];
|
||||
acc[key].push(v);
|
||||
return acc;
|
||||
}, {} as Record<string, Array<T>>)
|
||||
}
|
19
yarn.lock
19
yarn.lock
@ -2649,22 +2649,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/lodash.uniqby@npm:^4.7.7":
|
||||
version: 4.7.7
|
||||
resolution: "@types/lodash.uniqby@npm:4.7.7"
|
||||
dependencies:
|
||||
"@types/lodash": "*"
|
||||
checksum: f496fd390c632f070b2bae7527cecd79c5398c6c2d14157bb85830b78ad72acbea095ddd8573f33ca97a94ac31cdaae83800373bba9f4f4f503a4dce98a87812
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/lodash@npm:*, @types/lodash@npm:^4.14.195":
|
||||
version: 4.14.197
|
||||
resolution: "@types/lodash@npm:4.14.197"
|
||||
checksum: 53d7567d1704de76cf33266c78062e0fd722d4b846e5b1417d0b6ef0ee41c0d9c451b92bc34f73d5f1fcc45c7d36511e92f6f47a9279b48157ba60a92ddaa078
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/node@npm:*":
|
||||
version: 20.5.6
|
||||
resolution: "@types/node@npm:20.5.6"
|
||||
@ -7102,8 +7086,6 @@ __metadata:
|
||||
"@snort/system-web": ^1.2.11
|
||||
"@szhsin/react-menu": ^4.0.2
|
||||
"@testing-library/dom": ^9.3.1
|
||||
"@types/lodash": ^4.14.195
|
||||
"@types/lodash.uniqby": ^4.7.7
|
||||
"@types/node": ^20.10.3
|
||||
"@types/react": ^18.2.21
|
||||
"@types/react-dom": ^18.2.7
|
||||
@ -7123,7 +7105,6 @@ __metadata:
|
||||
eslint-plugin-formatjs: ^4.11.3
|
||||
flag-icons: ^6.11.0
|
||||
hls.js: ^1.4.6
|
||||
lodash: ^4.17.21
|
||||
marked: ^9.1.2
|
||||
postcss: ^8.4.32
|
||||
prettier: ^2.8.8
|
||||
|
Loading…
x
Reference in New Issue
Block a user