zhiwen0905 commited on
Commit
688f0b9
·
1 Parent(s): 4e573d8

feature(#195): implement setting page

Browse files
Extension/src/pages/Background/index.js CHANGED
@@ -8,10 +8,21 @@ chrome.runtime.onInstalled.addListener(function() {
8
  });
9
 
10
  // Handle the context menu item click
11
- chrome.contextMenus.onClicked.addListener(function(info, tab) {
12
  if (info.menuItemId === 'risingExtension') {
13
  chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
14
  chrome.tabs.sendMessage(tabs[0].id, { action: "open-modal" });
15
  });
16
  }
 
 
 
 
 
 
 
 
 
 
 
17
  });
 
8
  });
9
 
10
  // Handle the context menu item click
11
+ chrome.contextMenus.onClicked.addListener(function(info) {
12
  if (info.menuItemId === 'risingExtension') {
13
  chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
14
  chrome.tabs.sendMessage(tabs[0].id, { action: "open-modal" });
15
  });
16
  }
17
+ });
18
+
19
+ // Handle the local storage get value
20
+ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
21
+ if (request.method === 'getLocalStorage') {
22
+ chrome.storage.local.get(function(result) {
23
+ console.log('background result--------->', result)
24
+ sendResponse({ data: result });
25
+ });
26
+ }
27
+ return true; // Important for asynchronous sendMessage
28
  });
Extension/src/pages/Panel/Panel.css CHANGED
@@ -4,8 +4,8 @@
4
  }
5
 
6
  [data-theme='dark'] {
7
- --font-color: #aeafb2;
8
- --theme-color: #0d0c0d;
9
  }
10
 
11
  .main-layout {
 
4
  }
5
 
6
  [data-theme='dark'] {
7
+ --font-color: #e3e3e3;
8
+ --theme-color: #141414;
9
  }
10
 
