Skip to content

Commit 2f28a8e

Browse files
committed
feat: fix css and add normal pagination for mobile posts view
1 parent 2d8d8f9 commit 2f28a8e

File tree

1 file changed

+52
-26
lines changed

1 file changed

+52
-26
lines changed

src/views/Threads.vue

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,17 @@
198198
</table>
199199
</div>
200200

201+
<div class="mobile-pagination" v-if="threadData.data?.board">
202+
<div class="pagination-wrap">
203+
<simple-pagination
204+
v-model="currentPage"
205+
:pages="pages"
206+
:range-size="1"
207+
@update:modelValue="pageResults"
208+
/>
209+
</div>
210+
</div>
211+
201212
<div class="board-sidebar">
202213
<div class="board-actions" v-if="loggedIn">
203214
<a v-if="canCreate()" class="button secondary" href="#" @click.prevent="showEditor = true">
@@ -224,19 +235,20 @@ import SetModeratorsModal from '@/components/modals/threads/SetModerators.vue'
224235
import humanDate from '@/composables/filters/humanDate'
225236
import decode from '@/composables/filters/decode'
226237
import truncate from '@/composables/filters/truncate'
227-
import { inject, reactive, watch, toRefs } from 'vue'
238+
import { inject, reactive, watch, toRefs, computed } from 'vue'
228239
import { boardsApi, threadsApi, watchlistApi } from '@/api'
229240
import { AuthStore } from '@/composables/stores/auth'
230241
import { PreferencesStore, localStoragePrefs } from '@/composables/stores/prefs'
231242
import { processThreads } from '@/composables/utils/boardUtils'
232243
import BanStore from '@/composables/stores/ban'
233244
import Editor from '@/components/layout/Editor.vue'
234245
import slugify from 'slugify'
246+
import SimplePagination from '@/components/layout/SimplePagination.vue'
235247
236248
export default {
237249
name: 'Threads',
238250
props: ['boardSlug', 'boardId'],
239-
components: { Pagination, SetModeratorsModal, Editor },
251+
components: { Pagination, SetModeratorsModal, Editor, SimplePagination },
240252
beforeRouteEnter(to, from, next) {
241253
const params = {
242254
limit: localStoragePrefs().data.threads_per_page,
@@ -277,6 +289,13 @@ export default {
277289
},
278290
setup(props) {
279291
/* Internal Methods */
292+
const pageResults = page => {
293+
let query = { ...$route.query, page: page }
294+
if (query.page === 1 || !query.page) delete query.page
295+
if ($route.query.page !== v.currentPage)
296+
$router.replace({ name: $route.name, params: $route.params, query: query })
297+
}
298+
280299
const getThreads = () => {
281300
return Promise.resolve(props.boardId)
282301
.then(boardId => {
@@ -363,7 +382,6 @@ export default {
363382
364383
const canModerate = () => {
365384
if (v.banned) return false
366-
console.log(v.threadData?.data?.board, v.threadData?.data?.board?.disable_selfmod)
367385
if (v.threadData?.data?.board?.disable_selfmod) return false
368386
return v.threadData.data?.write_access && v.permissionUtils.hasPermission('threads.moderated.allow')
369387
}
@@ -387,6 +405,8 @@ export default {
387405
388406
/* View Data */
389407
const v = reactive({
408+
currentPage: Number($route.query.page) || 1,
409+
pages: computed(() => Math.ceil(v.threadData?.data?.board?.thread_count / v.threadData?.data?.limit)),
390410
threadData: { data: {} },
391411
showEditor: false,
392412
prefs: $prefs.data,
@@ -423,7 +443,7 @@ export default {
423443
v.banned = BanStore.updateBanNotice(v.threadData.data.banned_from_board)
424444
})) // Update threads on login
425445
426-
return { ...toRefs(v), createThread, canCreate, canSetModerator, canLock, canSticky, canModerate, canCreatePoll, watchBoard, setSortField, getSortClass, humanDate, decode, truncate }
446+
return { ...toRefs(v), pageResults, createThread, canCreate, canSetModerator, canLock, canSticky, canModerate, canCreatePoll, watchBoard, setSortField, getSortClass, humanDate, decode, truncate }
427447
}
428448
}
429449
</script>
@@ -448,6 +468,27 @@ export default {
448468
}
449469
}
450470
471+
.mobile-pagination {
472+
display: none;
473+
@include break-mobile-sm {
474+
border-top: 1px solid $border-color;
475+
position: fixed;
476+
bottom: 0;
477+
right: 0;
478+
left: 0;
479+
background: $base-background-color;
480+
padding: 0.75rem;
481+
z-index: 1000;
482+
margin: 0 auto;
483+
width: 100vw;
484+
display: block;
485+
486+
.pagination-wrap > ul {
487+
margin: 0 auto;
488+
width: fit-content;
489+
}
490+
}
491+
}
451492
452493
.board-controls {
453494
background-color: $base-background-color;
@@ -467,32 +508,12 @@ export default {
467508
font-weight: 600;
468509
text-transform: none;
469510
}
470-
471-
pagination {
472-
justify-self: end;
473-
}
474-
475-
@include break-mobile-sm {
476-
grid-template-columns: 1fr;
477-
margin-left: -1rem;
478-
margin-right: -1rem;
479-
padding-left: 1rem;
480-
padding-right: 1rem;
481-
width: 100vw;
482-
483-
pagination {
484-
justify-self: center;
485-
}
486-
}
487511
}
488512
489513
.board-data {
490514
padding-left: 1rem;
491515
grid-area: main;
492-
493-
@include break-min-large {
494-
// grid-column: auto;
495-
}
516+
width: 100%;
496517
}
497518
498519
.board-sidebar {
@@ -507,6 +528,8 @@ export default {
507528
508529
@include break-mobile-sm {
509530
margin-bottom: 1rem;
531+
width: 100%;
532+
.pagination-component { display: none; }
510533
}
511534
512535
@media screen and (min-width: 1280px) {
@@ -635,7 +658,10 @@ export default {
635658
padding: 0;
636659
-webkit-appearance: auto;
637660
width: initial;
638-
};
661+
}
662+
@include break-mobile-sm {
663+
text-align: left;
664+
}
639665
}
640666
641667

0 commit comments

Comments
 (0)