123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382 |
- <template>
- <div class='route_container'>
- <div class='thread_sorting'>
- <select-options
- :options='filterOptions'
- v-model='selectedFilterOption'
- class='thread_sorting__filter'
- ></select-options>
- <button class='button button--blue' v-if='this.$store.state.username' @click='$router.push("/thread/new")'>Post new thread</button>
- </div>
- <div class='threads_main'>
- <div class='threads_main__side_bar'>
- <div class='threads_main__side_bar__title'>
- categories
- </div>
- <div
- v-for='category in categories'
- class='threads_main__side_bar__menu_item'
- :class='{"threads_main__side_bar__menu_item--selected": category.value === selectedCategory}'
- @click='selectedCategory = category.value'
- >
- <span
- class='threads_main__side_bar__menu_item__border'
- :style='{"background-color": category.color}'
- ></span>
- <span
- class='threads_main__side_bar__menu_item__text'
- :style='{
- "color": category.value === selectedCategory ? category.color : undefined
- }'
- >{{category.name}}</span>
- </div>
- </div>
- <scroll-load
- class='threads_main__threads'
- v-if='filteredThreads.length'
- :loading='loading'
- @loadNext='getThreads'
- >
- <thread-display-placeholder v-for='n in newThreads' v-if='loadingNewer'></thread-display-placeholder>
- <div class='threads_main__load_new' v-if='newThreads' @click='getNewerThreads'>
- Load {{newThreads}} new {{newThreads | pluralize('thread')}}</span>
- </div>
- <thread-display v-for='thread in filteredThreads' :thread='thread'></thread-display>
- <thread-display-placeholder v-for='n in nextThreadsCount' v-if='loading'></thread-display-placeholder>
- </scroll-load>
- <div v-else class='threads_main__threads thread--empty'>
- <span class='fa fa-exclamation-circle'></span>
- No threads or posts.
- </div>
- </div>
- </div>
- </template>
- <script>
- import TabView from '../TabView'
- import ScrollLoad from '../ScrollLoad'
- import ThreadDisplay from '../ThreadDisplay'
- import ThreadDisplayPlaceholder from '../ThreadDisplayPlaceholder'
- import SelectOptions from '../SelectOptions'
- import AjaxErrorHandler from '../../assets/js/errorHandler'
- export default {
- name: 'index',
- components: {
- TabView,
- ScrollLoad,
- ThreadDisplay,
- ThreadDisplayPlaceholder,
- SelectOptions
- },
- data () {
- return {
- filterOptions: [
- {name: 'New', value: 'NEW'},
- {name: 'Most active', value: 'MOST_ACTIVE'},
- {name: 'No replies', value: 'NO_REPLIES'}
- ],
- selectedFilterOption: 'NEW',
- nextURL: '',
- nextThreadsCount: 0,
- loading: false,
- threads: [],
- newThreads: 0,
- loadingNewer: false
- }
- },
- computed: {
- filteredThreads () {
- var categories = {};
- var filter = this.selectedFilterOption
- this.$store.state.meta.categories.forEach(category => {
- categories[category.value] = category.name;
- });
- return this.threads.filter(thread => {
- return (thread.Category.value === this.selectedCategory) || (this.selectedCategory === 'ALL');
- }).map(thread => {
- var _thread = Object.assign({}, thread);
- _thread.category = categories[thread.Category.value];
- return _thread;
- }).sort((a, b) => {
- if(filter === 'NEW') {
- let aDate = new Date(a.Posts[0].createdAt)
- let bDate = new Date(b.Posts[0].createdAt)
- return bDate - aDate;
- } else if(filter === 'MOST_ACTIVE') {
- return b.postsCount - a.postsCount;
- }
- }).filter(thread => {
- if(filter === 'NO_REPLIES' && thread.postsCount-1) {
- return false
- } else {
- return true;
- }
- });
- },
- categories () {
- return this.$store.getters.alphabetizedCategories
- },
- selectedCategory: {
- set (val) {
- let name = this.categories.find(c => c.value === val)
- this.$store.dispatch('setTitle', name ? name.name : '')
- this.$store.commit('setSelectedCategory', val)
- },
- get () {
- return this.$store.state.category.selectedCategory
- }
- }
- },
- methods: {
- navigateToThread (slug, id) {
- this.$router.push('/thread/' + slug + '/' + id);
- },
- getThreads (initial) {
- if(this.nextURL === null && !initial) return
- let URL = '/api/v1/category/' + this.selectedCategory
- if(!initial) {
- URL = this.nextURL || URL
- }
- this.loading = true
- this.axios
- .get(URL)
- .then(res => {
- this.loading = false
- if(initial) {
- this.threads = res.data.Threads
- } else {
- this.threads.push(...res.data.Threads)
- }
- this.nextURL = res.data.meta.nextURL
- this.nextThreadsCount = res.data.meta.nextThreadsCount
- })
- .catch((e) => {
- this.loading = false
- AjaxErrorHandler(this.$store)(e)
- })
- },
- getNewerThreads () {
- this.loadingNewer = true
- this.axios
- .get('/api/v1/category/' + this.selectedCategory + '?limit=' + this.newThreads)
- .then(res => {
- this.loadingNewer = false
- this.newThreads = 0
- this.threads.unshift(...res.data.Threads)
- })
- .catch((e) => {
- this.loadingNewer = false
- AjaxErrorHandler(this.$store)(e)
- })
- }
- },
- watch: {
- selectedCategory (newValue) {
- this.$router.push('/category/' + newValue.toLowerCase());
- },
- $route () {
- this.selectedCategory = this.$route.path.split('/')[2].toUpperCase()
- this.newThreads = 0
- this.getThreads(true)
- }
- },
- created () {
- this.selectedCategory = this.$route.path.split('/')[2].toUpperCase()
- this.getThreads(true)
- socket.emit('join', 'index')
- socket.on('new thread', data => {
- if(data.value === this.selectedCategory || this.selectedCategory == 'ALL') {
- this.newThreads++
- }
- })
- },
- destroyed () {
- socket.emit('leave', 'index')
- socket.off('new thread')
- }
- }
- </script>
- <style lang='scss' scoped>
- @import '../../assets/scss/elementStyles.scss';
- @import '../../assets/scss/variables.scss';
- .forum_description {
- padding: 1rem;
- margin-bottom: 2rem;
- background-color: #fff;
- border-radius: 0.25rem;
-
- @extend .shadow_border;
- }
- .threads_main {
- display: flex;
- }
- .thread_sorting {
- margin-bottom: 1rem;
- display: flex;
- justify-content: space-between;
- @at-root #{&}__display {
- padding-right: 0.5rem;
- border-right: thin solid $color__gray--primary;
- margin-right: 1.25rem;
- width: 10rem;
- }
- }
- .threads_main__side_bar {
- width: 12rem;
- height: 0%;
- @extend .shadow_border;
- background: #fff;
- margin-top: 0.15rem;
- margin-right: 1rem;
- border-radius: 0.25rem;
- padding: 0.5rem 0 1rem 1rem;
- @at-root #{&}__title {
- cursor: default;
- font-weight: 500;
- font-variant: small-caps;
- font-size: 1.125rem;
- }
- @at-root #{&}__menu_item {
- cursor: pointer;
- margin-top: 0.5rem;
- position: relative;
- #{&}__border {
- display: inline-block;
- height: 0.75rem;
- width: 0.75rem;
- border-radius: 0.25rem;
- opacity: 0.5;
- background-color: $color__gray--darkest;
- position: relative;
- top: 0.05rem;
- transition: all 0.2s;
- }
- &:hover #{&}__border {
- opacity: 1;
- }
- &:active #{&}__border {
- filter: brightness(0.8);
- }
- #{&}__text {
- filter: saturate(0.75), brightness(0.75);
- }
-
- #{&}--selected {
- font-weight: 500;
- .threads_main__side_bar__menu_item__border {
- opacity: 1;
- &:active {
- filter: brightness(1);
- }
- }
- }
- }
- }
- .threads_main__threads {
- border-collapse: collapse;
- margin-top: 0.25rem;
- margin-left: 1rem;
- width: calc(100% - 11rem);
- }
- .threads_main__load_new {
- @extend .button;
- font-size: 1.25rem;
- margin: 0 0 1rem 0;
- background-color: $color__lightgray--primary;
- border-color: $color__gray--darker;
- width: 100%;
- font-weight: 300;
- }
- .thread {
- background-color: #fff;
- padding: 0.5rem 0;
- cursor: default;
- text-align: left;
- transition: background-color 0.2s;
- &:hover {
- background-color: $color__lightgray--primary;
- }
- td, th {
- padding: 0.3rem 0.5rem;
- border-bottom: solid thin $color__lightgray--primary;
- }
- @at-root #{&}--header {
- &:hover {
- background-color: #fff;
- }
- th {
- font-weight: 400;
- padding-bottom: 0.25rem;
- border-bottom: thin solid $color__lightgray--darkest;
- }
- }
- @at-root #{&}--empty {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- padding-right: 5rem;
- font-size: 2rem;
- user-select: none;
- cursor: default;
- transition: none;
- color: $color__gray--darkest;
- span {
- font-size: 4rem;
- color: $color__gray--darker;
- }
- }
- @at-root #{&}__section {
- padding: 0 0.5rem;
- }
- @at-root #{&}__user {
- display: inline-block;
- }
- @at-root #{&}__date {
- color: $color__text--secondary;
- display: inline-block;
- }
- }
- </style>
|