fix: inline card server name overflow

This commit is contained in:
hamster1963 2024-12-06 09:49:02 +08:00
parent 8261bd841e
commit 560bcea0b8
5 changed files with 52 additions and 49 deletions

1
.gitignore vendored
View File

@ -10,6 +10,7 @@ lerna-debug.log*
node_modules node_modules
dist dist
dist-ssr dist-ssr
dev-dist
*.local *.local
# Editor directories and files # Editor directories and files

View File

@ -1,22 +1,24 @@
import { useRegisterSW } from 'virtual:pwa-register/react'; import { useRegisterSW } from "virtual:pwa-register/react";
import { useTranslation } from 'react-i18next'; import { useTranslation } from "react-i18next";
import { toast } from 'sonner'; import { toast } from "sonner";
function ReloadPrompt() { function ReloadPrompt() {
const { t } = useTranslation(); const { t } = useTranslation();
const { const {
needRefresh: [needRefresh, setNeedRefresh], needRefresh: [needRefresh, setNeedRefresh],
updateServiceWorker, updateServiceWorker,
} = useRegisterSW({ } = useRegisterSW({
onRegisteredSW(swUrl) { onRegisteredSW(swUrl) {
console.log(`SW Registered: ${swUrl} (Version: ${import.meta.env.VITE_GIT_HASH})`); console.log(
`SW Registered: ${swUrl} (Version: ${import.meta.env.VITE_GIT_HASH})`,
);
}, },
onRegisterError(error) { onRegisterError(error) {
console.log('SW registration error', error); console.log("SW registration error", error);
}, },
onOfflineReady() { onOfflineReady() {
toast.success(t('pwa.offlineReady')); toast.success(t("pwa.offlineReady"));
}, },
}); });
@ -32,19 +34,14 @@ function ReloadPrompt() {
return null; return null;
} }
toast.message(`${t("pwa.newContent")} (${import.meta.env.VITE_GIT_HASH})`, {
action: {
toast.message( label: t("pwa.reload"),
`${t('pwa.newContent')} (${import.meta.env.VITE_GIT_HASH})`, onClick: () => update(),
{ },
action: { onDismiss: close,
label: t('pwa.reload'), duration: Infinity,
onClick: () => update(), });
},
onDismiss: close,
duration: Infinity,
}
);
return null; return null;
} }

View File

@ -82,7 +82,7 @@ export default function ServerCardInline({
> >
{showFlag ? <ServerFlag country_code={country_code} /> : null} {showFlag ? <ServerFlag country_code={country_code} /> : null}
</div> </div>
<div className="relative flex flex-col"> <div className="relative w-24 flex flex-col">
<p <p
className={cn( className={cn(
"break-all font-bold tracking-tight", "break-all font-bold tracking-tight",
@ -226,7 +226,7 @@ export default function ServerCardInline({
<div className="relative"> <div className="relative">
<p <p
className={cn( className={cn(
"break-all font-bold tracking-tight", "break-all font-bold w-24 tracking-tight",
showFlag ? "text-xs" : "text-sm", showFlag ? "text-xs" : "text-sm",
)} )}
> >

29
src/vite-env.d.ts vendored
View File

@ -1,22 +1,27 @@
/// <reference types="vite/client" /> /// <reference types="vite/client" />
declare module 'virtual:pwa-register/react' { declare module "virtual:pwa-register/react" {
import type { Dispatch, SetStateAction } from 'react' import type { Dispatch, SetStateAction } from "react";
export interface RegisterSWOptions { export interface RegisterSWOptions {
immediate?: boolean immediate?: boolean;
onNeedRefresh?: () => void onNeedRefresh?: () => void;
onOfflineReady?: () => void onOfflineReady?: () => void;
onRegistered?: (registration: ServiceWorkerRegistration | undefined) => void onRegistered?: (
onRegisteredSW?: (swScriptUrl: string, registration: ServiceWorkerRegistration | undefined) => void registration: ServiceWorkerRegistration | undefined,
onRegisterError?: (error) => void ) => void;
onRegisteredSW?: (
swScriptUrl: string,
registration: ServiceWorkerRegistration | undefined,
) => void;
onRegisterError?: (error) => void;
} }
export interface RegisterSWHook { export interface RegisterSWHook {
needRefresh: [boolean, Dispatch<SetStateAction<boolean>>] needRefresh: [boolean, Dispatch<SetStateAction<boolean>>];
offlineReady: [boolean, Dispatch<SetStateAction<boolean>>] offlineReady: [boolean, Dispatch<SetStateAction<boolean>>];
updateServiceWorker: (reloadPage?: boolean) => Promise<void> updateServiceWorker: (reloadPage?: boolean) => Promise<void>;
} }
export function useRegisterSW(options?: RegisterSWOptions): RegisterSWHook export function useRegisterSW(options?: RegisterSWOptions): RegisterSWHook;
} }

View File

@ -57,38 +57,38 @@ export default defineConfig({
runtimeCaching: [ runtimeCaching: [
{ {
urlPattern: /^https:\/\/fonts\.googleapis\.com\/.*/i, urlPattern: /^https:\/\/fonts\.googleapis\.com\/.*/i,
handler: 'CacheFirst', handler: "CacheFirst",
options: { options: {
cacheName: 'google-fonts-cache', cacheName: "google-fonts-cache",
expiration: { expiration: {
maxEntries: 10, maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 365 // <== 365 days maxAgeSeconds: 60 * 60 * 24 * 365, // <== 365 days
}, },
cacheableResponse: { cacheableResponse: {
statuses: [0, 200] statuses: [0, 200],
} },
} },
}, },
{ {
urlPattern: /^https:\/\/fonts\.gstatic\.com\/.*/i, urlPattern: /^https:\/\/fonts\.gstatic\.com\/.*/i,
handler: 'CacheFirst', handler: "CacheFirst",
options: { options: {
cacheName: 'gstatic-fonts-cache', cacheName: "gstatic-fonts-cache",
expiration: { expiration: {
maxEntries: 10, maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 365 // <== 365 days maxAgeSeconds: 60 * 60 * 24 * 365, // <== 365 days
}, },
cacheableResponse: { cacheableResponse: {
statuses: [0, 200] statuses: [0, 200],
} },
} },
}, },
] ],
}, },
devOptions: { devOptions: {
enabled: true, enabled: true,
type: 'module' type: "module",
} },
}), }),
], ],
resolve: { resolve: {