diff --git a/packages/client/src/interface/channels/AgeGate.tsx b/packages/client/src/interface/channels/AgeGate.tsx index d9dce8de..077f4e37 100644 --- a/packages/client/src/interface/channels/AgeGate.tsx +++ b/packages/client/src/interface/channels/AgeGate.tsx @@ -1,14 +1,20 @@ -import { JSXElement, Match, Switch, createEffect } from "solid-js"; +import { JSXElement, Match, Suspense, Switch } from "solid-js"; import { Trans } from "@lingui-solid/solid/macro"; +import { useQuery } from "@tanstack/solid-query"; import { styled } from "styled-system/jsx"; import { useState } from "@revolt/state"; import { LAYOUT_SECTIONS } from "@revolt/state/stores/Layout"; -import { Button, Checkbox, iconSize } from "@revolt/ui"; +import { Button, Checkbox, CircularProgress, Text, iconSize } from "@revolt/ui"; import MdWarning from "@material-design-icons/svg/round/warning.svg?component-solid"; +type GeoBlock = { + countryCode: string; + isAgeRestrictedGeo: boolean; +}; + /** * Age gate filter for any content */ @@ -21,53 +27,101 @@ export function AgeGate(props: { }) { const state = useState(); - const confirmed = state.layout.getSectionState(LAYOUT_SECTIONS.MATURE, false); - const allowed = state.layout.getSectionState( - props.contentId + "-nsfw", - false, - ); + const confirmed = () => + state.layout.getSectionState(LAYOUT_SECTIONS.MATURE, false); + const allowed = () => + state.layout.getSectionState(props.contentId + "-nsfw", false); + + const geoQuery = useQuery(() => ({ + queryKey: ["geoblock"], + queryFn: async (): Promise => { + const response = await fetch("https://geo.revolt.chat"); + if (!response.ok) { + throw new Error("Failed to fetch geo data"); + } + return response.json(); + }, + staleTime: 5 * 60 * 1000, // 5 minutes + throwOnError: true, + })); return ( - - - - - {props.contentName} - - This channel is marked as mature. - - - - }> + + + + + + {props.contentName} + + + + {geoQuery.data?.countryCode == "GB" ? ( + + This channel is not available in your region while we review + options on legal compliance. + + ) : ( + This content is not available in your region. )} - onChange={() => - state.layout.toggleSectionState(LAYOUT_SECTIONS.MATURE, false) - } - /> + - I confirm that I am at least 18 years old. - - - - - - - - - + + + + + + + {props.contentName} + + + + This channel is marked as mature. + + + + + state.layout.toggleSectionState(LAYOUT_SECTIONS.MATURE, false) + } + /> + + I confirm that I am at least 18 years old. + + + + + + + + + + + ); } @@ -82,27 +136,17 @@ const Base = styled("div", { padding: "var(--gap-lg)", userSelect: "none", overflowY: "auto", + color: "var(--md-sys-color-on-surface)", "& svg": { // TODO fill: "orange", }, - gap: "var(--gap-sm)", - }, -}); - -const Title = styled("h2", { - base: { - fontSize: "2em", - fontWeight: "black", + gap: "var(--gap-md)", }, }); -const SubText = styled("span", { - base: {}, -}); - const Confirmation = styled("label", { base: { display: "flex",