oxen-website/state/navigation.ts

93 lines
2.3 KiB
TypeScript
Raw Normal View History

2021-02-08 00:25:27 +01:00
import { ISplitPage } from '../types/cms';
2021-02-11 01:38:40 +01:00
export enum SideMenuItem {
BUILD = 'BUILD',
BUY_OXEN = 'BUY_OXEN',
WHO_ARE_WE = 'WHO_ARE_WE',
STAKE = 'STAKE',
USES = 'USES',
SESSION_LOKINET = 'SESSION_LOKINET',
GET_INVOLVED = 'GET_INVOLVED',
2021-02-18 04:07:53 +01:00
ROADMAP = 'ROADMAP',
2021-02-11 01:38:40 +01:00
}
2021-02-08 00:25:27 +01:00
export type TPages = {
[name: string]: ISplitPage;
};
2021-01-22 03:43:42 +01:00
export interface INavigation {
2021-02-09 04:22:35 +01:00
pageType: PageType;
2021-02-09 05:31:56 +01:00
postTitle?: string;
2021-02-10 02:04:00 +01:00
headerCollapsed: boolean;
sideMenuExpanded: boolean;
headerMobileMenuExpanded: boolean;
2021-02-08 00:25:27 +01:00
pages?: TPages;
2021-01-22 03:43:42 +01:00
}
2021-02-09 04:22:35 +01:00
export enum PageType {
NORMAL = 'NORMAL',
BLOG = 'BLOG',
POST = 'POST',
}
2021-01-22 03:43:42 +01:00
export const initialNavigationState: INavigation = {
2021-02-01 07:02:12 +01:00
// Side menu expanded only toggles for mobile.
// On desktop it's always open (if it fits).
2021-02-09 04:22:35 +01:00
pageType: PageType.NORMAL,
2021-02-09 05:31:56 +01:00
postTitle: undefined,
2021-02-08 07:37:50 +01:00
headerCollapsed: true,
2021-02-01 07:02:12 +01:00
sideMenuExpanded: false,
2021-02-10 02:04:00 +01:00
headerMobileMenuExpanded: false,
2021-01-22 03:43:42 +01:00
};
export enum NavigationActions {
2021-02-08 07:37:50 +01:00
SET_HEADER_COLLAPSED = 'SET_HEADER_COLLAPSED',
2021-02-09 04:22:35 +01:00
SET_PAGE_TYPE = 'SET_PAGE_TYPE',
2021-02-09 05:31:56 +01:00
SET_POST_TITLE = 'SET_POST_TITLE',
2021-02-01 07:02:12 +01:00
EXPAND_SIDE_MENU = 'EXPAND_SIDE_MENU',
COLLAPSE_SIDE_MENU = 'COLLAPSE_SIDE_MENU',
2021-02-08 00:25:27 +01:00
SET_SPLIT_PAGES_CONTENT = 'SET_SPLIT_PAGES_CONTENT',
2021-02-10 02:04:00 +01:00
EXPAND_MOBILE_HEADER_MENU = 'EXPAND_MOBILE_HEADER_MENU',
COLLAPSE_MOBILE_HEADER_MENU = 'COLLAPSE_MOBILE_HEADER_MENU',
2021-01-22 03:43:42 +01:00
}
// ////////////////////////////// //
// Action Creators //
// ////////////////////////////// //
2021-02-08 07:37:50 +01:00
export const setHeaderCollapsed = (collapsed: boolean) => ({
type: NavigationActions.SET_HEADER_COLLAPSED,
payload: collapsed,
});
2021-02-09 04:22:35 +01:00
export const setPageType = (type: PageType) => ({
type: NavigationActions.SET_PAGE_TYPE,
payload: type,
2021-02-08 01:20:21 +01:00
});
2021-02-09 05:31:56 +01:00
// For sidebar title
export const setPostTitle = (title: string) => ({
type: NavigationActions.SET_POST_TITLE,
payload: title,
});
2021-02-01 07:02:12 +01:00
export const expandSideMenu = () => ({
type: NavigationActions.EXPAND_SIDE_MENU,
2021-01-28 02:54:06 +01:00
});
2021-02-01 07:02:12 +01:00
export const collapseSideMenu = () => ({
type: NavigationActions.COLLAPSE_SIDE_MENU,
});
2021-02-08 00:25:27 +01:00
export const setSplitPagesContent = (pages: TPages) => ({
type: NavigationActions.SET_SPLIT_PAGES_CONTENT,
payload: pages,
});
2021-02-10 02:04:00 +01:00
export const expandMobileHeaderMenu = () => ({
type: NavigationActions.EXPAND_MOBILE_HEADER_MENU,
});
export const collapseMobileHeader = () => ({
type: NavigationActions.COLLAPSE_MOBILE_HEADER_MENU,
});