Show error message if searching is not available

This commit is contained in:
Aya Morisawa 2018-07-19 08:24:03 +09:00
parent 7e27e2757f
commit e03ec67b5c
2 changed files with 28 additions and 6 deletions

View File

@ -6,6 +6,7 @@
<div :class="$style.loading" v-if="fetching"> <div :class="$style.loading" v-if="fetching">
<mk-ellipsis-icon/> <mk-ellipsis-icon/>
</div> </div>
<p :class="$style.notAvailable" v-if="!fetching && notAvailable">検索機能を利用することができません</p>
<p :class="$style.empty" v-if="!fetching && empty">%fa:search%{{ q }}に関する投稿は見つかりませんでした</p> <p :class="$style.empty" v-if="!fetching && empty">%fa:search%{{ q }}に関する投稿は見つかりませんでした</p>
<mk-notes ref="timeline" :class="$style.notes" :more="existMore ? more : null"/> <mk-notes ref="timeline" :class="$style.notes" :more="existMore ? more : null"/>
</mk-ui> </mk-ui>
@ -24,7 +25,8 @@ export default Vue.extend({
moreFetching: false, moreFetching: false,
existMore: false, existMore: false,
offset: 0, offset: 0,
empty: false empty: false,
notAvailable: false
}; };
}, },
watch: { watch: {
@ -71,7 +73,11 @@ export default Vue.extend({
res(notes); res(notes);
this.fetching = false; this.fetching = false;
Progress.done(); Progress.done();
}, rej); }, (e: string) => {
this.fetching = false;
Progress.done();
if (e === 'searching not available') this.notAvailable = true;
});
})); }));
}, },
more() { more() {
@ -130,4 +136,18 @@ export default Vue.extend({
font-size 3em font-size 3em
color #ccc color #ccc
.notAvailable
display block
margin 0 auto
padding 32px
max-width 400px
text-align center
color #999
> [data-fa]
display block
margin-bottom 16px
font-size 3em
color #ccc
</style> </style>

View File

@ -18,6 +18,8 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) =>
const [limit = 10, limitErr] = $.num.optional.range(1, 30).get(params.limit); const [limit = 10, limitErr] = $.num.optional.range(1, 30).get(params.limit);
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');
if (es == null) return rej('searching not available');
es.search({ es.search({
index: 'misskey', index: 'misskey',
type: 'note', type: 'note',
@ -53,10 +55,10 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) =>
$in: hits $in: hits
} }
}, { }, {
sort: { sort: {
_id: -1 _id: -1
} }
}); });
res(await Promise.all(notes.map(note => pack(note, me)))); res(await Promise.all(notes.map(note => pack(note, me))));
}); });