From fae39b16f094ebfac89feda93e641814bd55f956 Mon Sep 17 00:00:00 2001 From: mantou132 <709922234@qq.com> Date: Sat, 14 Oct 2023 23:07:43 +0800 Subject: [PATCH] Fixed recent game count for width screen --- packages/webapp/src/modules/game-list.ts | 7 +++++-- packages/webapp/src/pages/games.ts | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/webapp/src/modules/game-list.ts b/packages/webapp/src/modules/game-list.ts index 0d13a6d3..46ea133c 100644 --- a/packages/webapp/src/modules/game-list.ts +++ b/packages/webapp/src/modules/game-list.ts @@ -9,6 +9,7 @@ import { boolattribute, repeat, styleMap, + numattribute, } from '@mantou/gem'; import { isNotNullish } from 'duoyun-ui/lib/types'; import { mediaQuery } from '@mantou/gem/helper/mediaquery'; @@ -78,6 +79,7 @@ export class MGameListElement extends GemElement { @boolattribute recent: boolean; @boolattribute new: boolean; @boolattribute all: boolean; + @numattribute length: number; constructor() { super(); @@ -93,9 +95,9 @@ export class MGameListElement extends GemElement { get #data() { if (this.new) { - return store.gameIds?.slice(store.gameIds.length - 4).reverse(); + return store.gameIds?.slice(store.gameIds.length - this.length).reverse(); } else if (this.recent) { - return store.recentGameIds?.slice(0, 4); + return store.recentGameIds?.slice(0, this.length); } else if (this.favorite) { return store.favoriteIds; } else { @@ -153,6 +155,7 @@ export class MGameListElement extends GemElement { } }, () => [ + this.length, store.topGameIds, // mt app need immediately update isMtApp && store.favoriteIds, diff --git a/packages/webapp/src/pages/games.ts b/packages/webapp/src/pages/games.ts index 66dc24e8..d07a74ec 100644 --- a/packages/webapp/src/pages/games.ts +++ b/packages/webapp/src/pages/games.ts @@ -125,6 +125,12 @@ export class PGamesElement extends GemElement { #canvas = document.createElement('canvas'); + #media = matchMedia('(width > 1024px)'); + + get #gamesLength() { + return this.#media.matches ? 5 : 4; + } + #getBackgroundImageUrl = async (text: string) => { await fontLoading(pixelFont); const font = `bold 10px '${pixelFont.family}', sans-serif`; @@ -166,6 +172,10 @@ export class PGamesElement extends GemElement { }); }; + mounted = () => { + this.#media.onchange = this.update; + }; + render = () => { const topData = store.topGameIds?.map((id) => ({ onClick: (evt: PointerEvent) => { @@ -192,8 +202,8 @@ export class PGamesElement extends GemElement { .interval=${7000} @change=${({ detail }: CustomEvent) => this.#onTopChange(detail, topData?.length)} > - - + + `; };