11
  .main-layout {
Extension/src/pages/Panel/Panel.jsx CHANGED
@@ -27,17 +27,7 @@ const URL_ASK_WEBSITE = URL_BASE + 'browser/ask'
27
  const URL_DELETE_RTD = URL_BASE + 'auto_task/delete'
28
 
29
  let prompt = ""
30
- const confs = {
31
- "openai_key": "",
32
- "pinecone_key": "",
33
- "pinecone_env": "",
34
- "firebase_key": "",
35
- "token": "",
36
- "uuid": "extension-uuid",
37
- "settings": {
38
- "temperature": 0.6
39
- }
40
- }
41
  const logoUrl = Browser.runtime.getURL('logo_panel.png')
42
 
43
  const Panel = () => {
@@ -45,6 +35,14 @@ const Panel = () => {
45
  const [messages, setMessages] = useState([]);
46
  const [isLoading, setLoadingStatus] = useState(false);
47
  const chat_box = useRef(null);
 
 
 
 
 
 
 
 
48
 
49
  const handleQuestionUpdated = (event) => {
50
  if (event.key === "Enter" && !isLoading) {
 
27
  const URL_DELETE_RTD = URL_BASE + 'auto_task/delete'
28
 
29
  let prompt = ""
30
+
 
 
 
 
 
 
 
 
 
 
31
  const logoUrl = Browser.runtime.getURL('logo_panel.png')
32
 
33
  const Panel = () => {
 
35
  const [messages, setMessages] = useState([]);
36
  const [isLoading, setLoadingStatus] = useState(false);
37
  const chat_box = useRef(null);
38
+ const [confs, setConfs] = useState(null);
39
+
40
+ useEffect(() => {
41
+ // Send a message to background script to get the storage value
42
+ chrome.runtime.sendMessage({ method: 'getLocalStorage' }, (response) => {
43
+ setConfs(response.data);
44
+ });
45
+ }, []);
46
 
47
  const handleQuestionUpdated = (event) => {
48
  if (event.key === "Enter" && !isLoading) {
Extension/src/pages/Popup/Popup.css CHANGED
@@ -1,3 +1,72 @@
1
- .popup {
2
- text-align: center;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  }
 
1
+ [data-theme='light'] {
2
+ --font-color: #c9d1d9;
3
+ --theme-color: #333333;
4
+ }
5
+
6
+ [data-theme='dark'] {
7
+ --font-color: #e3e3e3;
8
+ --theme-color: #141414;
9
+ }
10
+
11
+ .main-layout {
12
+ display: flex;
13
+ flex-direction: column;
14
+ height: 490px; /* Set the height of the layout to be 100% of the viewport */
15
+ width: 400px;
16
+ background-color: var(--theme-color);
17
+ color: var(--font-color);
18
+ }
19
+
20
+ .header {
21
+ height: 55px;
22
+ text-align: left;
23
+ padding-top: 5px;
24
+ padding-left: 10px;
25
+ }
26
+
27
+ .divider {
28
+ margin: 0;
29
+ background-color: grey;
30
+ }
31
+
32
+ .content {
33
+ padding: 10px;
34
+ }
35
+
36
+ .footer {
37
+ padding: 10px;
38
+ background-color: var(--theme-color);
39
+ display: flex;
40
+ justify-content: flex-end;
41
+ gap: 15px;
42
+ align-items: center;
43
+ color: grey;
44
+ }
45
+
46
+ .custom-input {
47
+ margin-bottom: 15px;
48
+ background-color: #202020;
49
+ color: white;
50
+ }
51
+
52
+ .ant-input-group-addon {
53
+ color: var(--font-color) !important;
54
+ width: 120px !important;
55
+ }
56
+
57
+ .ant-input {
58
+ background-color: #202020;
59
+ color: var(--font-color) !important;
60
+ }
61
+
62
+ .footer-btn {
63
+ background-color: inherit;
64
+ color: var(--font-color);
65
+ border: 0;
66
+ }
67
+
68
+ .footer-btn:hover {
69
+ border: 1px solid white !important;
70
+ color: var(--font-color) !important;
71
+ border-radius: 10px !important;
72
  }
Extension/src/pages/Popup/Popup.jsx CHANGED
@@ -1,12 +1,127 @@
1
- import React from 'react';
 
 
 
 
 
2
  import './Popup.css';
3
 
 
4
  const Popup = () => {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  return (
6
- <div className="popup">
7
- <h1>Rising</h1>
8
- <h3>AI Assistance</h3>
9
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  );
11
  };
12
 
 
1
+ import React, {useState} from 'react';import {
2
+ Divider,
3
+ Input,
4
+ Layout,
5
+ Button
6
+ } from 'antd';
7
  import './Popup.css';
8
 
9
+ const {Footer, Content} = Layout;
10
  const Popup = () => {
11
+ const [hostName,setHostName] = useState("")
12
+ const [openaiKey,setOpenaiKey] = useState("")
13
+ const [pineconeKey,setPineconeKey] = useState("")
14
+ const [pineconeEnv,setPineconeEnv] = useState("")
15
+ const [firebaseKey,setFirebaseKey] = useState("")
16
+ const [token,setToken] = useState("")
17
+ const [uuid,setUuid] = useState("")
18
+ const [temperature,setTemperature] = useState(0)
19
+
20
+ /// Check if the user's system is in dark mode
21
+ const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
22
+ let isDarkMode = darkModeMediaQuery.matches;
23
+
24
+ const handleThemeChange = (e) => {
25
+ isDarkMode = e.matches;
26
+ };
27
+
28
+ // Listen for changes in the theme data
29
+ darkModeMediaQuery.addEventListener('change', handleThemeChange);
30
+
31
+ const handleSave = () => {
32
+ chrome.storage.local.set({
33
+ "host_name": hostName,
34
+ "openai_key": openaiKey,
35
+ "pinecone_key": pineconeKey,
36
+ "pinecone_env": pineconeEnv,
37
+ "firebase_key": firebaseKey,
38
+ "token": token,
39
+ "uuid": uuid,
40
+ "temperature": temperature
41
+ }, () => {
42
+ console.log('Successfully set to local storage')
43
+ })
44
+ }
45
+
46
+ const handleCancel = () => {
47
+
48
+ }
49
+
50
  return (
51
+
52
+ <Layout className="main-layout" data-theme={isDarkMode ? 'dark': 'light'}>
53
+ <div className="header">
54
+ <h1>Settings</h1>
55
+ </div>
56
+ <Divider className="divider"/>
57
+ <Content className="content">
58
+ <Input
59
+ name="hostName"
60
+ addonBefore="Host Name"
61
+ value={hostName}
62
+ className="custom-input"
63
+ onChange={(e) => setHostName(e.target.value)}
64
+ />
65
+ <Input
66
+ name="openaiKey"
67
+ addonBefore="OpenAI Key"
68
+ value={openaiKey}
69
+ className="custom-input"
70
+ onChange={(e) => setOpenaiKey(e.target.value)}
71
+ />
72
+ <Input
73
+ name="pineconeKey"
74
+ addonBefore="Pinecone Key"
75
+ value={pineconeKey}
76
+ className="custom-input"
77
+ onChange={(e) => setPineconeKey(e.target.value)}
78
+ />
79
+ <Input
80
+ name="pineconeEnv"
81
+ addonBefore="Pinecone Env"
82
+ value={pineconeEnv}
83
+ className="custom-input"
84
+ onChange={(e) => setPineconeEnv(e.target.value)}
85
+ />
86
+ <Input
87
+ name="firebaseKey"
88
+ addonBefore="Firebase Key"
89
+ value={firebaseKey}
90
+ className="custom-input"
91
+ onChange={(e) => setFirebaseKey(e.target.value)}
92
+ />
93
+ <Input
94
+ name="token"
95
+ addonBefore="Token"
96
+ value={token}
97
+ className="custom-input"
98
+ onChange={(e) => setToken(e.target.value)}
99
+ />
100
+ <Input
101
+ name="uuid"
102
+ addonBefore="UUID"
103
+ value={uuid}
104
+ className="custom-input"
105
+ onChange={(e) => setUuid(e.target.value)}
106
+ />
107
+ <Input
108
+ name="temperature"
109
+ addonBefore="Temperature"
110
+ type="number"
111
+ value={temperature}
112
+ step="0.1"
113
+ min="0"
114
+ max="1"
115
+ className="custom-input"
116
+ onChange={(e) => setTemperature(e.target.value)}
117
+ />
118
+ </Content>
119
+ <Divider className="divider"/>
120
+ <Footer className="footer">
121
+ <Button className="footer-btn" onClick={handleSave}>Save</Button>
122
+ <Button className="footer-btn" onClick={handleCancel}>Cancel</Button>
123
+ </Footer>
124
+ </Layout>
125
  );
126
  };
127
 
Extension/src/pages/Popup/index.css CHANGED
@@ -1,17 +1,3 @@
1
  body {
2
- width: 200px;
3
- height: 100px;
4
- margin: 0;
5
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
6
- 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
7
- sans-serif;
8
- -webkit-font-smoothing: antialiased;
9
- -moz-osx-font-smoothing: grayscale;
10
-
11
- position: relative;
12
- }
13
-
14
- code {
15
- font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
16
- monospace;
17
  }
 
1
  body {
2
+ margin: 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  }