Commit 7a7c2e86 authored by Chunchi Che's avatar Chunchi Che

move getCardImgUrl under api path

parent 595e4e0e
import { useConfig } from "@/config";
import sqliteMiddleWare, { sqliteCmd } from "@/middleware/sqlite"; import sqliteMiddleWare, { sqliteCmd } from "@/middleware/sqlite";
import { FtsParams } from "@/middleware/sqlite/fts"; import { FtsParams } from "@/middleware/sqlite/fts";
import { isSuperReleaseCard } from "./superPreRelease";
const NeosConfig = useConfig();
export interface CardMeta { export interface CardMeta {
id: number; id: number;
data: CardData; data: CardData;
...@@ -71,3 +76,19 @@ export function getCardStr(meta: CardMeta, idx: number): string | undefined { ...@@ -71,3 +76,19 @@ export function getCardStr(meta: CardMeta, idx: number): string | undefined {
const str = `str${idx + 1}` as CardStrRange; const str = `str${idx + 1}` as CardStrRange;
return meta.text[str]; return meta.text[str];
} }
export function getCardImgUrl(code: number, back = false) {
const ASSETS_BASE =
import.meta.env.BASE_URL === "/"
? NeosConfig.assetsPath
: `${import.meta.env.BASE_URL}${NeosConfig.assetsPath}`;
if (back || code === 0) {
return `${ASSETS_BASE}/card_back.jpg`;
}
if (isSuperReleaseCard(code)) {
return `${NeosConfig.preReleaseImgUrl}/${code}.jpg`;
} else {
return `${NeosConfig.releaseImgUrl}/${code}.jpg`;
}
}
...@@ -3,10 +3,14 @@ import { Avatar, Button, Checkbox, Input, List } from "antd"; ...@@ -3,10 +3,14 @@ import { Avatar, Button, Checkbox, Input, List } from "antd";
import React, { useState } from "react"; import React, { useState } from "react";
import { proxy, useSnapshot } from "valtio"; import { proxy, useSnapshot } from "valtio";
import { CardMeta, searchCards, sendSelectOptionResponse } from "@/api"; import {
CardMeta,
getCardImgUrl,
searchCards,
sendSelectOptionResponse,
} from "@/api";
import { isDeclarable, isToken } from "@/common"; import { isDeclarable, isToken } from "@/common";
import { emptySearchConditions } from "@/middleware/sqlite/fts"; import { emptySearchConditions } from "@/middleware/sqlite/fts";
import { getCardImgUrl } from "@/ui/Shared";
import { NeosModal } from "../NeosModal"; import { NeosModal } from "../NeosModal";
import styles from "./index.module.scss"; import styles from "./index.module.scss";
......
...@@ -21,8 +21,7 @@ import React, { useEffect, useState } from "react"; ...@@ -21,8 +21,7 @@ import React, { useEffect, useState } from "react";
import { proxy, useSnapshot } from "valtio"; import { proxy, useSnapshot } from "valtio";
import { sendSortCardResponse } from "@/api"; import { sendSortCardResponse } from "@/api";
import { CardMeta } from "@/api/cards"; import { CardMeta, getCardImgUrl } from "@/api/cards";
import { getCardImgUrl } from "@/ui/Shared";
import { NeosModal } from "../NeosModal"; import { NeosModal } from "../NeosModal";
......
import classNames from "classnames"; import classNames from "classnames";
import { CSSProperties, useMemo } from "react"; import { CSSProperties, useMemo } from "react";
import { isSuperReleaseCard } from "@/api"; import { getCardImgUrl } from "@/api";
import { useConfig } from "@/config";
import styles from "./index.module.scss"; import styles from "./index.module.scss";
...@@ -10,6 +9,7 @@ interface Props { ...@@ -10,6 +9,7 @@ interface Props {
className?: string; className?: string;
isBack?: boolean; isBack?: boolean;
code?: number; code?: number;
targeted?: boolean;
// cardName?: string; // cardName?: string;
style?: CSSProperties; style?: CSSProperties;
width?: number | string; width?: number | string;
...@@ -50,22 +50,3 @@ export const YgoCard: React.FC<Props> = (props) => { ...@@ -50,22 +50,3 @@ export const YgoCard: React.FC<Props> = (props) => {
[code], [code],
); );
}; };
const NeosConfig = useConfig();
// TODO: 这个函数应该从这个文件抽离出来作为公共的函数使用
export function getCardImgUrl(code: number, back = false) {
const ASSETS_BASE =
import.meta.env.BASE_URL === "/"
? NeosConfig.assetsPath
: `${import.meta.env.BASE_URL}${NeosConfig.assetsPath}`;
if (back || code === 0) {
return `${ASSETS_BASE}/card_back.jpg`;
}
if (isSuperReleaseCard(code)) {
return `${NeosConfig.preReleaseImgUrl}/${code}.jpg`;
} else {
return `${NeosConfig.releaseImgUrl}/${code}.jpg`;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment