Skip to content

Commit

Permalink
adds story visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jhmullen committed Oct 13, 2021
1 parent d6b695c commit 8e728f6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/cms/scripts/migration/db_0.21/story.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ module.exports = function(sequelize, db) {
image: {
type: db.STRING,
defaultValue: ""
},
visible: {
type: db.BOOLEAN,
defaultValue: true
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion packages/cms/src/api/mortarRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ module.exports = function(app) {
const now = Date.now();
stories = stories
.map(story => extractLocaleContent(story.toJSON(), locale, "story"))
.filter(story => story.date < now);
.filter(story => story.visible && story.date < now);
return res.json(stories.sort(sorter));
});

Expand Down
4 changes: 4 additions & 0 deletions packages/cms/src/db/story.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ module.exports = function(sequelize, db) {
image: {
type: db.STRING,
defaultValue: ""
},
visible: {
type: db.BOOLEAN,
defaultValue: true
}
},
{
Expand Down
22 changes: 22 additions & 0 deletions packages/cms/src/story/StoryEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {connect} from "react-redux";
import Button from "../components/fields/Button";
import Deck from "../components/interface/Deck";
import TextCard from "../components/cards/TextCard";
import Select from "../components/fields/Select";
import Loading from "components/Loading";
import {DatePicker} from "@blueprintjs/datetime";
import deepClone from "../utils/deepClone";
Expand Down Expand Up @@ -41,6 +42,14 @@ class StoryEditor extends Component {
return str.replace(/^\s+|\s+$/gm, "").replace(/[^a-zA-ZÀ-ž0-9-\ _]/g, "");
}

changeVisibility(e) {
const {minData} = this.state;
minData.visible = e.target.value;
const payload = {id: minData.id, visible: minData.visible};
this.setState({minData});
this.props.updateEntity("story", payload);
}

changeField(field, e) {
const {minData} = this.state;
minData[field] = field === "slug" ? this.urlPrep(e.target.value) : e.target.value;
Expand Down Expand Up @@ -86,6 +95,7 @@ class StoryEditor extends Component {
type="story"
/>}
>

<div className="cms-editor-header">
{/* change slug */}
<label className="bp3-label cms-slug">
Expand All @@ -110,6 +120,18 @@ class StoryEditor extends Component {
}
</div>
</div>
<Select
label="Story Visibility"
className="cms-profile-visible-selector"
namespace="cms"
fontSize="xs"
inline
value={minData.visible}
onChange={this.changeVisibility.bind(this)}
>
<option key="true" value={true}>Visible</option>
<option key="false" value={false}>Hidden</option>
</Select>
</div>
</Deck>

Expand Down

0 comments on commit 8e728f6

Please sign in to comment.