Skip to content

Commit

Permalink
fix(source): set isHome value for the home data object
Browse files Browse the repository at this point in the history
  • Loading branch information
DAreRodz committed Jul 11, 2019
1 parent 31d34e4 commit 9af88b4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 0 additions & 2 deletions packages/source/src/__tests__/data.tests.ts
Expand Up @@ -98,7 +98,6 @@ const postArchive: PostArchiveData = {
isPostTypeArchive: true,
isPostArchive: true,
isHome: true,
isFrontPage: true,
type: "post",
items: [],
isReady: true,
Expand Down Expand Up @@ -138,7 +137,6 @@ const page: PageData = {
isPage: true,
type: "page",
id: 11,
isFrontPage: false,
isReady: true,
isFetching: false
};
Expand Down
4 changes: 1 addition & 3 deletions packages/source/src/data.ts
Expand Up @@ -38,6 +38,7 @@ export type BaseData = {
isPost?: false;
isPage?: false;
isAttachment?: false;
isHome?: boolean;
};

// NOT FOUND
Expand Down Expand Up @@ -106,8 +107,6 @@ export type PostArchiveData = Merge<
PostTypeArchiveData,
{
isPostArchive: true;
isHome: boolean;
isFrontPage?: boolean;
}
>;

Expand Down Expand Up @@ -145,7 +144,6 @@ export type PageData = Merge<
{
type: "page";
isPage: true;
isFrontPage?: boolean;
}
>;

Expand Down
6 changes: 5 additions & 1 deletion packages/wp-source/src/actions.ts
Expand Up @@ -27,8 +27,10 @@ const actions: WpSource["actions"]["source"] = {

// get and execute the corresponding handler based on path
try {
// transform path if there is some redirection
let { path } = routeParams;
// check if this is the homepage URL
const isHome = path === normalize(state.source.subdirectory || "/");
// transform path if there is some redirection
const redirection = getMatch(path, redirections);
if (redirection) path = redirection.func(redirection.params);

Expand All @@ -41,6 +43,8 @@ const actions: WpSource["actions"]["source"] = {
isFetching: false,
isReady: true
};
// set isHome value if it's true
if (isHome) source.data[route].isHome = true;
} catch (e) {
console.log(e);
// an error happened
Expand Down

0 comments on commit 9af88b4

Please sign in to comment.