commit 392d177403939f4b34038fd5bf232c98c0948b70
parent 6e8f8c14554c36d057cbac5179711b6c9d64b9b6
Author: Johan Lindskogen <johan.lindskogen@gmail.com>
Date: Sun, 1 Apr 2018 20:32:15 +0200
Add hotlist state
Diffstat:
5 files changed, 52 insertions(+), 2 deletions(-)
diff --git a/src/lib/weechat/types.ts b/src/lib/weechat/types.ts
@@ -29,6 +29,18 @@ interface WeechatBuffer {
type: number;
}
+interface WeechatHotlist {
+ buffer: string;
+ count: number[];
+}
+
+interface Hotlist extends WeechatHotlist {
+ message: number;
+ privmsg: number;
+ highlight: number;
+ sum: number;
+}
+
interface Localvariables {
plugin: string;
name: string;
diff --git a/src/store/hotlists.ts b/src/store/hotlists.ts
@@ -0,0 +1,14 @@
+import { omit } from "lodash";
+
+export type HotListState = { [key: string]: Hotlist };
+
+const initialState: HotListState = {};
+
+export default (state: HotListState = initialState, action): HotListState => {
+ switch (action.type) {
+ case "FETCH_HOTLISTS":
+ return action.payload;
+ default:
+ return state;
+ }
+};
diff --git a/src/store/index.ts b/src/store/index.ts
@@ -2,6 +2,7 @@ import { combineReducers, createStore, applyMiddleware } from "redux";
import buffers, { BufferState } from "./buffers";
import lines, { LineState } from "./lines";
+import hotlists, { HotListState } from "./hotlists";
type AppState = {
connected: boolean;
@@ -12,6 +13,7 @@ export type StoreState = {
app: AppState;
buffers: BufferState;
lines: LineState;
+ hotlists: HotListState;
};
const initialState: AppState = {
@@ -39,7 +41,8 @@ const app = (state: AppState = initialState, action) => {
const reducer = combineReducers({
app,
buffers,
- lines
+ lines,
+ hotlists
});
export default createStore(
diff --git a/src/store/selectors.ts b/src/store/selectors.ts
@@ -0,0 +1,21 @@
+import { StoreState } from ".";
+
+const createEmptyHotlist = (bufferId: string) => ({
+ buffer: bufferId,
+ count: [0, 0, 0, 0],
+ message: 0,
+ privmsg: 0,
+ highlight: 0,
+ sum: 0
+});
+
+export const getHotlistForBufferId = (
+ state: StoreState,
+ bufferId: string
+): Hotlist => {
+ if (bufferId && state.hotlists[bufferId]) {
+ return state.hotlists[bufferId];
+ } else {
+ return createEmptyHotlist(bufferId);
+ }
+};
diff --git a/src/usecase/Root.tsx b/src/usecase/Root.tsx
@@ -22,7 +22,7 @@ export default class WeechatNative extends React.Component {
componentWillMount() {
connection.connect().then(
conn => {
- // conn.send("(hotlist) hdata hotlist:gui_hotlist(*)");
+ conn.send("(hotlist) hdata hotlist:gui_hotlist(*)");
conn.send(
"(buffers) hdata buffer:gui_buffers(*) local_variables,notify,number,full_name,short_name,title,hidden,type"
);