a bit clearer draft editing flow, partially divorced menu-item from list-item

This commit is contained in:
Henry Jameson 2024-12-30 03:10:11 +02:00
parent 8657c820bd
commit 68e8a24f18
8 changed files with 74 additions and 32 deletions

View file

@ -390,6 +390,20 @@ nav {
} }
} }
.menu-item {
line-height: var(--__line-height);
font-family: inherit;
font-weight: 400;
font-size: 100%;
cursor: pointer;
a,
button:not(.button-default) {
color: var(--text);
font-size: 100%;
}
}
.menu-item, .menu-item,
.list-item { .list-item {
display: block; display: block;
@ -397,10 +411,6 @@ nav {
border: none; border: none;
outline: none; outline: none;
text-align: initial; text-align: initial;
font-size: inherit;
font-family: inherit;
font-weight: 400;
cursor: pointer;
color: inherit; color: inherit;
clear: both; clear: both;
position: relative; position: relative;
@ -410,7 +420,6 @@ nav {
border-width: 0; border-width: 0;
border-top-width: 1px; border-top-width: 1px;
width: 100%; width: 100%;
line-height: var(--__line-height);
padding: var(--__vertical-gap) var(--__horizontal-gap); padding: var(--__vertical-gap) var(--__horizontal-gap);
background: transparent; background: transparent;
@ -450,10 +459,8 @@ nav {
border: none; border: none;
outline: none; outline: none;
display: inline; display: inline;
font-size: 100%;
font-family: inherit; font-family: inherit;
line-height: unset; line-height: unset;
color: var(--text);
} }
&:first-child { &:first-child {

View file

@ -3,6 +3,7 @@ import EditStatusForm from 'src/components/edit_status_form/edit_status_form.vue
import ConfirmModal from 'src/components/confirm_modal/confirm_modal.vue' import ConfirmModal from 'src/components/confirm_modal/confirm_modal.vue'
import StatusContent from 'src/components/status_content/status_content.vue' import StatusContent from 'src/components/status_content/status_content.vue'
import Gallery from 'src/components/gallery/gallery.vue' import Gallery from 'src/components/gallery/gallery.vue'
import { cloneDeep } from 'lodash'
const Draft = { const Draft = {
components: { components: {
@ -19,8 +20,8 @@ const Draft = {
} }
}, },
data () { data () {
console.log('DRAFT', this.draft)
return { return {
referenceDraft: cloneDeep(this.draft),
editing: false, editing: false,
showingConfirmDialog: false showingConfirmDialog: false
} }
@ -35,6 +36,11 @@ const Draft = {
return {} return {}
} }
}, },
safeToSave () {
return this.draft.status ||
this.draft.files?.length ||
this.draft.hasPoll
},
postStatusFormProps () { postStatusFormProps () {
return { return {
draftId: this.draft.id, draftId: this.draft.id,
@ -48,7 +54,6 @@ const Draft = {
return this.$store.getters.mergedConfig.collapseMessageWithSubject return this.$store.getters.mergedConfig.collapseMessageWithSubject
}, },
nsfwClickthrough () { nsfwClickthrough () {
console.log(this.draft)
if (!this.draft.nsfw) { if (!this.draft.nsfw) {
return false return false
} }
@ -58,6 +63,16 @@ const Draft = {
return true return true
} }
}, },
watch: {
editing (newVal) {
if (newVal) return
if (this.safeToSave) {
this.$store.dispatch('addOrSaveDraft', { draft: this.draft })
} else {
this.$store.dispatch('addOrSaveDraft', { draft: this.referenceDraft })
}
}
},
methods: { methods: {
toggleEditing () { toggleEditing () {
this.editing = !this.editing this.editing = !this.editing

View file

@ -44,10 +44,12 @@
<div v-if="editing"> <div v-if="editing">
<PostStatusForm <PostStatusForm
v-if="draft.type !== 'edit'" v-if="draft.type !== 'edit'"
:disable-draft="true"
v-bind="postStatusFormProps" v-bind="postStatusFormProps"
/> />
<EditStatusForm <EditStatusForm
v-else v-else
:disable-draft="true"
:params="postStatusFormProps" :params="postStatusFormProps"
/> />
</div> </div>
@ -66,11 +68,10 @@
<div class="actions"> <div class="actions">
<button <button
class="btn button-default" class="btn button-default"
:class="{ toggled: editing }"
:aria-expanded="editing" :aria-expanded="editing"
@click.prevent.stop="toggleEditing" @click.prevent.stop="toggleEditing"
> >
{{ $t('drafts.continue') }} {{ editing ? $t('drafts.save') : $t('drafts.continue') }}
</button> </button>
<button <button
class="btn button-default" class="btn button-default"
@ -87,6 +88,8 @@
<style lang="scss"> <style lang="scss">
.Draft { .Draft {
position: relative; position: relative;
line-height: 1.1;
font-size: initial;
a { a {
color: var(--link); color: var(--link);
@ -119,7 +122,6 @@
flex: 1; flex: 1;
margin-left: 1em; margin-left: 1em;
margin-right: 1em; margin-right: 1em;
max-width: 10em;
} }
} }
} }

View file

@ -16,6 +16,7 @@
> >
<template #item="{ item: draft }"> <template #item="{ item: draft }">
<Draft <Draft
class="draft"
:draft="draft" :draft="draft"
/> />
</template> </template>
@ -26,3 +27,9 @@
</template> </template>
<script src="./drafts.js"></script> <script src="./drafts.js"></script>
<style lang="scss">
.draft {
margin: 1em 0;
}
</style>

View file

@ -118,7 +118,8 @@ const PostStatusForm = {
'resize', 'resize',
'mediaplay', 'mediaplay',
'mediapause', 'mediapause',
'can-close' 'can-close',
'update'
], ],
components: { components: {
MediaUpload, MediaUpload,
@ -218,7 +219,7 @@ const PostStatusForm = {
emojiInputShown: false, emojiInputShown: false,
idempotencyKey: '', idempotencyKey: '',
saveInhibited: true, saveInhibited: true,
savable: false saveable: false
} }
}, },
computed: { computed: {
@ -343,7 +344,7 @@ const PostStatusForm = {
return this.$store.getters.mergedConfig.autoSaveDraft return this.$store.getters.mergedConfig.autoSaveDraft
}, },
autoSaveState () { autoSaveState () {
if (this.savable) { if (this.saveable) {
return this.$t('post_status.auto_save_saving') return this.$t('post_status.auto_save_saving')
} else if (this.newStatus.id) { } else if (this.newStatus.id) {
return this.$t('post_status.auto_save_saved') return this.$t('post_status.auto_save_saved')
@ -363,7 +364,7 @@ const PostStatusForm = {
this.statusChanged() this.statusChanged()
} }
}, },
savable (val) { saveable (val) {
// https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event#usage_notes // https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event#usage_notes
// MDN says we'd better add the beforeunload event listener only when needed, and remove it when it's no longer needed // MDN says we'd better add the beforeunload event listener only when needed, and remove it when it's no longer needed
if (val) { if (val) {
@ -382,7 +383,7 @@ const PostStatusForm = {
this.autoPreview() this.autoPreview()
this.updateIdempotencyKey() this.updateIdempotencyKey()
this.debouncedMaybeAutoSaveDraft() this.debouncedMaybeAutoSaveDraft()
this.savable = true this.saveable = true
this.saveInhibited = false this.saveInhibited = false
}, },
clearStatus () { clearStatus () {
@ -411,7 +412,7 @@ const PostStatusForm = {
el.style.height = undefined el.style.height = undefined
this.error = null this.error = null
if (this.preview) this.previewStatus() if (this.preview) this.previewStatus()
this.savable = false this.saveable = false
}, },
async postStatus (event, newStatus, opts = {}) { async postStatus (event, newStatus, opts = {}) {
if (this.posting && !this.optimisticPosting) { return } if (this.posting && !this.optimisticPosting) { return }
@ -754,13 +755,13 @@ const PostStatusForm = {
if (this.newStatus.id !== id) { if (this.newStatus.id !== id) {
this.newStatus.id = id this.newStatus.id = id
} }
this.savable = false this.saveable = false
}) })
} else if (this.newStatus.id) { } else if (this.newStatus.id) {
// There is a draft, but there is nothing in it, clear it // There is a draft, but there is nothing in it, clear it
return this.abandonDraft() return this.abandonDraft()
.then(() => { .then(() => {
this.savable = false this.saveable = false
}) })
} }
} }
@ -788,7 +789,7 @@ const PostStatusForm = {
// No draft available, fall back // No draft available, fall back
}, },
requestClose () { requestClose () {
if (!this.savable) { if (!this.saveable) {
this.$emit('can-close') this.$emit('can-close')
} else { } else {
this.$refs.draftCloser.requestClose() this.$refs.draftCloser.requestClose()

View file

@ -5,14 +5,31 @@
margin-bottom: 0.5em; margin-bottom: 0.5em;
} }
.more-post-actions {
height: 100%;
.btn {
height: 100%;
}
}
.form-bottom { .form-bottom {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
padding: 0.5em; padding: 0.5em;
height: 2.5em; height: 2.5em;
.post-button { .post-button-group {
width: 7.5em; width: 10em;
display: flex;
.post-button {
flex: 1 0 auto;
}
.more-post-actions {
flex: 0 0 auto;
}
} }
p { p {
@ -22,14 +39,6 @@
} }
} }
.more-post-actions {
height: 100%;
.btn {
height: 100%;
}
}
.form-bottom-left { .form-bottom-left {
display: flex; display: flex;
flex: 1; flex: 1;

View file

@ -302,7 +302,7 @@
<FAIcon icon="poll-h" /> <FAIcon icon="poll-h" />
</button> </button>
</div> </div>
<div class="btn-group"> <div class="btn-group post-button-group">
<button <button
class="btn button-default post-button" class="btn button-default post-button"
:disabled="isOverLengthLimit || posting || uploadingFiles || disableSubmit" :disabled="isOverLengthLimit || posting || uploadingFiles || disableSubmit"

View file

@ -1515,6 +1515,7 @@
"drafts": "Drafts", "drafts": "Drafts",
"no_drafts": "You have no drafts", "no_drafts": "You have no drafts",
"continue": "Continue composing", "continue": "Continue composing",
"save": "Save without posting",
"abandon": "Abandon draft", "abandon": "Abandon draft",
"abandon_confirm_title": "Abandon confirmation", "abandon_confirm_title": "Abandon confirmation",
"abandon_confirm": "Do you really want to abandon this draft?", "abandon_confirm": "Do you really want to abandon this draft?",