-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(content): fetch and store dataset in content cache (#33)
* feat(content): fetch and store dataset in content cache * test(content): fix failing tests * test(content): add tests for dataset caching
- Loading branch information
1 parent
a379a98
commit 72cf484
Showing
6 changed files
with
172 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,39 @@ | ||
import { Page } from "fsxa-api"; | ||
import { Page, Dataset } from "fsxa-api"; | ||
|
||
export function useContent() { | ||
const currentDataset = useState<Dataset | null>("currentDataset"); | ||
const cachedDatasets = useState<{ | ||
[caasId: string]: Dataset; | ||
}>("cachedDatasets", () => ({})); | ||
|
||
function findCachedDatasetByRoute(route: string) { | ||
return cachedDatasets.value[route]; | ||
} | ||
function addToCachedDatasets(route: string, data: Dataset) { | ||
if (!cachedPages.value[route]) cachedDatasets.value[route] = data; | ||
} | ||
|
||
const currentPage = useState<Page | null>("currentPage"); | ||
const cachedPages = useState<{ | ||
[caasId: string]: Page; | ||
}>("cachedPages", () => ({})); | ||
|
||
function findCachedPageBySeoRoute(seoRoute: string) { | ||
return cachedPages.value[seoRoute]; | ||
function findCachedPageByRoute(route: string) { | ||
return cachedPages.value[route]; | ||
} | ||
|
||
function addToCache(seoRoute: string, data: Page) { | ||
if (!cachedPages.value[seoRoute]) cachedPages.value[seoRoute] = data; | ||
function addToCachedPages(route: string, data: Page) { | ||
if (!cachedPages.value[route]) cachedPages.value[route] = data; | ||
} | ||
|
||
return { | ||
currentPage, | ||
currentDataset, | ||
cachedPages, | ||
addToCache, | ||
findCachedPageBySeoRoute, | ||
cachedDatasets, | ||
addToCachedPages, | ||
addToCachedDatasets, | ||
findCachedPageByRoute, | ||
findCachedDatasetByRoute, | ||
}; | ||
} |
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
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
Oops, something went wrong.