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-2544] Clean up package code before publishing; remove lots of unused code #439

Merged
merged 18 commits into from
Dec 5, 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
12 changes: 4 additions & 8 deletions src/python/move_emojis/scripts/generate_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
)
TYPESCRIPT_SYMBOL_EMOJIS_PATH = os.path.join(
TYPESCRIPT_PATH_DIR,
"symbol-emojis.json",
"symbol-emojis.ts",
)
TYPESCRIPT_CHAT_EMOJIS_PATH = os.path.join(
TYPESCRIPT_PATH_DIR,
"chat-emojis.json",
"chat-emojis.ts",
)
TYPESCRIPT_SYMBOL_NAMES_PATH = os.path.join(
TYPESCRIPT_PATH_DIR,
Expand Down Expand Up @@ -125,11 +125,11 @@ def ensure_write_to_file(data: str | dict[str, Any] | list[str], fp: str):
fp_obj = pathlib.Path(fp)
pathlib.Path(fp_obj.parent).mkdir(exist_ok=True)

with open(fp, "w") as outfile:
with open(fp, "w", encoding="utf-8") as outfile:
if isinstance(data, str):
_ = outfile.write(data)
else:
json.dump(data, outfile, indent=2)
json.dump(data, outfile, indent=2, ensure_ascii=False)


if __name__ == "__main__":
Expand Down Expand Up @@ -159,12 +159,8 @@ def ensure_write_to_file(data: str | dict[str, Any] | list[str], fp: str):
ensure_write_to_file(symbol_emojis, SYMBOL_EMOJIS_ALL_DATA_PATH)
typescript_symbol_emojis = as_emoji_to_name_dict(symbol_emojis)
typescript_chat_emojis = as_emoji_to_name_dict(extended_emojis)
typescript_symbol_names = {k: None for k in typescript_symbol_emojis.values()}
typescript_chat_names = {k: None for k in typescript_chat_emojis.values()}
ensure_write_to_file(typescript_symbol_emojis, TYPESCRIPT_SYMBOL_EMOJIS_PATH)
ensure_write_to_file(typescript_symbol_names, TYPESCRIPT_SYMBOL_NAMES_PATH)
ensure_write_to_file(typescript_chat_emojis, TYPESCRIPT_CHAT_EMOJIS_PATH)
ensure_write_to_file(typescript_chat_names, TYPESCRIPT_CHAT_NAMES_PATH)
# The rust processor uses the `symbol-emojis.json` data at build time, so if the
# path for the directory exists, output the data there as well.
if pathlib.Path(RUST_JSON_PATH).parent.exists():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,59 +1,17 @@
import { type SymbolEmojiData } from "@sdk/emoji_data/types";
import { useGenerateEvent } from "../../test-generate-event/use-generate-event";
import { type PropsWithChildren } from "react";
import { ROUTES } from "router/routes";
import { emojiNamesToPath } from "utils/pathname-helpers";
import Link from "next/link";
import { VERCEL } from "@sdk/const";
import React from "react";

/**
* To facilitate easy visual testing, we swap out the link on the grid table card with a div that triggers a
* random event when clicked. Note that the test click div will never render in Vercel build mode or in
* production. You also have to set a specific environment variable to true.
*
* We put this component in the grid table card component so that when the user clicks on the card, it will
* trigger the event (or navigate to the market page if not in test mode).
*
* @returns {JSX.Element} The link that goes to the market page, or if in test, the div that emulates triggering a
* random event in our event state store.
*/
export const GenerateEventComponent = ({
export const EmojiMarketPageLink = ({
emojis,
marketID,
...props
}: { emojis: SymbolEmojiData[]; marketID: number } & PropsWithChildren) => {
// Note that without `stateOnly: true`, the event could conflict with other events. This may cause
// visual artifacts that won't actually appear with real data.
const generateEvent = useGenerateEvent({ marketID, emojis, stateOnly: true });
}: { emojis: SymbolEmojiData[] } & PropsWithChildren) => (
<Link href={`${ROUTES.market}/${emojiNamesToPath(emojis.map((x) => x.name))}`}>
{props.children}
</Link>
);

return (
<>
<div onClick={generateEvent}>{props.children}</div>
</>
);
};

export const LinkOrAnimationTrigger = ({
emojis,
marketID,
...props
}: { emojis: SymbolEmojiData[]; marketID: number } & PropsWithChildren) => {
return (
<>
{VERCEL ||
process.env.NODE_ENV === "production" ||
process.env.NEXT_PUBLIC_ANIMATION_TEST !== "true" ? (
<Link href={`${ROUTES.market}/${emojiNamesToPath(emojis.map((x) => x.name))}`}>
{props.children}
</Link>
) : (
<GenerateEventComponent emojis={emojis} marketID={marketID}>
{props.children}
</GenerateEventComponent>
)}
</>
);
};

export default React.memo(LinkOrAnimationTrigger);
export default React.memo(EmojiMarketPageLink);
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
LAYOUT_DURATION,
tableCardVariants,
} from "./animation-variants/grid-variants";
import LinkOrAnimationTrigger from "./LinkOrAnimationTrigger";
import EmojiMarketPageLink from "./LinkOrAnimationTrigger";
import { type SymbolEmojiData } from "@sdk/emoji_data";
import { Emoji } from "utils/emoji";
import { SortMarketsBy } from "@sdk/indexer-v2/types/common";
Expand Down Expand Up @@ -205,7 +205,7 @@ const TableCard = ({
}}
{...props}
>
<LinkOrAnimationTrigger emojis={emojis} marketID={marketID}>
<EmojiMarketPageLink emojis={emojis}>
<motion.div
animate={controls}
variants={animationsOn ? glowVariants : {}}
Expand Down Expand Up @@ -290,7 +290,7 @@ const TableCard = ({
</Flex>
</motion.div>
</motion.div>
</LinkOrAnimationTrigger>
</EmojiMarketPageLink>
</motion.div>
);
};
Expand Down
Loading
Loading