Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Campaign filter #58

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions src/campaign/fetch/containers/AllCampaignsView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import * as React from "react";
import FetchCampaigns from "../components/FetchCampaigns";
import * as Formsy from "formsy-react";
import { FormsySelect } from "formsy-material-ui/lib";
import { MenuItem } from "material-ui";

interface IAllCampaignsProps {
params: any;
}

const gameTypes = [ "all", "micro20", "dnd35"];

class AllCampaignsView extends React.Component<IAllCampaignsProps, void> {
private gameTypeMenu;

private constructor (props) {
super(props);
this.props.params.selectedGame = "all";
this.gameTypeMenu = this.generateMenuItems(gameTypes);
}
public render() {
let gameDropDown = <section className="gameTypeSection">
<Formsy.Form
className="campaignViewForm"
>
<FormsySelect
key={"gameTypeList"}
className="gameTypeDropDown"
autoComplete="off"
name={"gameType"}
floatingLabelText={"Game Type"}
value={this.props.params.selectedGame}
onChange={this.changeCampaign.bind(this, null)}

>
<MenuItem primaryText=" "/>
{this.gameTypeMenu}
</FormsySelect>
</Formsy.Form>
</section>;
let gameType = this.props.params.selectedGame;
let campaigns;
if (gameType === "all") {
campaigns = gameTypes.map((game) => {
if (game === "all") {
return;
}
return <FetchCampaigns key={game} gameType={game}/>;
});
} else {
campaigns = <FetchCampaigns key={gameType} gameType={gameType}/>;
}
return <section className="CampaignViewAll">
{gameDropDown}
{campaigns}
</section>;
}
private generateMenuItems(menuItems) {
return menuItems.map((menuName, index) => {
return <MenuItem key={index} value={menuName.toLowerCase()} primaryText={menuName} />;
});
}
private changeCampaign(value: string, event) {
this.props.params.selectedGame = event.target.innerHTML;
this.forceUpdate();
}
}

export default AllCampaignsView;
6 changes: 6 additions & 0 deletions src/campaign/routes.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import CampaignsView from "./fetch/containers/CampaignsView";
import CampaignView from "./fetch/containers/CampaignView";
import AllCampaignsView from "./fetch/containers/AllCampaignsView";
import CampaignCreator from "./create/containers/CampaignCreator";
import { simpleAuth } from "../auth/authMethods";

Expand All @@ -20,5 +21,10 @@ export default {
onEnter: simpleAuth,
path: "/campaign/create",
},
{
component: AllCampaignsView,
onEnter: simpleAuth,
path: "/campaigns",
},
],
};
67 changes: 67 additions & 0 deletions src/character/fetch/containers/AllCharactersView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import * as React from "react";
import FetchCharacters from "../components/FetchCharacters";
import * as Formsy from "formsy-react";
import { FormsySelect } from "formsy-material-ui/lib";
import { MenuItem } from "material-ui";

interface IAllCharactersViewProps {
params: any;
}
const gameTypes = [ "all", "micro20", "dnd35"];
class AllCharactersView extends React.Component<IAllCharactersViewProps, void> {
private gameTypeMenu;

private constructor (props) {
super(props);
this.props.params.selectedGame = "all";
this.gameTypeMenu = this.generateMenuItems(gameTypes);
}
public render() {
let gameDropDown = <section className="gameTypeSection">
<Formsy.Form
className="campaignViewForm"
>
<FormsySelect
key={"gameTypeList"}
className="gameTypeDropDown"
autoComplete="off"
name={"gameType"}
floatingLabelText={"Game Type"}
value={this.props.params.selectedGame}
onChange={this.changeGameType.bind(this, null)}

>
<MenuItem primaryText=" "/>
{this.gameTypeMenu}
</FormsySelect>
</Formsy.Form>
</section>;
let gameType = this.props.params.selectedGame;
let characters;
if (gameType === "all") {
characters = gameTypes.map((game) => {
if (game === "all") {
return;
}
return <FetchCharacters key={game} gameType={game}/>;
});
} else {
characters = <FetchCharacters key={gameType} gameType={gameType}/>;
}
return <section className="CharacterViewAll">
{gameDropDown}
{characters}
</section>;
}
private generateMenuItems(menuItems) {
return menuItems.map((menuName, index) => {
return <MenuItem key={index} value={menuName.toLowerCase()} primaryText={menuName} />;
});
}
private changeGameType(value: string, event) {
this.props.params.selectedGame = event.target.innerHTML;
this.forceUpdate();
}
}

export default AllCharactersView;
6 changes: 6 additions & 0 deletions src/character/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import CharacterCreator from "./creator/containers/CharacterCreator";
import { simpleAuth } from "../auth/authMethods";
import CharacterView from "./fetch/containers/CharacterView";
import CharactersView from "./fetch/containers/CharactersView";
import AllCharactersView from "./fetch/containers/AllCharactersView";

export default {
childRoutes: [
Expand All @@ -20,5 +21,10 @@ export default {
onEnter: simpleAuth,
path: "/:gameType/characters",
},
{
component: AllCharactersView,
onEnter: simpleAuth,
path: "/characters",
},
],
};
4 changes: 2 additions & 2 deletions src/layout/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ class Sidebar extends React.Component<ISidebarProps, void> {
{icon: <FontIcon className="material-icons">add_circle</FontIcon>,
route: "/campaign/create", text: "Campaign Creator"},
{icon: <FontIcon className="material-icons">assignment</FontIcon>,
route: "/micro20/campaigns", text: "All Campaigns"},
route: "/campaigns", text: "All Campaigns"},
{icon: null, route: null, text: null},
{icon: <FontIcon className="material-icons">add_circle</FontIcon>,
route: "/character/create", text: "Character Creator"},
{icon: <FontIcon className="material-icons">assignment_ind</FontIcon>,
route: "/micro20/characters", text: "All Characters"},
route: "/characters", text: "All Characters"},
{icon: null, route: null, text: null},
{icon: <FontIcon className="material-icons">settings</FontIcon>,
route: "/settings", text: "Settings"},
Expand Down