11import { RangeSlider } from "./RangeSlider" ;
22import { IParameterV2 } from "../../config" ;
3- import React from "react" ;
3+ import React , { useEffect } from "react" ;
44import styled from "styled-components" ;
5- import { useParams } from "../../popup" ;
6- import { sendRequest } from "../../message" ;
5+ import { PopupDispatch , updateParam } from "../../popup" ;
6+ import { sendRequestToContent } from "../../message" ;
77
88const StyledContainer = styled . div `
99 width: 320px;
@@ -14,13 +14,23 @@ const StyledContainer = styled.div`
1414 font-size: 12px;
1515` ;
1616
17- export const HomePage = ( ) => {
18- const params = useParams ( ) ;
19- return < > { params && < HomePageChild params = { params } /> } </ > ;
20- } ;
17+ interface HomePageProps {
18+ param : IParameterV2 ;
19+ dispatch : PopupDispatch ;
20+ }
2121
22- export const HomePageChild = ( props : { params : IParameterV2 } ) => {
23- const { params } = props ;
22+ export const HomePage = ( props : HomePageProps ) => {
23+ const { param, dispatch } = props ;
24+ useEffect ( ( ) => {
25+ updateParam ( param ) ;
26+ } , [
27+ param . repeatPostThreshold ,
28+ param . repeatWordThreshold ,
29+ param . postFrequencyThreshold ,
30+ param . lengthThreshold ,
31+ param . lookChats ,
32+ param . executionInterval ,
33+ ] ) ;
2434 return (
2535 < StyledContainer >
2636 < RangeSlider
@@ -29,20 +39,13 @@ export const HomePageChild = (props: { params: IParameterV2 }) => {
2939 min = { 1 }
3040 max = { 10 }
3141 step = { 1 }
32- defaultValue = { params . repeatPostThreshold }
42+ defaultValue = { param . repeatPostThreshold }
3343 updateParam = { ( value : number ) => {
3444 const newParam : IParameterV2 = {
35- ...params ,
45+ ...param ,
3646 repeatPostThreshold : value ,
3747 } ;
38- sendRequest ( {
39- type : "UPDATE_PARAM" ,
40- from : "POPUP" ,
41- to : "BACKGROUND" ,
42- data : {
43- param : newParam ,
44- } ,
45- } ) ;
48+ dispatch ( { t : "update" , param : newParam } ) ;
4649 } }
4750 />
4851 < RangeSlider
@@ -51,20 +54,13 @@ export const HomePageChild = (props: { params: IParameterV2 }) => {
5154 min = { 1 }
5255 max = { 20 }
5356 step = { 1 }
54- defaultValue = { params . repeatWordThreshold }
57+ defaultValue = { param . repeatWordThreshold }
5558 updateParam = { ( value : number ) => {
5659 const newParam : IParameterV2 = {
57- ...params ,
60+ ...param ,
5861 repeatWordThreshold : value ,
5962 } ;
60- sendRequest ( {
61- type : "UPDATE_PARAM" ,
62- from : "POPUP" ,
63- to : "BACKGROUND" ,
64- data : {
65- param : newParam ,
66- } ,
67- } ) ;
63+ dispatch ( { t : "update" , param : newParam } ) ;
6864 } }
6965 />
7066 < RangeSlider
@@ -73,20 +69,13 @@ export const HomePageChild = (props: { params: IParameterV2 }) => {
7369 min = { 1 }
7470 max = { 50 }
7571 step = { 1 }
76- defaultValue = { params . postFrequencyThreshold }
72+ defaultValue = { param . postFrequencyThreshold }
7773 updateParam = { ( value : number ) => {
7874 const newParam : IParameterV2 = {
79- ...params ,
75+ ...param ,
8076 postFrequencyThreshold : value ,
8177 } ;
82- sendRequest ( {
83- type : "UPDATE_PARAM" ,
84- from : "POPUP" ,
85- to : "BACKGROUND" ,
86- data : {
87- param : newParam ,
88- } ,
89- } ) ;
78+ dispatch ( { t : "update" , param : newParam } ) ;
9079 } }
9180 />
9281 < RangeSlider
@@ -95,20 +84,13 @@ export const HomePageChild = (props: { params: IParameterV2 }) => {
9584 min = { 1 }
9685 max = { 200 }
9786 step = { 1 }
98- defaultValue = { params . lengthThreshold }
87+ defaultValue = { param . lengthThreshold }
9988 updateParam = { ( value : number ) => {
10089 const newParam : IParameterV2 = {
101- ...params ,
90+ ...param ,
10291 lengthThreshold : value ,
10392 } ;
104- sendRequest ( {
105- type : "UPDATE_PARAM" ,
106- from : "POPUP" ,
107- to : "BACKGROUND" ,
108- data : {
109- param : newParam ,
110- } ,
111- } ) ;
93+ dispatch ( { t : "update" , param : newParam } ) ;
11294 } }
11395 />
11496 < RangeSlider
@@ -117,20 +99,13 @@ export const HomePageChild = (props: { params: IParameterV2 }) => {
11799 min = { 1 }
118100 max = { 250 }
119101 step = { 1 }
120- defaultValue = { params . lookChats }
102+ defaultValue = { param . lookChats }
121103 updateParam = { ( value : number ) => {
122104 const newParam : IParameterV2 = {
123- ...params ,
105+ ...param ,
124106 lookChats : value ,
125107 } ;
126- sendRequest ( {
127- type : "UPDATE_PARAM" ,
128- from : "POPUP" ,
129- to : "BACKGROUND" ,
130- data : {
131- param : newParam ,
132- } ,
133- } ) ;
108+ dispatch ( { t : "update" , param : newParam } ) ;
134109 } }
135110 />
136111 < RangeSlider
@@ -139,20 +114,13 @@ export const HomePageChild = (props: { params: IParameterV2 }) => {
139114 min = { 50 }
140115 max = { 10000 }
141116 step = { 100 }
142- defaultValue = { params . executionInterval }
117+ defaultValue = { param . executionInterval }
143118 updateParam = { ( value : number ) => {
144119 const newParam : IParameterV2 = {
145- ...params ,
120+ ...param ,
146121 executionInterval : value ,
147122 } ;
148- sendRequest ( {
149- type : "UPDATE_PARAM" ,
150- from : "POPUP" ,
151- to : "BACKGROUND" ,
152- data : {
153- param : newParam ,
154- } ,
155- } ) ;
123+ dispatch ( { t : "update" , param : newParam } ) ;
156124 } }
157125 />
158126 </ StyledContainer >
0 commit comments