{"version":3,"file":"useArticle-DDGKtfA0.js","sources":["../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/getMonth.js","../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/getYear.js","../../meteoapi/client/services/ArticleService.ts","../../src/utils/article.ts","../../src/components/weather-report/figure/Image.tsx","../../src/components/weather-report/figure/Figure.tsx","../../src/hooks/useArticle.ts"],"sourcesContent":["import { toDate } from \"./toDate.js\";\n\n/**\n * The {@link getMonth} function options.\n */\n\n/**\n * @name getMonth\n * @category Month Helpers\n * @summary Get the month of the given date.\n *\n * @description\n * Get the month of the given date.\n *\n * @param date - The given date\n * @param options - An object with options\n *\n * @returns The month index (0-11)\n *\n * @example\n * // Which month is 29 February 2012?\n * const result = getMonth(new Date(2012, 1, 29))\n * //=> 1\n */\nexport function getMonth(date, options) {\n return toDate(date, options?.in).getMonth();\n}\n\n// Fallback for modularized imports:\nexport default getMonth;\n","import { toDate } from \"./toDate.js\";\n\n/**\n * The {@link getYear} function options.\n */\n\n/**\n * @name getYear\n * @category Year Helpers\n * @summary Get the year of the given date.\n *\n * @description\n * Get the year of the given date.\n *\n * @param date - The given date\n * @param options - An object with options\n *\n * @returns The year\n *\n * @example\n * // Which year is 2 July 2014?\n * const result = getYear(new Date(2014, 6, 2))\n * //=> 2014\n */\nexport function getYear(date, options) {\n return toDate(date, options?.in).getFullYear();\n}\n\n// Fallback for modularized imports:\nexport default getYear;\n","/* generated using openapi-typescript-codegen -- do not edit */\n/* istanbul ignore file */\n/* tslint:disable */\n/* eslint-disable */\nimport type { Article } from '../models/Article';\nimport type { RegionalSummary } from '../models/RegionalSummary';\nimport type { CancelablePromise } from '../core/CancelablePromise';\nimport { OpenAPI } from '../core/OpenAPI';\nimport { request as __request } from '../core/request';\nexport class ArticleService {\n /**\n * Returns articles by date\n * @returns Article Returned when successful\n * @throws ApiError\n */\n public static getArticleByDate({\n year,\n month,\n day,\n }: {\n year: string,\n month: string,\n day: string,\n }): CancelablePromise
{\n return __request(OpenAPI, {\n method: 'GET',\n url: '/articles/{year}/{month}/{day}',\n path: {\n 'year': year,\n 'month': month,\n 'day': day,\n },\n errors: {\n 404: `Returned when the article does not exist`,\n },\n });\n }\n /**\n * Returns the latest article\n * @returns Article Returned when successful\n * @throws ApiError\n */\n public static getLatestArticle(): CancelablePromise
{\n return __request(OpenAPI, {\n method: 'GET',\n url: '/articles/latest',\n errors: {\n 404: `Returned when the article does not exist`,\n },\n });\n }\n /**\n * Returns latest regional summary\n * @returns RegionalSummary Returned when successful\n * @throws ApiError\n */\n public static getLatestRegionalSummary({\n region,\n }: {\n region: string,\n }): CancelablePromise {\n return __request(OpenAPI, {\n method: 'GET',\n url: '/regional-summary/{region}/latest',\n path: {\n 'region': region,\n },\n errors: {\n 404: `Returned when the regional-summary does not exist`,\n },\n });\n }\n}\n","import { ImageFormat } from \"@Components/weather-report/figure/Image\";\nimport { Image } from \"@MeteoApi/models/Image\";\nimport { getMonth, getYear, isValid } from \"date-fns\";\n\nexport const getArticleDate = () => {\n const date = new Date(\n new URLSearchParams(window.location.hash.slice(1)).get(\"date\") ||\n window.location.hash.slice(1),\n );\n if (isValid(date)) {\n return {\n year: getYear(date).toString(),\n // getMonth returns 0-indexed month, so we need to add 1 to get the correct month demanded by the API\n month: (getMonth(date) + 1).toString(),\n day: date.getDate().toString(),\n };\n } else {\n return \"today\" as const;\n }\n};\n\nexport const getArticleImageUrl = (\n image: Exclude>,\n format: ImageFormat,\n isDarkMode: boolean,\n): string => {\n const { url, url_responsive, url_dark } = image;\n switch (format) {\n case \"compact\":\n return isDarkMode && url_dark ? url_dark : url;\n case \"avatar\":\n return url_responsive ?? url;\n case \"avatar-small\":\n return url_responsive ?? url;\n default:\n return url;\n }\n};\n","import { LayoutType } from \"@Components/weather-report/subsection/SubsectionEntry\";\nimport { Image as ImageModel } from \"@MeteoApi/models/Image\";\nimport { getArticleImageUrl } from \"@Utils/article\";\nimport classNames from \"classnames\";\nimport { useDarkMode } from \"usehooks-ts\";\n\nexport type ImageFormat = LayoutType | \"avatar\" | \"avatar-small\";\nexport type ImageProps = ImageModel & { format: ImageFormat; testId?: string };\n\nconst Image = ({ format, alt_text: altText, testId, ...rest }: ImageProps) => {\n const { isDarkMode } = useDarkMode();\n const src = getArticleImageUrl(rest, format, isDarkMode);\n const title = altText ?? undefined;\n const alt = format === \"avatar\" ? `Profilbild von ${title}` : title;\n\n return (\n \n \n \n );\n};\n\nexport default Image;\n","import Image, { ImageProps } from \"@Components/weather-report/figure/Image\";\nimport classNames from \"classnames\";\n\nconst Figure = ({\n source,\n legend,\n format,\n showCaption = !!legend && format === \"default\",\n testId = \"\",\n ...rest\n}: ImageProps & { showCaption?: boolean }) => (\n \n \n {showCaption && (\n
\n Legende:\n \n {legend}\n \n {source && (\n \n {source.toUpperCase()}\n \n )}\n
\n )}\n \n);\n\nexport default Figure;\n","import { Article } from \"@MeteoApi/models/Article\";\nimport { ArticleService } from \"@MeteoApi/services/ArticleService\";\nimport { getArticleDate } from \"@Utils/article\";\nimport { useEffect, useState } from \"react\";\n\nconst useArticleDate = () => {\n const [articleDate, setArticleDate] = useState(getArticleDate());\n\n useEffect(() => {\n const handleHashChange = () => {\n setArticleDate(getArticleDate());\n };\n\n window.addEventListener(\"hashchange\", handleHashChange);\n\n return () => {\n window.removeEventListener(\"hashchange\", handleHashChange);\n };\n }, []);\n\n return articleDate;\n};\n\nexport const useArticle = () => {\n const articleDate = useArticleDate();\n const [article, setArticle] = useState
();\n const [error, setError] = useState();\n\n const removeLoadingState = () => {\n // remove CMS loading state\n const shimmerBox = document.getElementsByClassName(\"shimmer-box\")[0] as\n | HTMLElement\n | undefined;\n shimmerBox?.style.setProperty(\"display\", \"none\");\n };\n\n useEffect(() => {\n const promise =\n articleDate === \"today\"\n ? ArticleService.getLatestArticle()\n : ArticleService.getArticleByDate(articleDate);\n promise\n .then((article: Article) => {\n setArticle(article);\n removeLoadingState();\n return;\n })\n .catch((e: Error) => {\n // eslint-disable-next-line no-console\n console.error(e);\n setError(e);\n removeLoadingState();\n });\n }, [articleDate]);\n\n return { article, error };\n};\n"],"names":["getMonth","date","options","toDate","getYear","ArticleService","year","month","day","__request","OpenAPI","region","getArticleDate","isValid","getArticleImageUrl","image","format","isDarkMode","url","url_responsive","url_dark","Image","altText","testId","rest","useDarkMode","src","title","alt","jsx","classNames","Figure","source","legend","showCaption","jsxs","useArticleDate","articleDate","setArticleDate","useState","useEffect","handleHashChange","useArticle","article","setArticle","error","setError","removeLoadingState","shimmerBox","e"],"mappings":"ktCAwBO,SAASA,EAASC,EAAMC,EAAS,CACtC,OAAOC,EAAOF,EAAMC,GAAA,YAAAA,EAAS,EAAE,EAAE,SAAU,CAC7C,CCFO,SAASE,EAAQH,EAAMC,EAAS,CACrC,OAAOC,EAAOF,EAAMC,GAAA,YAAAA,EAAS,EAAE,EAAE,YAAa,CAChD,CCjBO,MAAMG,CAAe,CAMxB,OAAc,iBAAiB,CAC3B,KAAAC,EACA,MAAAC,EACA,IAAAC,CAAA,EAK2B,CAC3B,OAAOC,EAAUC,EAAS,CACtB,OAAQ,MACR,IAAK,iCACL,KAAM,CACF,KAAQJ,EACR,MAASC,EACT,IAAOC,CACX,EACA,OAAQ,CACJ,IAAK,0CAAA,CACT,CACH,CAAA,CAOL,OAAc,kBAA+C,CACzD,OAAOC,EAAUC,EAAS,CACtB,OAAQ,MACR,IAAK,mBACL,OAAQ,CACJ,IAAK,0CAAA,CACT,CACH,CAAA,CAOL,OAAc,yBAAyB,CACnC,OAAAC,CAAA,EAGmC,CACnC,OAAOF,EAAUC,EAAS,CACtB,OAAQ,MACR,IAAK,oCACL,KAAM,CACF,OAAUC,CACd,EACA,OAAQ,CACJ,IAAK,mDAAA,CACT,CACH,CAAA,CAET,CCpEO,MAAMC,EAAiB,IAAM,CAClC,MAAMX,EAAO,IAAI,KACf,IAAI,gBAAgB,OAAO,SAAS,KAAK,MAAM,CAAC,CAAC,EAAE,IAAI,MAAM,GAC3D,OAAO,SAAS,KAAK,MA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