React Map Optimization, [missing map keys ] (#283)

* comment unused import ( minmizes js )

* Add keys missing keys on map for better React Diff

* [ImgBot] Optimize images

*Total -- 821.02kb -> 674.06kb (17.9%)

/public/nostrich_512.png -- 650.16kb -> 527.94kb (18.8%)
/public/nostrich_256.png -- 170.86kb -> 146.12kb (14.48%)

Signed-off-by: ImgBotApp <ImgBotHelp@gmail.com>

---------

Signed-off-by: ImgBotApp <ImgBotHelp@gmail.com>
Co-authored-by: ImgBotApp <ImgBotHelp@gmail.com>
This commit is contained in:
Ahmed Rowaihi
2023-02-13 01:06:21 +03:00
committed by GitHub
parent 94beae35bc
commit 2adf176dde
6 changed files with 12 additions and 11 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 171 KiB

After

Width:  |  Height:  |  Size: 146 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 650 KiB

After

Width:  |  Height:  |  Size: 528 KiB

View File

@ -1,5 +1,5 @@
import "./Note.css"; import "./Note.css";
import { useCallback, useMemo, useState, useLayoutEffect, ReactNode } from "react"; import React, { useCallback, useMemo, useState, useLayoutEffect, ReactNode } from "react";
import { useNavigate, Link } from "react-router-dom"; import { useNavigate, Link } from "react-router-dom";
import { useInView } from "react-intersection-observer"; import { useInView } from "react-intersection-observer";
import { useIntl, FormattedMessage } from "react-intl"; import { useIntl, FormattedMessage } from "react-intl";
@ -127,12 +127,12 @@ export default function Note(props: NoteProps) {
} }
mentions.sort(a => (a.name.startsWith("npub") ? 1 : -1)); mentions.sort(a => (a.name.startsWith("npub") ? 1 : -1));
const othersLength = mentions.length - maxMentions; const othersLength = mentions.length - maxMentions;
const renderMention = (m: { link: React.ReactNode }, idx: number) => { const renderMention = (m: { link: React.ReactNode; pk: string; name: string }, idx: number) => {
return ( return (
<> <React.Fragment key={m.pk}>
{idx > 0 && ", "} {idx > 0 && ", "}
{m.link} {m.link}
</> </React.Fragment>
); );
}; };
const pubMentions = const pubMentions =

View File

@ -38,7 +38,7 @@ export default function Text({ content, tags, creator, users }: TextProps) {
if (typeof f === "string") { if (typeof f === "string") {
return f.split(UrlRegex).map(a => { return f.split(UrlRegex).map(a => {
if (a.startsWith("http")) { if (a.startsWith("http")) {
return <HyperText link={a} creator={creator} />; return <HyperText key={a} link={a} creator={creator} />;
} }
return a; return a;
}); });
@ -60,7 +60,7 @@ export default function Text({ content, tags, creator, users }: TextProps) {
if (ref) { if (ref) {
switch (ref.Key) { switch (ref.Key) {
case "p": { case "p": {
return <Mention pubkey={ref.PubKey ?? ""} />; return <Mention key={ref.PubKey} pubkey={ref.PubKey ?? ""} />;
} }
case "e": { case "e": {
const eText = hexToBech32("note", ref.Event).substring(0, 12); const eText = hexToBech32("note", ref.Event).substring(0, 12);
@ -71,7 +71,7 @@ export default function Text({ content, tags, creator, users }: TextProps) {
); );
} }
case "t": { case "t": {
return <Hashtag tag={ref.Hashtag ?? ""} />; return <Hashtag key={ref.Hashtag} tag={ref.Hashtag ?? ""} />;
} }
} }
} }
@ -109,7 +109,7 @@ export default function Text({ content, tags, creator, users }: TextProps) {
if (typeof f === "string") { if (typeof f === "string") {
return f.split(HashtagRegex).map(i => { return f.split(HashtagRegex).map(i => {
if (i.toLowerCase().startsWith("#")) { if (i.toLowerCase().startsWith("#")) {
return <Hashtag tag={i.substring(1)} />; return <Hashtag key={i} tag={i.substring(1)} />;
} else { } else {
return i; return i;
} }

View File

@ -12,7 +12,7 @@ import { DefaultRelays, EmailRegex } from "Const";
import { bech32ToHex, unwrap } from "Util"; import { bech32ToHex, unwrap } from "Util";
import { HexKey } from "Nostr"; import { HexKey } from "Nostr";
import ZapButton from "Element/ZapButton"; import ZapButton from "Element/ZapButton";
import useImgProxy from "Feed/ImgProxy"; // import useImgProxy from "Feed/ImgProxy";
interface ArtworkEntry { interface ArtworkEntry {
name: string; name: string;
@ -51,7 +51,7 @@ export default function LoginPage() {
const [key, setKey] = useState(""); const [key, setKey] = useState("");
const [error, setError] = useState(""); const [error, setError] = useState("");
const [art, setArt] = useState<ArtworkEntry>(); const [art, setArt] = useState<ArtworkEntry>();
const { proxy } = useImgProxy(); // const { proxy } = useImgProxy();
useEffect(() => { useEffect(() => {
if (publicKey) { if (publicKey) {

View File

@ -278,7 +278,7 @@ export default function ProfilePage() {
} }
function renderTab(v: Tab) { function renderTab(v: Tab) {
return <TabElement t={v} tab={tab} setTab={setTab} />; return <TabElement key={v.value} t={v} tab={tab} setTab={setTab} />;
} }
const w = window.document.querySelector(".page")?.clientWidth; const w = window.document.querySelector(".page")?.clientWidth;
@ -293,6 +293,7 @@ export default function ProfilePage() {
</div> </div>
<div className="tabs main-content" ref={horizontalScroll}> <div className="tabs main-content" ref={horizontalScroll}>
{[ProfileTab.Notes, ProfileTab.Followers, ProfileTab.Follows, ProfileTab.Muted].map(renderTab)} {[ProfileTab.Notes, ProfileTab.Followers, ProfileTab.Follows, ProfileTab.Muted].map(renderTab)}
{optionalTabs.map(renderTab)} {optionalTabs.map(renderTab)}
{isMe && renderTab(ProfileTab.Blocked)} {isMe && renderTab(ProfileTab.Blocked)}
</div> </div>