-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/evansloan/collectionlog.net
- Loading branch information
Showing
34 changed files
with
14,051 additions
and
9,893 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
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 @@ | ||
nodeLinker: node-modules |
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 |
---|---|---|
@@ -1,21 +1,44 @@ | ||
import React from 'react'; | ||
import { BrowserRouter, Routes, Route } from 'react-router-dom'; | ||
import { createSyncStoragePersister } from '@tanstack/query-sync-storage-persister'; | ||
import { QueryClient } from '@tanstack/react-query'; | ||
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'; | ||
import { PersistQueryClientProvider } from '@tanstack/react-query-persist-client'; | ||
|
||
import { Hiscores, Home, Log } from './pages'; | ||
import { Footer, Header } from './components/layout'; | ||
|
||
const queryClient = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
retry: false, | ||
retryOnMount: false, | ||
refetchOnWindowFocus: false, | ||
cacheTime: 1000 * 60, | ||
staleTime: 1000 * 60, | ||
}, | ||
}, | ||
}); | ||
|
||
const persister = createSyncStoragePersister({ | ||
storage: window.sessionStorage, | ||
}); | ||
|
||
const App = () => ( | ||
<BrowserRouter> | ||
<Header /> | ||
<Routes> | ||
<Route path='/' element={<Home />} /> | ||
<Route path='/log/:username' element={<Log />} /> | ||
<Route path='/log/:username/:entry' element={<Log />} /> | ||
<Route path='/hiscores' element={<Hiscores />} /> | ||
<Route path='/hiscores/:page' element={<Hiscores />} /> | ||
</Routes> | ||
<Footer /> | ||
</BrowserRouter> | ||
<PersistQueryClientProvider client={queryClient} persistOptions={{ persister }} > | ||
<BrowserRouter> | ||
<Header /> | ||
<Routes> | ||
<Route path='/' element={<Home />} /> | ||
<Route path='/log/:username' element={<Log />} /> | ||
<Route path='/log/:username/:pageName' element={<Log />} /> | ||
<Route path='/hiscores' element={<Hiscores />} /> | ||
<Route path='/hiscores/:page' element={<Hiscores />} /> | ||
</Routes> | ||
<Footer /> | ||
</BrowserRouter> | ||
<ReactQueryDevtools initialIsOpen={false} /> | ||
</PersistQueryClientProvider> | ||
); | ||
|
||
export default App; |
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,39 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useEffect, useState } from 'react'; | ||
import { CollectionLogAPI } from '../../api/collection-log/collection-log-api'; | ||
import CollectionLogService from '../../services/collection-log'; | ||
|
||
const api = CollectionLogAPI.getInstance(); | ||
|
||
export const useCollectionLog = (username: string) => { | ||
username = username.toLowerCase(); | ||
const [collectionLogService, setCollectionLogService] = useState<CollectionLogService>(); | ||
const query = useQuery({ | ||
queryKey: ['collection-log', username], | ||
queryFn: async () => await api.getCollectionLog(username), | ||
}); | ||
|
||
useEffect(() => { | ||
if (!query.data) { | ||
return; | ||
} | ||
setCollectionLogService(new CollectionLogService(query.data)); | ||
}, [query.data]); | ||
|
||
return { collectionLog: collectionLogService, ...query }; | ||
}; | ||
|
||
export const useRecentItems = (params: { global?: boolean; username?: string }) => { | ||
const username = params.username?.toLowerCase().trim(); | ||
const query = useQuery({ | ||
queryKey: ['recent-items', username ?? 'global'], | ||
queryFn: async () => { | ||
return params.global | ||
? await api.getRecentItemsGlobal() | ||
: await api.getRecentItems(username as string); | ||
}, | ||
}); | ||
|
||
return { recentItems: query.data, ...query }; | ||
}; | ||
|
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,38 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useState } from 'react'; | ||
import { CollectionLogAPI } from '../../api/collection-log/collection-log-api'; | ||
|
||
const api = CollectionLogAPI.getInstance(); | ||
|
||
export const useRanks = (username: string) => { | ||
username = username.toLowerCase(); | ||
const query = useQuery({ | ||
queryKey: ['ranks', username], | ||
queryFn: async () => await api.getRanksByUsername(username), | ||
}); | ||
|
||
return { ranks: query.data, ...query }; | ||
}; | ||
|
||
export const useHiscores = (page: number, filter: RankType, username?: string) => { | ||
const [hsPage, setHsPage] = useState(page); | ||
const query = useQuery({ | ||
queryKey: ['hiscores', page, filter, username], | ||
queryFn: async () => { | ||
if (username) { | ||
const rank = await api.getRankByUsername(username.toLowerCase().trim(), filter); | ||
page = rank != 0 ? Math.ceil(rank / 25) : 1; | ||
} | ||
|
||
setHsPage(page); | ||
return { hiscores: await api.getHiscores(page, filter), page }; | ||
}, | ||
}); | ||
|
||
return { | ||
...query, | ||
hiscores: query.data?.hiscores, | ||
page: query.data?.page ?? hsPage, | ||
setPage: setHsPage, | ||
}; | ||
}; |
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,13 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import TwitchAPI from '../../api/twitch/twitch-api'; | ||
|
||
const api = TwitchAPI.getInstance(); | ||
|
||
export const useTwitchStreams = () => { | ||
const query = useQuery({ | ||
queryKey: ['twitch-streams'], | ||
queryFn: async () => await api.getStreams(), | ||
}); | ||
|
||
return { ...query, streams: query.data }; | ||
}; |
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,23 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { CollectionLogAPI } from '../../api/collection-log/collection-log-api'; | ||
|
||
const api = CollectionLogAPI.getInstance(); | ||
|
||
export const useUserSettings = (username: string) => { | ||
username = username.toLowerCase().trim(); | ||
const query = useQuery({ | ||
queryKey: ['user-settings', username], | ||
queryFn: async () => await api.getUserSettings(username), | ||
}); | ||
|
||
return { ...query, userSettings: query.data }; | ||
}; | ||
|
||
export const useUserCount = () => { | ||
const query = useQuery({ | ||
queryKey: ['user-count'], | ||
queryFn: async () => await api.getUserCount(), | ||
}); | ||
|
||
return { ...query, userCount: query.data }; | ||
}; |
Oops, something went wrong.