-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: pull events from buddydatasheets
- Loading branch information
Showing
18 changed files
with
1,087 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Link } from "@/components/link"; | ||
import Markdown from "react-markdown"; | ||
import { z } from "zod"; | ||
|
||
export const SHEETS = { | ||
Timers: { | ||
gid: 0, | ||
schema: z.array( | ||
z.object({ | ||
title: z.string(), | ||
description: z.string().transform((x) => ( | ||
<Markdown | ||
components={{ | ||
a(props) { | ||
const { children, ...rest } = props; | ||
return <Link {...rest}>{children}</Link>; | ||
}, | ||
}} | ||
> | ||
{x} | ||
</Markdown> | ||
)), | ||
type: z.enum(["maintenance", "event", "reset"]), | ||
start: z.string().transform((x) => new Date(x).getTime()), | ||
end: z.string().transform((x) => new Date(x).getTime()), | ||
}), | ||
), | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { SHEETS } from "@/api/buddy-data-sheets"; | ||
import { queryClient } from "@/api/query-client"; | ||
import axios from "axios"; | ||
import { parse } from "papaparse"; | ||
|
||
export type BuddyDataSheets = keyof typeof SHEETS; | ||
|
||
const buddyData = axios.create({ | ||
baseURL: | ||
"https://docs.google.com/spreadsheets/d/e/2PACX-1vT6RyWZRbuYrNfSnbHEa2PBXgETOgZtfhYgN6QlTqDr5PRVM9IlG93otgT_S_cppwdxAhoIqTc_EAsM", | ||
method: "GET", | ||
headers: {}, | ||
}); | ||
|
||
const urlParams = (gid: number) => `pub?single=true&output=csv&gid=${gid}`; | ||
|
||
export const queryBuddyData = async (sheet: BuddyDataSheets) => { | ||
const { data } = await buddyData({ | ||
url: urlParams(SHEETS[sheet].gid), | ||
}); | ||
|
||
console.log(parse(data, { header: true }).data); | ||
|
||
return SHEETS[sheet].schema.parse(parse(data, { header: true }).data); | ||
}; | ||
|
||
export const ensureBuddyData = async (sheet: BuddyDataSheets) => | ||
await queryClient.ensureQueryData({ | ||
queryKey: ["buddyData", sheet], | ||
queryFn: () => queryBuddyData(sheet), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { MINUTE, SECOND, WEEK } from "@/constants/time"; | ||
import { createSyncStoragePersister } from "@tanstack/query-sync-storage-persister"; | ||
import { QueryClient } from "@tanstack/react-query"; | ||
import { removeOldestQuery } from "@tanstack/react-query-persist-client"; | ||
import { compress, decompress } from "lz-string"; | ||
|
||
const CACHE_MAX_AGE = 2 * WEEK; | ||
const MAX_RETRY_DELAY = 64 * SECOND; | ||
|
||
export const queryClient = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
gcTime: CACHE_MAX_AGE, | ||
staleTime: 5 * SECOND, | ||
retry: true, | ||
retryDelay: (attemptIndex) => | ||
attemptIndex < 6 | ||
? Math.min( | ||
Math.ceil(SECOND * (2 ** attemptIndex + Math.random())), | ||
MAX_RETRY_DELAY, | ||
) | ||
: MAX_RETRY_DELAY, | ||
refetchInterval: MINUTE, | ||
}, | ||
}, | ||
}); | ||
|
||
const persister = createSyncStoragePersister({ | ||
storage: window.localStorage, | ||
retry: removeOldestQuery, | ||
key: "FFXIV Buddy React Query Persister", | ||
serialize: (data) => compress(JSON.stringify(data)), | ||
deserialize: (data) => JSON.parse(decompress(data)), | ||
}); | ||
|
||
export const persistOptions = { persister, maxAge: CACHE_MAX_AGE }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { BuddyDataSheets, queryBuddyData } from "@/api/buddy-data"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
|
||
export const useQueryBuddyData = (sheet: BuddyDataSheets) => { | ||
return useQuery({ | ||
queryKey: ["buddyData", sheet], | ||
queryFn: () => queryBuddyData(sheet), | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
import { cn } from "@/utils/cn"; | ||
import { PropsWithChildren } from "react"; | ||
import { Helmet } from "react-helmet-async"; | ||
|
||
interface PageProps extends PropsWithChildren { | ||
className?: string; | ||
title?: string; | ||
} | ||
|
||
export default function Page({ children, className }: PageProps) { | ||
return <section className={cn("mx-auto", className)}>{children}</section>; | ||
export default function Page({ children, className, title }: PageProps) { | ||
return ( | ||
<section className={cn("mx-auto", className)}> | ||
{title && ( | ||
<Helmet> | ||
<title>{title}</title> | ||
</Helmet> | ||
)} | ||
{children} | ||
</section> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { ensureBuddyData } from "@/api/buddy-data"; | ||
import { Component } from "@/routes/timers/timers"; | ||
|
||
export const loader = async () => await ensureBuddyData("Timers"); | ||
|
||
export { Component }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters