Skip to content
This repository was archived by the owner on Nov 12, 2019. It is now read-only.

Commit fdff17f

Browse files
committed
save data for theme color
1 parent 0e01a56 commit fdff17f

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

js/actions/modifySettings.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
import * as TYPES from './actionTypes';
77
import SettingsDataDAO from '../dao/SettingsDataDAO';
88

9-
export function changeColor(color) {
9+
export function changeColor(color, flag=true) {
10+
if(flag) {
11+
let dao = new SettingsDataDAO();
12+
dao.saveThemeColor(color);
13+
}
14+
15+
console.log(color);
1016
return {
1117
type: TYPES.CHANGE_COLOR,
1218
color: color
@@ -30,7 +36,7 @@ export function changeShowThumbnail(value, flag=true) {
3036
}
3137
}
3238

33-
function getShowThumbnailValue() {
39+
function fetchShowThumbnailValue() {
3440
return (dispatch) => {
3541
let dao = new SettingsDataDAO();
3642
dao.getShowThumbnailValue().then((result)=>{
@@ -41,8 +47,22 @@ function getShowThumbnailValue() {
4147
};
4248
}
4349

50+
function fetchThemeColorValue() {
51+
return (dispatch) => {
52+
let dao = new SettingsDataDAO();
53+
dao.getThemeColorValue().then((result)=>{
54+
console.log('right');
55+
dispatch(changeColor(result, false));
56+
}, (error)=>{
57+
console.log('wrong');
58+
dispatch(changeColor(error));
59+
});
60+
};
61+
}
62+
4463
export function initialSettingsStateFacade() {
4564
return (dispatch)=>{
46-
dispatch(getShowThumbnailValue());
65+
dispatch(fetchShowThumbnailValue());
66+
dispatch(fetchThemeColorValue());
4767
}
4868
}

js/dao/SettingsDataDAO.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
'use strict';
55

66
const SHOW_THUMBNAIL = 'showThumbnail';
7-
7+
const THEME_COLOR = 'themeColor';
88

99
import {AsyncStorage} from 'react-native';
1010

@@ -29,5 +29,20 @@ export default class SettingsDataDAO{
2929
});
3030
}
3131

32+
saveThemeColor(color){
33+
AsyncStorage.setItem(THEME_COLOR, color);
34+
}
35+
36+
getThemeColorValue(){
37+
return new Promise((resolve, reject) => {
38+
AsyncStorage.getItem(THEME_COLOR, (error, result) => {
39+
if(!error && result){
40+
resolve(result);
41+
}else{
42+
reject('#1e90ff');
43+
}
44+
});
45+
});
46+
}
3247

3348
}

0 commit comments

Comments
 (0)