Skip to content

Commit 844cdfa

Browse files
committed
New algo, bugfixes, UI/UX improvements
1 parent 61f0051 commit 844cdfa

File tree

7 files changed

+1202
-906
lines changed

7 files changed

+1202
-906
lines changed

components/AddRoomModal.vue

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
title="Add a Room"
44
ref="modal"
55
:ok-title="type === 'n' ? 'Create' : 'Join'"
6-
:busy="adding_room"
7-
:no-close-on-backdrop="adding_room"
8-
:no-close-on-esc="adding_room"
6+
:ok-disabled="!can_submit"
7+
:busy="!can_edit"
8+
:no-close-on-backdrop="!can_edit"
9+
:no-close-on-esc="!can_edit"
910
@ok="handleOk"
1011
>
1112
<AlertSection ref="alerts" />
@@ -16,26 +17,34 @@
1617
<b-form-input
1718
id="name-input"
1819
v-model="form.name"
19-
:disabled="adding_room"
20+
:disabled="!can_edit"
2021
placeholder="Room Name (optional)"
2122
/>
2223
</b-form-group>
2324
</b-tab>
2425
<b-tab title="Join a room"></b-tab>
2526
</b-tabs>
26-
<b-form-group label-for="alias-input">
27+
<b-form-group label-for="room-input">
2728
<b-input-group prepend="#">
2829
<b-form-input
29-
id="alias-input"
30-
aria-describedby="alias-live-feedback"
31-
v-model="form.alias"
32-
:disabled="adding_room"
30+
id="room-input"
31+
aria-describedby="room-live-feedback"
32+
v-model="form.room"
33+
:disabled="!can_edit"
3334
:required="type === 'j'"
34-
:state="alias_valid"
35-
:placeholder="type === 'n' ? 'Room Alias (optional)' : 'Room Alias'"
35+
:state="room_valid"
36+
:placeholder="
37+
type === 'n' ? 'Room Alias (optional)' : 'Room Alias or ID'
38+
"
3639
/>
37-
<b-form-invalid-feedback id="alias-live-feedback">
38-
Enter just the localpart of the alias.
40+
<b-form-invalid-feedback id="room-live-feedback">
41+
<template v-if="type === 'n'">
42+
Enter just the localpart of the alias to create.
43+
</template>
44+
<template v-if="type === 'j'">
45+
Enter both the localpart and server name with the # or ! (ex.
46+
#matrix:matrix.org)
47+
</template>
3948
</b-form-invalid-feedback>
4049
</b-input-group>
4150
</b-form-group>
@@ -46,13 +55,14 @@
4655
<script>
4756
import { debug } from '@/plugins/debug'
4857
import AlertSection from '@/components/AlertSection'
58+
import { matrix_typed_state, plaintext } from '@/plugins/matrix.js'
4959
5060
export default {
5161
components: { AlertSection },
5262
data() {
5363
return {
5464
form: {
55-
alias: '',
65+
room: '',
5666
name: '',
5767
tab: 0
5868
},
@@ -65,11 +75,24 @@ export default {
6575
type() {
6676
return this.form.tab === 0 ? 'n' : 'j'
6777
},
68-
alias_valid() {
69-
const res = /^[^#:]*$/gm.exec(this.form.alias)
70-
return this.form.alias.length || this.type === 'j'
71-
? (res && res.index === 0) || false
72-
: undefined
78+
room_valid() {
79+
if (this.type === 'n') {
80+
const res = /^[^!#:]*$/gm.exec(this.form.room)
81+
return res && res.index === 0 ? undefined : false
82+
} else if (this.type === 'j') {
83+
const res = /^[!#][^!#:]+:[a-zA-Z0-9-.]+(:[0-9]+)?$/gm.exec(
84+
this.form.room
85+
)
86+
return res && res.index === 0 ? undefined : false
87+
}
88+
return false
89+
},
90+
can_submit() {
91+
// BS has a really weird way of validating forms
92+
return this.room_valid !== false && !this.adding_room
93+
},
94+
can_edit() {
95+
return !this.adding_room
7396
}
7497
},
7598
@@ -86,15 +109,25 @@ export default {
86109
return
87110
}
88111
89-
const alias = values.alias.trim()
112+
const room = values.room.trim()
90113
const name = values.name
91114
this.adding_room = true
92115
if (this.type === 'n') {
93116
this.$matrix.client
94117
.createRoom({
95-
room_alias_name: alias !== '' ? alias : undefined,
118+
room_alias_name: room !== '' ? room : undefined,
96119
name: name !== '' ? name : undefined
97120
})
121+
.then((data) =>
122+
this.$matrix.client
123+
.sendStateEvent(
124+
data.room_id,
125+
matrix_typed_state,
126+
{ type: plaintext },
127+
''
128+
)
129+
.then(() => data)
130+
)
98131
.then(
99132
({ room_id }) => {
100133
if (room_id) {
@@ -115,12 +148,12 @@ export default {
115148
})
116149
} else if (this.type === 'j') {
117150
this.$matrix.client
118-
.joinRoom(values.room, { syncRoom: false })
151+
.joinRoom(`${values.room}`, { syncRoom: false })
119152
.then(
120153
({ roomId }) => {
121-
if (roomId) {
154+
/* if (roomId) {
122155
this.$router.replace('/edit/' + encodeURIComponent(roomId))
123-
}
156+
} */
124157
this.hide()
125158
},
126159
(e) => {
@@ -139,10 +172,7 @@ export default {
139172
140173
handleOk(e) {
141174
e.preventDefault()
142-
if (
143-
this.alias_valid === false ||
144-
(!this.alias_valid && this.type === 'j')
145-
) {
175+
if (!this.can_submit) {
146176
return
147177
}
148178
this.onFormSubmit(this.form)

components/DocumentEditor.vue

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
placeholder="Untitled Document"
1313
v-model="internal_title"
1414
@blur="(e) => e.target.focus()"
15+
@keyup="onTitleInputKeyEvent"
1516
/>
1617
<b-input-group-append v-if="internal_title !== title">
17-
<b-button
18-
variant="success"
19-
@click="$emit('set-title', internal_title)"
20-
>
18+
<b-button variant="success" @click="onTitleChangeRequested()">
2119
<b-icon icon="check" />
2220
</b-button>
2321
<b-button variant="danger" @click="() => (internal_title = title)">
@@ -62,6 +60,7 @@ export default {
6260
line: true,
6361
theme: 'mdn-like'
6462
},
63+
console,
6564
6665
changes_to_ignore: {}
6766
}
@@ -78,6 +77,21 @@ export default {
7877
},
7978
8079
methods: {
80+
onTitleChangeRequested() {
81+
this.$emit('set-title', this.internal_title)
82+
},
83+
onTitleInputKeyEvent(e) {
84+
switch (e.keyCode) {
85+
case 13:
86+
this.onTitleChangeRequested()
87+
e.target.blur()
88+
break
89+
case 27:
90+
e.target.blur()
91+
break
92+
}
93+
},
94+
8195
insert(pos, text, meta) {
8296
const cmdoc = this.$refs.codemirror.codemirror.doc
8397
debug.log(`INSERT '${text}' AT ${pos}`)
@@ -159,7 +173,7 @@ export default {
159173
height: 100%;
160174
}
161175
.input-text-unless-focus:not(:focus) {
162-
background-color: #0000;
176+
background-color: #0000000e;
163177
border-color: #0000;
164178
}
165179
.with-loading {

layouts/gradient-bg-full.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ html {
1919
height: 100%;
2020
}
2121
22+
body,
2223
#__nuxt,
2324
#__layout {
2425
height: 100%;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "matrix-notepad",
3-
"version": "0.2.1",
3+
"version": "0.2.2",
44
"description": "Store & collaborate on text files over the Matrix protocol",
55
"author": "Nathan Pennie",
66
"license": "GPL-3.0",
@@ -14,7 +14,7 @@
1414
"test": "jest"
1515
},
1616
"dependencies": {
17-
"@kb1rd/logootish-js": "0.3.1",
17+
"@kb1rd/logootish-js": "0.4.2",
1818
"@nuxtjs/axios": "^5.3.6",
1919
"bootstrap-vue": "^2.5.0",
2020
"codemirror": "^5.48.2",

pages/edit/_room.vue

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,9 @@ export default {
136136
this.documentInsert = ({ pos, body }) => doc.insert(pos, body)
137137
this.documentRemove = ({ pos, length }) => doc.remove(pos, length)
138138
this.fetchEvents = (n) => {
139-
doc
140-
.fetchEvents(n)
141-
.catch((e) => {
142-
debug.error(e)
143-
})
139+
doc.fetchEvents(n).catch((e) => {
140+
debug.error(e)
141+
})
144142
}
145143
} catch (e) {
146144
debug.error('Failed to open document', e)

0 commit comments

Comments
 (0)