Skip to content

Commit bda2efd

Browse files
committed
feat(server-url): add settings to change server url
Add new colors Fix errors Change method names
1 parent 59c0669 commit bda2efd

File tree

7 files changed

+344
-278
lines changed

7 files changed

+344
-278
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ All messages are en- and decrypted with the stored secret key and send to the se
2323
This plugins needs a server ([https://github.com/ph1p/figma-chat-server](https://github.com/ph1p/figma-chat-server)).
2424
This is a simple websocket server. **Messages are only forwarded and not stored!**
2525

26-
At first I thought about saving the messages in one element,
26+
---
27+
28+
At first I thought about saving the messages in one element inside the figma-file,
2729
but the plugin can't be notified when a new message arrives.
28-
The plugin must poll every n milliseconds.
30+
The plugin have to poll every n milliseconds.
2931

3032
### Todolist/Featurelist
3133

32-
- [ ] set custom server URL ([https://github.com/ph1p/figma-chat-server](https://github.com/ph1p/figma-chat-server))
34+
- [x] set custom server URL ([https://github.com/ph1p/figma-chat-server](https://github.com/ph1p/figma-chat-server))
3335
- [ ] notifications
3436
- [ ] save local history
3537
- [ ] regenerate new room name and secret key

assets/chat-settings.png

1.94 KB
Loading

src/assets/css/ui.css

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,40 +69,79 @@ body {
6969
color: #fff;
7070
}
7171

72-
.messages .message.me .user,
73-
.messages .message.yellow .user {
72+
.messages .message.me .user {
7473
color: #000;
7574
}
7675

77-
.messages .message.me .selection,
78-
.messages .message.yellow .selection {
76+
.messages .message.me .selection {
7977
border-color: #000;
8078
color: #000;
8179
}
8280

83-
.messages .message.blue {
84-
background-color: #18a0fb;
81+
.messages .message.lightblue .user {
82+
color: #357d94;
83+
}
84+
.messages .message.lightblue .selection {
85+
border-color: #357d94;
86+
color: #357d94;
8587
}
8688

87-
.messages .message.purple {
88-
background-color: #7b61ff;
89+
.messages .message.lightgreen .user {
90+
color: #3a8459;
91+
}
92+
.messages .message.lightgreen .selection {
93+
border-color: #3a8459;
94+
color: #3a8459;
8995
}
9096

91-
.messages .message.hot-pink {
92-
background-color: #ff00ff;
97+
.messages .message.purple .user {
98+
color: #433688;
99+
}
100+
.messages .message.purple .selection {
101+
border-color: #433688;
102+
color: #433688;
103+
}
104+
105+
.messages .message.red .user {
106+
color: #842713;
107+
}
108+
.messages .message.red .selection {
109+
border-color: #842713;
110+
color: #842713;
111+
}
112+
113+
.messages .message.green .user {
114+
color: #0d6540;
115+
}
116+
.messages .message.green .selection {
117+
border-color: #0d6540;
118+
color: #0d6540;
93119
}
94120

121+
.messages .message.gray {
122+
background-color: #4f4f4f;
123+
}
124+
.messages .message.blue {
125+
background-color: #18a0fb;
126+
}
127+
.messages .message.lightblue {
128+
background-color: #56ccf2;
129+
color: #357d94;
130+
}
131+
.messages .message.purple {
132+
background-color: #7b61ff;
133+
}
95134
.messages .message.green {
96135
background-color: #1bc47d;
97136
}
98-
137+
.messages .message.lightgreen {
138+
background-color: #6fcf97;
139+
}
99140
.messages .message.red {
100141
background-color: #f24822;
101142
}
102-
103-
.messages .message.yellow {
104-
background-color: #ffeb00;
105-
color: #000;
143+
.messages .message.orange {
144+
background-color: #f2994a;
106145
}
107146

108147
.chat .footer {
@@ -162,14 +201,14 @@ body {
162201
}
163202
.settings .colors {
164203
display: grid;
165-
grid-template-columns: repeat(3, 1fr);
204+
grid-template-columns: repeat(4, 1fr);
166205
grid-gap: 32px;
167206
margin-bottom: 30px;
168207
}
169208
.settings .colors .color {
170209
position: relative;
171-
width: 60px;
172-
height: 60px;
210+
width: 40px;
211+
height: 40px;
173212
border-radius: 100%;
174213
cursor: pointer;
175214
}
@@ -179,8 +218,8 @@ body {
179218
top: -6px;
180219
position: absolute;
181220
border-radius: 100%;
182-
width: 70px;
183-
height: 70px;
221+
width: 50px;
222+
height: 50px;
184223
border: 1px solid #000;
185224
}
186225

src/code.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,37 @@ async function main() {
3939

4040
main().then(({ roomName, secret }) => {
4141
figma.ui.onmessage = async message => {
42-
if (message.action === 'save-settings') {
43-
await figma.clientStorage.setAsync('settings', message.options);
42+
if (message.action === 'save-user-settings') {
43+
await figma.clientStorage.setAsync('user-settings', message.options);
4444

4545
figma.ui.postMessage({
46-
type: 'settings',
46+
type: 'user-settings',
4747
settings: message.options
4848
});
4949
}
5050

51-
if (message.action === 'get-settings') {
52-
const settings = await figma.clientStorage.getAsync('settings');
51+
if (message.action === 'get-user-settings') {
52+
const settings = await figma.clientStorage.getAsync('user-settings');
5353
figma.ui.postMessage({
54-
type: 'settings',
54+
type: 'user-settings',
5555
settings
5656
});
5757
}
5858

59-
if (message.action === 'message') {
60-
throw 'Neue Nachricht!';
59+
if (message.action === 'set-server-url') {
60+
await figma.clientStorage.setAsync('server-url', message.options);
61+
62+
alert('Please restart the plugin to connect to the new server.');
63+
figma.closePlugin();
64+
}
65+
66+
if (message.action === 'initialize') {
67+
const url = await figma.clientStorage.getAsync('server-url');
68+
69+
figma.ui.postMessage({
70+
type: 'initialize',
71+
url: url || ''
72+
});
6173
}
6274

6375
if (message.action === 'get-selection') {

src/components/settings.tsx

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ export default function Settings(props) {
66
const closeSettings = () => props.setSettingsView(false);
77

88
const [settings, setSettings] = useState({
9-
...props.settings,
10-
user: {
11-
...props.settings.user
12-
}
9+
...props.settings
1310
});
11+
const [url, setUrl] = useState(props.url);
1412

1513
const saveSettings = () => {
16-
sendMainMessage('save-settings', settings);
14+
sendMainMessage('save-user-settings', settings);
15+
16+
if (url && url !== props.url) {
17+
sendMainMessage('set-server-url', url);
18+
}
1719

1820
props.setSettingsView(false);
1921
};
@@ -24,14 +26,11 @@ export default function Settings(props) {
2426
<h4>Name</h4>
2527
<input
2628
type="input"
27-
value={settings.user.name}
29+
value={settings.name}
2830
onChange={e =>
2931
setSettings({
3032
...settings,
31-
user: {
32-
...settings.user,
33-
name: e.target.value
34-
}
33+
name: e.target.value
3534
})
3635
}
3736
className="input"
@@ -47,32 +46,27 @@ export default function Settings(props) {
4746
onClick={() =>
4847
setSettings({
4948
...settings,
50-
user: {
51-
...settings.user,
52-
color
53-
}
49+
color
5450
})
5551
}
56-
className={`color ${settings.user.color === color && ' active'}`}
52+
className={`color ${settings.color === color && ' active'}`}
5753
style={{ backgroundColor: color }}
5854
/>
5955
))}
6056
</div>
6157

62-
<strong>Current Server</strong><p>{settings.url}</p>
58+
<h4>
59+
Current Server (needs restart)
60+
<p>{props.url}</p>
61+
</h4>
6362

64-
{/* <input
63+
<input
6564
type="input"
66-
value={settings.url}
67-
onChange={e =>
68-
setSettings({
69-
...settings,
70-
url: e.target.value
71-
})
72-
}
65+
value={url}
66+
onChange={e => setUrl(e.target.value)}
7367
className="input"
7468
placeholder="Server-URL ..."
75-
/> */}
69+
/>
7670
</div>
7771

7872
<div className="footer">

src/helpers.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ export const sendMainMessage = (action, options = {}) =>
1010
);
1111

1212
export const colors = {
13+
'#4F4F4F': 'gray',
1314
'#18A0FB': 'blue',
15+
'#56CCF2': 'lightblue',
1416
'#7B61FF': 'purple',
15-
'#FF00FF': 'hot-pink',
1617
'#1BC47D': 'green',
18+
'#6fcf97': 'lightgreen',
1719
'#F24822': 'red',
18-
'#FFEB00': 'yellow'
20+
'#F2994A': 'orange'
1921
};

0 commit comments

Comments
 (0)