Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

Commit

Permalink
feature: add transliteration settings state in redux store
Browse files Browse the repository at this point in the history
  • Loading branch information
tux4 committed May 31, 2020
1 parent 56b3135 commit a748ffc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions parijat-frontend/src/actions/actionTypes.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const FAV_ITEM = 'FAV_ITEM';
export const SET_TRANSLITERATION_ENABLED = 'SET_TRANSLITERATION_ENABLED';
9 changes: 8 additions & 1 deletion parijat-frontend/src/actions/user.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { FAV_ITEM } from './actionTypes';
import { FAV_ITEM, SET_TRANSLITERATION_ENABLED } from './actionTypes';

export function favItem(item) {
return {
type: FAV_ITEM,
item
};
}

export function setTransliterationEnabled(isEnabled) {
return {
type: SET_TRANSLITERATION_ENABLED,
item: isEnabled,
};
}
8 changes: 7 additions & 1 deletion parijat-frontend/src/reducers/user.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { FAV_ITEM } from '../actions/actionTypes';
import {
FAV_ITEM,
SET_TRANSLITERATION_ENABLED
} from '../actions/actionTypes';

let initialState = {
transliteration: true,
favs: []
};

export default function user(state = initialState, action) {
switch (action.type) {
case FAV_ITEM:
return { ...state, favs: [...state.favs, action.item] };
case SET_TRANSLITERATION_ENABLED:
return { ...state, transliteration: action.item };
default:
return state;
}
Expand Down
3 changes: 2 additions & 1 deletion parijat-frontend/src/routes/content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ContentPage extends Component {
result: null
};
}

componentDidMount() {
getContent(this.props.id).then(result => {
this.setState({ result });
Expand All @@ -66,7 +67,7 @@ class ContentPage extends Component {
return (
<div>
<Header />
<button onClick={this.favItem}>Favourite</button>
<button onClick={this.favItem}>♥️ Favourite</button>
<ContentContainer>
{this.state.result != null ? (
<Content result={this.state.result} />
Expand Down

0 comments on commit a748ffc

Please sign in to comment.