Skip to content

Commit

Permalink
Set Default Temp to 26 (#124)
Browse files Browse the repository at this point in the history
* Set Default Temp to 26

Improve energy conservation and protect the earth!

* 添加提示,力图符合《公民生态环境行为规范》

见《规范》第二条 节约能源资源:合理设定空调温度,夏季不低于26度,冬季不高于20度。

* try to fix error

* Update acSlice.ts

* ♻️ set default temperature to 26

Co-authored-by: YunYouJun <[email protected]>
  • Loading branch information
nkh0472 and YunYouJun authored May 26, 2021
1 parent f5f7346 commit b914c84
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/components/RemoteControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { useAppDispatch, useAppSelector } from "../app/hooks";
import {
decreaseTemperature,
increaseTemperature,
setMode,
toggleMode,
toggleStatus,
} from "../features/ac/acSlice";
import { RootState } from "../app/store";
Expand Down Expand Up @@ -158,7 +158,7 @@ export default function RemoteControl() {
aria-label="cold"
className={classes.margin}
onClick={() => {
dispatch(setMode("cold"));
dispatch(toggleMode("cold"));
}}
>
<AcUnitIcon />
Expand All @@ -181,7 +181,7 @@ export default function RemoteControl() {
className={classes.margin}
style={{ backgroundColor: "orange", color: "white" }}
onClick={() => {
dispatch(setMode("hot"));
dispatch(toggleMode("hot"));
}}
>
<WbSunnyIcon />
Expand Down
35 changes: 34 additions & 1 deletion src/features/ac/acSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ export const acItemKey = {
temperature: namespace + "temperature",
};

// https://baike.baidu.com/item/26度空调节能倡导行动
const defaultTemperature = 26;

const initialState: AcState = {
status: false,
mode: (localStorage.getItem(acItemKey.mode) as AcMode) || "cold",
temperature:
parseInt(localStorage.getItem(acItemKey.temperature) || "") || 20,
parseInt(localStorage.getItem(acItemKey.temperature) || "") ||
defaultTemperature,
};

const maxTemperature = 31;
Expand Down Expand Up @@ -135,4 +139,33 @@ export const decreaseTemperature = (): AppThunk => (dispatch, getState) => {
}
};

/**
* 切换模式
* @param mode
* @returns
*/
export const toggleMode =
(mode: AcMode): AppThunk =>
(dispatch, getState) => {
dispatch(setMode(mode));
const currentTemperature = selectTemperature(getState());
const goodColdTemperature = 26;
const goodHotTemperature = 20;

const recommendedSlogan = (mode: AcMode, temperature: number) =>
`建议将空调的制${
mode === "cold" ? "冷" : "热"
}温度调至 ${temperature} 度以${
mode === "cold" ? "上" : "下"
},为节能减排贡献一份力量!`;

if (mode === "cold" && currentTemperature < goodColdTemperature) {
dispatch(setMessage(recommendedSlogan("cold", goodColdTemperature)));
dispatch(setOpen(true));
} else if (mode === "hot" && currentTemperature > goodHotTemperature) {
dispatch(setMessage(recommendedSlogan("hot", goodHotTemperature)));
dispatch(setOpen(true));
}
};

export default acSlice.reducer;

1 comment on commit b914c84

@vercel
Copy link

@vercel vercel bot commented on b914c84 May 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.