fix(frontend): various papercuts

- properly refreshes branches when new one is created
- no longer edits the prop on commit edit
- increases toast timeout to 10s
- allows for stream owner commit editing
This commit is contained in:
Dimitrie Stefanescu
2022-06-20 10:32:13 +01:00
parent df29ab89bf
commit f6cb75e1d8
7 changed files with 58 additions and 43 deletions
@@ -259,12 +259,9 @@ body::-webkit-scrollbar {
.spinning-icon {
animation: spinner-spin 0.5s linear infinite;
}
<<<<<<< HEAD
}
.no-mouse {
pointer-events: none;
=======
>>>>>>> main
}
.mouse {
pointer-events: auto;
@@ -218,11 +218,7 @@ export default Vue.extend({
top: 0;
left: 0;
<<<<<<< HEAD
z-index: 1;
=======
z-index: 10;
>>>>>>> main
}
.no-scrollbar {
@@ -1,8 +1,8 @@
<template>
<v-snackbar v-model="snack" app bottom color="primary">
<v-snackbar v-model="snack" app bottom color="primary" timeout="10000">
{{ text }}
<template #action="{}">
<v-btn v-if="actionName" :to="to" @click="snack = false">
<v-btn v-if="actionName" :to="to" small @click="snack = false">
{{ actionName }}
</v-btn>
<v-btn small icon @click="snack = false">
@@ -17,7 +17,7 @@
<v-row>
<v-col cols="12" class="pb-0">
<v-text-field
v-model="commit.message"
v-model="message"
label="Message"
:rules="nameRules"
required
@@ -25,7 +25,7 @@
></v-text-field>
<p>Move this commit to a different branch:</p>
<v-select
v-model="commit.branchName"
v-model="newBranch"
filled
rounded
dense
@@ -33,7 +33,6 @@
:items="branchNames"
prepend-icon="mdi-source-branch"
class="pb-5"
@change="setNewBranchName"
/>
</v-col>
</v-row>
@@ -105,7 +104,8 @@ export default {
showDeleteDialog: false,
localBranches: [],
branchCursor: null,
newBranch: null,
newBranch: this.stream.commit.branchName,
message: this.stream.commit.message,
loading: false,
commitIdConfirmation: '',
commit: this.stream.commit,
@@ -126,35 +126,54 @@ export default {
await this.fetchBranches()
},
methods: {
setNewBranchName(newBranch) {
this.newBranch = newBranch
},
async editCommit() {
console.log(this.commit.branch)
this.$mixpanel.track('Commit Action', { type: 'action', name: 'update' })
this.loading = true
try {
await this.$apollo.mutate({
mutation: gql`
mutation commitUpdate($myCommit: CommitUpdateInput!) {
commitUpdate(commit: $myCommit)
}
`,
variables: {
myCommit: {
streamId: this.stream.id,
id: this.commit.id,
message: this.commit.message,
newBranchName: this.newBranch
}
const myCommit = {
streamId: this.stream.id,
id: this.commit.id
}
let messageChanged = false
let branchChanged = false
if (this.commit.message !== this.message) {
messageChanged = true
myCommit.message = this.message
}
if (this.commit.branchName !== this.newBranch) {
branchChanged = true
myCommit.newBranchName = this.newBranch
}
if (messageChanged || branchChanged)
try {
await this.$apollo.mutate({
mutation: gql`
mutation commitUpdate($myCommit: CommitUpdateInput!) {
commitUpdate(commit: $myCommit)
}
`,
variables: { myCommit }
})
} catch (err) {
this.$eventHub.$emit('notification', {
text: err.message
})
}
this.loading = false
this.commit.message = this.message
this.commit.branchName = this.newBranch
if (branchChanged) {
this.$eventHub.$emit('notification', {
text: `Commit moved to branch ${this.newBranch}.`,
action: {
name: 'View Branch',
to: `/streams/${this.$route.params.streamId}/branches/${this.newBranch}`
}
})
} catch (err) {
this.$eventHub.$emit('notification', {
text: err.message
})
}
this.loading = false
this.$emit('close')
},
async deleteCommit() {
@@ -196,7 +215,7 @@ export default {
query Stream($streamId: String!, $cursor: String) {
stream(id: $streamId) {
id
branches(limit: 10, cursor: $cursor) {
branches(limit: 100, cursor: $cursor) {
totalCount
cursor
items {
@@ -215,7 +215,7 @@
>
<new-branch
@close="newBranchDialog = false"
@refetch-branches="$apollo.queries.branchQuery.refetch()"
@refetch-branches="refetchBranches()"
/>
</v-dialog>
</portal>
@@ -327,7 +327,7 @@ export default {
query Stream($streamId: String!, $cursor: String) {
stream(id: $streamId) {
id
branches(limit: 10, cursor: $cursor) {
branches(limit: 100, cursor: $cursor) {
totalCount
cursor
items {
@@ -141,7 +141,7 @@ module.exports = {
},
async commitUpdate(parent, args, context) {
await authorizeResolver(
const role = await authorizeResolver(
context.userId,
args.commit.streamId,
'stream:contributor'
@@ -155,8 +155,10 @@ module.exports = {
id: args.commit.id
})
if (commit.authorId !== context.userId)
throw new ForbiddenError('Only the author of a commit may update it.')
if (commit.authorId !== context.userId || role !== 'stream:owner')
throw new ForbiddenError(
'Only the author of a commit or a stream owner may update it.'
)
const updated = await updateCommit({ ...args.commit })
@@ -101,7 +101,8 @@ module.exports = {
throw new Error('Failed to update commit branch. ')
}
}
return await Commits().where({ id }).update({ message })
if (message) await Commits().where({ id }).update({ message })
return true
},
async getCommitById({ streamId, id }) {