1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2024-12-29 16:07:40 +01:00

Merge pull request #949 from movie-web/feature/#944

Add dismissable banners
This commit is contained in:
William Oldham 2024-02-28 11:31:32 +00:00 committed by GitHub
commit acec24b9b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 3 deletions

View file

@ -10,6 +10,7 @@ export function Banner(props: {
id: string;
}) {
const [ref] = useRegisterBanner<HTMLDivElement>(props.id);
const hideBanner = useBannerStore((s) => s.hideBanner);
const styles = {
error: "bg-[#C93957] text-white",
};
@ -29,6 +30,12 @@ export function Banner(props: {
<Icon icon={icons[props.type]} />
<div>{props.children}</div>
</div>
<span
className="absolute right-4 hover:cursor-pointer"
onClick={() => hideBanner(props.id, true)}
>
<Icon icon={Icons.X} />
</span>
</div>
</div>
);
@ -38,6 +45,7 @@ export function BannerLocation(props: { location?: string }) {
const { t } = useTranslation();
const isOnline = useBannerStore((s) => s.isOnline);
const setLocation = useBannerStore((s) => s.setLocation);
const ignoredBannerIds = useBannerStore((s) => s.ignoredBannerIds);
const currentLocation = useBannerStore((s) => s.location);
const loc = props.location ?? null;
@ -53,7 +61,7 @@ export function BannerLocation(props: { location?: string }) {
return (
<div>
{!isOnline ? (
{!isOnline && !ignoredBannerIds.includes("offline") ? (
<Banner id="offline" type="error">
{t("navigation.banner.offline")}
</Banner>

View file

@ -13,9 +13,10 @@ interface BannerStore {
isOnline: boolean;
isTurnstile: boolean;
location: string | null;
ignoredBannerIds: string[];
updateHeight(id: string, height: number): void;
showBanner(id: string): void;
hideBanner(id: string): void;
hideBanner(id: string, force?: boolean): void;
setLocation(loc: string | null): void;
updateOnline(isOnline: boolean): void;
updateTurnstile(isTurnstile: boolean): void;
@ -27,6 +28,7 @@ export const useBannerStore = create(
isOnline: true,
isTurnstile: false,
location: null,
ignoredBannerIds: [],
updateOnline(isOnline) {
set((s) => {
s.isOnline = isOnline;
@ -45,14 +47,16 @@ export const useBannerStore = create(
showBanner(id) {
set((s) => {
if (s.banners.find((v) => v.id === id)) return;
if (s.ignoredBannerIds.includes(id)) return;
s.banners.push({
id,
height: 0,
});
});
},
hideBanner(id) {
hideBanner(id, force = false) {
set((s) => {
if (force) s.ignoredBannerIds.push(id);
s.banners = s.banners.filter((v) => v.id !== id);
});
},