Fix request/reports not filtering and form auto focussing on mounted when `autofocus` is `false`

This commit is contained in:
wvffle 2022-11-02 13:53:44 +00:00 committed by JuniorJPDJ
parent 66fd99c246
commit 8a1cdd27d5
4 changed files with 15 additions and 8 deletions

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import axios from 'axios' import axios from 'axios'
import { useVModel, watchDebounced, useTextareaAutosize, syncRef } from '@vueuse/core' import { useVModel, watchDebounced, useTextareaAutosize, syncRef } from '@vueuse/core'
import { ref, computed, watchEffect, onMounted, nextTick } from 'vue' import { ref, computed, watchEffect, onMounted, nextTick, watch } from 'vue'
import { useGettext } from 'vue3-gettext' import { useGettext } from 'vue3-gettext'
interface Events { interface Events {
@ -61,14 +61,15 @@ watchEffect(async () => {
if (value.value && !preview.value && !isLoadingPreview.value) { if (value.value && !preview.value && !isLoadingPreview.value) {
await loadPreview() await loadPreview()
} }
return
} }
await nextTick()
textarea.value.focus()
}) })
watch(isPreviewing, (to, from) => {
if (from === true) {
textarea.value.focus()
}
}, { flush: 'post' })
onMounted(async () => { onMounted(async () => {
if (props.autofocus) { if (props.autofocus) {
await nextTick() await nextTick()

View File

@ -157,6 +157,7 @@ export default [
path: 'reports', path: 'reports',
name: 'manage.moderation.reports.list', name: 'manage.moderation.reports.list',
component: () => import('~/views/admin/moderation/ReportsList.vue'), component: () => import('~/views/admin/moderation/ReportsList.vue'),
props: route => ({ defaultQuery: route.query.q }),
meta: { meta: {
paginateBy: 25 paginateBy: 25
} }
@ -171,6 +172,7 @@ export default [
path: 'requests', path: 'requests',
name: 'manage.moderation.requests.list', name: 'manage.moderation.requests.list',
component: () => import('~/views/admin/moderation/RequestsList.vue'), component: () => import('~/views/admin/moderation/RequestsList.vue'),
props: route => ({ defaultQuery: route.query.q }),
meta: { meta: {
paginateBy: 25 paginateBy: 25
} }

View File

@ -25,11 +25,13 @@ interface Props extends SmartSearchProps, OrderingProps {
mode?: 'card' mode?: 'card'
// TODO(wvffle): Remove after https://github.com/vuejs/core/pull/4512 is merged // TODO(wvffle): Remove after https://github.com/vuejs/core/pull/4512 is merged
defaultQuery?: string
orderingConfigName?: RouteRecordName orderingConfigName?: RouteRecordName
updateUrl?: boolean updateUrl?: boolean
} }
const props = withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {
defaultQuery: '',
updateUrl: false, updateUrl: false,
mode: 'card', mode: 'card',
orderingConfigName: undefined orderingConfigName: undefined
@ -81,7 +83,7 @@ const fetchData = async () => {
} }
onSearch(() => (page.value = 1)) onSearch(() => (page.value = 1))
watch(page, fetchData) watch([page, query], fetchData)
onOrderingUpdate(fetchData) onOrderingUpdate(fetchData)
fetchData() fetchData()

View File

@ -22,11 +22,13 @@ import usePage from '~/composables/navigation/usePage'
interface Props extends SmartSearchProps, OrderingProps { interface Props extends SmartSearchProps, OrderingProps {
// TODO(wvffle): Remove after https://github.com/vuejs/core/pull/4512 is merged // TODO(wvffle): Remove after https://github.com/vuejs/core/pull/4512 is merged
defaultQuery?: string
orderingConfigName?: RouteRecordName orderingConfigName?: RouteRecordName
updateUrl?: boolean updateUrl?: boolean
} }
const props = withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {
defaultQuery: '',
updateUrl: false, updateUrl: false,
orderingConfigName: undefined orderingConfigName: undefined
}) })
@ -77,7 +79,7 @@ const fetchData = async () => {
} }
onSearch(() => (page.value = 1)) onSearch(() => (page.value = 1))
watch(page, fetchData) watch([page, query], fetchData)
onOrderingUpdate(fetchData) onOrderingUpdate(fetchData)
fetchData() fetchData()