index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <div>
  3. <div class="main-content">
  4. <div class="container">
  5. <div class="columns is-mobile">
  6. <!-- posts -->
  7. <div class="column is-8">
  8. <div
  9. v-for="blog in publishedBlogs"
  10. :key="blog._id"
  11. class="section">
  12. <div class="post">
  13. <div @click="$router.push(`/blogs/${blog.slug}`)" class="post-header clickable">
  14. <h4 class="title is-4">{{blog.title}}</h4>
  15. <h5 class="subtitle is-5">{{blog.subtitle}}</h5>
  16. </div>
  17. <div class="post-content">
  18. by {{blog.author.name}}, {{blog.createdAt | formatDate}}
  19. </div>
  20. </div>
  21. </div>
  22. <!-- end of blog -->
  23. <!-- pagination -->
  24. <div class="section">
  25. <no-ssr placeholder="Loading...">
  26. <paginate
  27. v-model="currentPage"
  28. :page-count="pagination.pageCount"
  29. :click-handler="fetchBlogs"
  30. :prev-text="'Prev'"
  31. :next-text="'Next'"
  32. :container-class="'paginationContainer'">
  33. </paginate>
  34. </no-ssr>
  35. </div>
  36. <!-- end of pagination -->
  37. </div>
  38. <!-- side bar -->
  39. <div class="column is-4 is-narrow">
  40. <!-- featured -->
  41. <div class="section">
  42. <div class="sidebar">
  43. <div class="sidebar-header">
  44. <h4 class="title is-4">Featured Posts</h4>
  45. </div>
  46. <div class="sidebar-list">
  47. <!-- Featured Blogs -->
  48. <p
  49. v-for="fBlog in featuredBlogs"
  50. :key="fBlog._id">
  51. <nuxt-link :to="`/blogs/${fBlog.slug}`">
  52. {{fBlog.title}}
  53. </nuxt-link>
  54. </p>
  55. <!-- Featured Blogs -->
  56. </div>
  57. </div>
  58. </div>
  59. </div>
  60. <!-- end of side bar -->
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. </template>
  66. <script>
  67. import { mapState } from 'vuex';
  68. export default {
  69. computed: {
  70. ...mapState({
  71. publishedBlogs: state => state.blog.items.all,
  72. featuredBlogs: state => state.blog.items.featured,
  73. pagination: state => state.blog.pagination
  74. }),
  75. currentPage: {
  76. get() {
  77. return this.$store.state.blog.pagination.pageNum
  78. },
  79. set(value) {
  80. this.$store.commit('blog/setPage', value)
  81. }
  82. }
  83. },
  84. async fetch({store, query}) {
  85. // Try to get values from query
  86. const filter = {}
  87. const {pageNum, pageSize} = query
  88. if (pageNum && pageSize) {
  89. filter.pageNum = parseInt(pageNum, 10)
  90. filter.pageSize = parseInt(pageSize, 10)
  91. store.commit('blog/setPage', filter.pageNum)
  92. } else {
  93. filter.pageNum = 1
  94. filter.pageSize = 6
  95. }
  96. await store.dispatch('blog/fetchBlogs', filter)
  97. await store.dispatch('blog/fetchFeaturedBlogs', {'filter[featured]': true})
  98. },
  99. methods: {
  100. setQueryPaginationParams() {
  101. const { pageSize, pageNum } = this.pagination
  102. this.$router.push({query: {pageNum, pageSize}})
  103. },
  104. async fetchBlogs() {
  105. const filter = {}
  106. filter.pageSize = this.pagination.pageSize
  107. filter.pageNum = this.pagination.pageNum
  108. // Here store the query params!
  109. const result = await this.$store.dispatch('blog/fetchBlogs', filter)
  110. if(result.isAxiosError !== true){
  111. this.setQueryPaginationParams()
  112. }
  113. },
  114. }
  115. }
  116. </script>
  117. <style scoped>
  118. .post-content {
  119. font-style: italic;
  120. }
  121. .pagination-content {
  122. display: flex;
  123. justify-content: flex-end;
  124. }
  125. .clickable {
  126. cursor: pointer;
  127. }
  128. #root {
  129. flex: 1 0 auto;
  130. }
  131. *:focus {
  132. outline: none;
  133. }
  134. a {
  135. transition: all .35s;
  136. color: #000;
  137. }
  138. .button:focus {
  139. border-color: #d74436;
  140. box-shadow: 0 0 0 0;
  141. }
  142. .input, .textarea, .input[type] {
  143. font-size: 1.1rem;
  144. }
  145. .input:focus, .textarea:focus, .input[type]:focus {
  146. border: 2px solid #d74436;
  147. }
  148. /* this is used when inline-styled content
  149. overlaps text backgrounds in a really ugly way */
  150. .buffer {
  151. padding-bottom: 1.1rem;
  152. }
  153. /* navigation */
  154. .nav {
  155. background-color: #0d0c0d;
  156. }
  157. .nav-left {
  158. padding-left: 2rem;
  159. }
  160. .nav-right, .nav-center {
  161. padding-right: 2rem;
  162. }
  163. a.nav-item.is-tab {
  164. font-weight: 700;
  165. font-size: 13px;
  166. text-transform: uppercase;
  167. color: #fff;
  168. padding: 0.4rem;
  169. }
  170. a.nav-item:hover {
  171. color: #d74436;
  172. }
  173. a.nav-item.is-tab:hover {
  174. border-bottom: 4px solid #d74436;
  175. }
  176. /* main content */
  177. .main-content {
  178. padding: 4rem 0 2rem 0;
  179. min-height: 800px
  180. }
  181. .main-content .container {
  182. padding: 0 2rem 2rem 2rem;
  183. }
  184. /* section */
  185. .section {
  186. padding: 0 0 2rem 0;
  187. }
  188. .section-header {
  189. padding-bottom: 3rem;
  190. }
  191. .section-header .title {
  192. text-transform: uppercase;
  193. color: #4a4a4a;
  194. font-size: 1.3rem;
  195. }
  196. .section-header a {
  197. color: #d74436;
  198. font-weight: 700;
  199. }
  200. .section-header a:hover {
  201. color: #e50076;
  202. }
  203. /* sidebar */
  204. .sidebar-header {
  205. border-color: #d74436;
  206. padding-bottom: 1rem;
  207. border-bottom: 4px solid #d74436;
  208. }
  209. .sidebar-header .title, .sidebar-header-single .title {
  210. font-weight: 700;
  211. text-transform: uppercase;
  212. font-size: 1.3rem;
  213. }
  214. .sidebar-list p, .sidebar-list-single p {
  215. font-size: 1.1rem;
  216. font-weight: 300;
  217. padding-bottom: 0.8rem;
  218. }
  219. .sidebar-list a {
  220. color: #4a4a4a;
  221. }
  222. .sidebar-list, .post-content, .sidebar-list-single {
  223. padding-top: 1.4rem;
  224. }
  225. .sidebar-list-nav {
  226. padding-top: 1rem;
  227. }
  228. .sidebar-list-nav .is-tab {
  229. padding-right: 1rem;
  230. }
  231. .sidebar-footer-single {
  232. padding-top: 2rem;
  233. }
  234. .sidebar-footer-single a {
  235. color: #000;
  236. font-weight: 700;
  237. text-transform: uppercase;
  238. font-size: 1.1rem;
  239. border-right: 4px solid #d74436;
  240. padding-right: 1rem;
  241. }
  242. .sidebar-footer-single a:hover {
  243. color: #363636;
  244. }
  245. /* post */
  246. .post-header, .sidebar-header-single {
  247. border-color: #d74436;
  248. padding-left: 1rem;
  249. border-left: 4px solid #d74436;
  250. }
  251. .post-header .title {
  252. font-weight: 700;
  253. font-size: 1.8rem;
  254. color: rgba(0,0,0,.84)!important;
  255. fill: rgba(0,0,0,.84)!important;
  256. }
  257. .post-header .subtitle, .sidebar-header-single .subtitle {
  258. font-size: 1.1rem;
  259. }
  260. .post-content p, .post-single-content p {
  261. margin-bottom: 0.8rem;
  262. }
  263. .post-content, .post-single-content {
  264. font-size: 1.1rem;
  265. font-weight: 300;
  266. }
  267. /* override */
  268. .post-single-content form p:nth-child(even) {
  269. border-right: 0;
  270. }
  271. .post-single-content form label {
  272. text-transform: uppercase;
  273. color: #4a4a4a;
  274. padding-bottom: 0.2rem;
  275. }
  276. .post-single-content form .input[type] {
  277. padding-top: 0.2rem;
  278. }
  279. .post-single-content p:nth-child(even) {
  280. border-right: 4px solid #d74436;
  281. padding-right: 1rem;
  282. }
  283. .post-content a {
  284. color: #d74436;
  285. }
  286. .card-content-form form {
  287. padding-top: 1.5rem;
  288. }
  289. .post-footer {
  290. padding: 1.5rem 0 0 0;
  291. }
  292. /* pagination */
  293. .pagination-content {
  294. border-right: 4px solid #d74436;
  295. padding-right: 1rem;
  296. }
  297. .pagination-link.is-current {
  298. background-color: #d74436;
  299. border-color: #d74436;
  300. }
  301. </style>