Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ECO-2364] Fix double rendering issue on home page #341

Merged
merged 4 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import { marketDataToProps } from "./utils";
import { useGridRowLength } from "./hooks/use-grid-items-per-line";
import { type MarketDataSortByHomePage } from "lib/queries/sorting/types";
import { useEffect, useMemo, useRef } from "react";
import "./module.css";
import { useEmojiPicker } from "context/emoji-picker-context";
import { type HomePageProps } from "app/home/HomePage";
import "./module.css";

export const ClientGrid = ({
markets,
Expand All @@ -20,11 +19,10 @@ export const ClientGrid = ({
sortBy: MarketDataSortByHomePage;
}) => {
const rowLength = useGridRowLength();
const searchEmojis = useEmojiPicker((s) => s.emojis);

const ordered = useMemo(() => {
return marketDataToProps(markets, searchEmojis);
}, [markets, searchEmojis]);
return marketDataToProps(markets);
}, [markets]);

const initialRender = useRef(true);

Expand All @@ -41,7 +39,7 @@ export const ClientGrid = ({
{ordered.map((v, i) => {
return (
<TableCard
key={`live-${v.marketID}-${v.searchEmojisKey}`}
key={`live-${v.marketID}`}
index={i}
pageOffset={(page - 1) * MARKETS_PER_PAGE}
marketID={v.marketID}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { type SymbolEmoji } from "@sdk/emoji_data";

export type PropsWithTime = Omit<TableCardProps, "index" | "rowLength"> & {
time: number;
searchEmojisKey: string;
};
export type PropsWithTimeAndIndex = TableCardProps & {
time: number;
Expand All @@ -19,18 +18,14 @@ export type WithTimeIndexAndPrev = PropsWithTimeAndIndex & {

const toSearchEmojisKey = (searchEmojis: string[]) => `{${searchEmojis.join("")}}`;

export const marketDataToProps = (
markets: HomePageProps["markets"],
searchEmojis: string[]
): PropsWithTime[] =>
export const marketDataToProps = (markets: HomePageProps["markets"]): PropsWithTime[] =>
markets.map((m) => ({
time: Number(m.market.time),
symbol: m.market.symbolData.symbol,
marketID: Number(m.market.marketID),
emojis: m.market.emojis,
staticMarketCap: m.state.instantaneousStats.marketCap.toString(),
staticVolume24H: m.dailyVolume.toString(),
searchEmojisKey: toSearchEmojisKey(searchEmojis),
}));

export const stateEventsToProps = (
Expand Down Expand Up @@ -103,7 +98,7 @@ export const constructOrdered = ({
// We don't need to filter the fetched data because it's already filtered and sorted by the
// server. We only need to filter event store state events.
const searchEmojis = getSearchEmojis() as Array<SymbolEmoji>;
const initial = marketDataToProps(markets, searchEmojis);
const initial = marketDataToProps(markets);

// If we're sorting by bump order, deduplicate and sort the events by bump order.
const bumps = stateEventsToProps(stateFirehose, getMarket, searchEmojis);
Expand Down
Loading