Skip to content

Commit afad766

Browse files
committed
#11 #1 Cleaning up the code. Working on the selection logic.
1 parent f09ebd3 commit afad766

File tree

5 files changed

+32
-34
lines changed

5 files changed

+32
-34
lines changed

components/RecordingItem.vue

+1-6
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,10 @@ export default {
113113
}`
114114
115115
this.track.addEventListener('loadeddata', () => {
116-
console.log('finished loading')
117-
console.log(this.track.duration)
118116
this.totalDuration = getMMSS(this.track.duration)
119117
})
120118
121119
this.track.addEventListener('ended', () => {
122-
console.log('ended!')
123120
this.isPlaying = false
124121
})
125122
@@ -142,9 +139,7 @@ export default {
142139
}
143140
},
144141
seek(payload) {
145-
if (typeof payload === 'number') {
146-
this.track.currentTime = (payload * this.track.duration) / 100
147-
}
142+
this.track.currentTime = (payload * this.track.duration) / 100
148143
}
149144
}
150145
}

components/RecordingsList.vue

+11-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
<v-list-item-group
44
v-model="selected"
55
mandatory
6-
@change="$emit('input', selected)"
6+
@change="
7+
$emit(
8+
'input',
9+
recordingsInternal[selected] ? recordingsInternal[selected].id : null
10+
)
11+
"
712
>
813
<div v-for="(recording, index) in recordingsInternal" :key="recording.id">
914
<recording-item
@@ -27,7 +32,7 @@ export default {
2732
},
2833
props: {
2934
value: {
30-
type: Number,
35+
type: String,
3136
default: null
3237
},
3338
recordings: {
@@ -37,17 +42,18 @@ export default {
3742
},
3843
data() {
3944
return {
40-
selected: this.selectedItem,
45+
selected: null,
4146
recordingsInternal: this.recordings
4247
}
4348
},
4449
methods: {
4550
remove(id) {
46-
console.log(id)
4751
const index = this.recordings.findIndex(
4852
(recording) => recording.id === id
4953
)
50-
54+
if (this.selected === index) {
55+
this.$emit('input', null)
56+
}
5157
this.recordingsInternal.splice(index, 1)
5258
}
5359
}

functions/store_file.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// const { MongoClient } = require('mongodb')
21
import { MongoClient } from 'mongodb'
32

43
exports.handler = function(event, context, callback) {

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"generate": "nuxt generate",
1212
"lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
1313
"test": "jest",
14-
"deploy": "nuxt build; netlify-lambda build functions"
14+
"deploy": "nuxt build; netlify-lambda build functions",
15+
"fn": "netlify-lambda serve functions"
1516
},
1617
"lint-staged": {
1718
"*.{js,vue}": "npm run lint",

pages/index.vue

+18-21
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,27 @@
4747

4848
<recordings-list
4949
v-if="recordings.length"
50-
v-model="selected"
50+
v-model="selectedRecording"
5151
:recordings="recordings"
5252
></recordings-list>
53-
54-
selected: {{ selected }}
5553
</v-card-text>
5654
</v-card>
5755

5856
<v-card class="mt-4">
5957
<v-card-text>
6058
<v-text-field
59+
v-model="name"
6160
name="name"
6261
label="Your Name"
6362
single-line
6463
></v-text-field>
6564
</v-card-text>
6665
<v-card-actions>
6766
<v-spacer></v-spacer>
68-
<v-btn color="primary" :disabled="!recordings.length && !selected"
67+
<v-btn
68+
color="primary"
69+
:disabled="!selectedRecording || !name"
70+
@click="sendRecording"
6971
>Send it!</v-btn
7072
>
7173
</v-card-actions>
@@ -93,16 +95,14 @@ export default {
9395
recorder: null,
9496
input: null,
9597
audioContext: null,
96-
selected: null,
98+
selectedRecording: null,
9799
timerStatus: 'stopped',
98100
recordings: [],
99101
count: 0,
100-
TIME_LIMIT: 60
102+
TIME_LIMIT: 60,
103+
name: ''
101104
}
102105
},
103-
created() {
104-
console.log(typeof WebAudioRecorder)
105-
},
106106
methods: {
107107
toggleRecorder() {
108108
this.isRecording = !this.isRecording
@@ -153,13 +153,15 @@ export default {
153153
const url = URL.createObjectURL(blob)
154154
// the url already gives us a unique id, so we might as well use that :D
155155
const id = url.split('3333/')[1]
156-
this.recordings.push({
156+
const recording = {
157157
number: ++this.count,
158158
id,
159159
audio: url,
160160
encoding: ENCODING_TYPE
161-
})
161+
}
162+
this.recordings.push(recording)
162163
},
164+
// stop the recording when time is up
163165
onTimeout: this.stopRecording
164166
})
165167
@@ -184,21 +186,16 @@ export default {
184186
this.isRecording = false
185187
this.timerStatus = 'stopped'
186188
187-
// // stop microphone access
188-
// //! can't do this, otherwise can't record further notes
189-
190-
// // see https://blog.addpipe.com/using-webaudiorecorder-js-to-record-audio-on-your-website/
191-
// // I don't understand why they initialize the recording object
192-
// // every single time a new recording is started 🤔
189+
// stop microphone access
190+
// see https://blog.addpipe.com/using-webaudiorecorder-js-to-record-audio-on-your-website/
193191
this.getUserMediaStream.getAudioTracks()[0].stop()
194192
195193
// tell the recorder to finish the recording (stop recording + encode the recorded audio)
196194
this.recorder.finishRecording()
197195
console.warn('Recording stopped')
198-
// },
199-
// log(event) {
200-
// console.warnData += event + `<br>`
201-
// }
196+
},
197+
sendRecording() {
198+
console.log(this.selectedRecording)
202199
}
203200
},
204201
head() {

0 commit comments

Comments
 (0)