index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. // TODO: Maybe getters ?
  96. filter.pageNum = store.state.blog.pagination.pageNum
  97. filter.pageSize = store.state.blog.pagination.pageSize
  98. }
  99. await store.dispatch('blog/fetchBlogs', filter)
  100. await store.dispatch('blog/fetchFeaturedBlogs', {'filter[featured]': true})
  101. },
  102. methods: {
  103. setQueryPaginationParams() {
  104. const { pageSize, pageNum } = this.pagination
  105. this.$router.push({query: {pageNum, pageSize}})
  106. },
  107. async fetchBlogs() {
  108. const filter = {}
  109. filter.pageSize = this.pagination.pageSize
  110. filter.pageNum = this.pagination.pageNum
  111. // Here store the query params!
  112. const result = await this.$store.dispatch('blog/fetchBlogs', filter)
  113. if(result.isAxiosError !== true){
  114. this.setQueryPaginationParams()
  115. }
  116. },
  117. }
  118. }
  119. </script>
  120. <style scoped>
  121. .post-content {
  122. font-style: italic;
  123. }
  124. .pagination-content {
  125. display: flex;
  126. justify-content: flex-end;
  127. }
  128. .clickable {
  129. cursor: pointer;
  130. }
  131. #root {
  132. flex: 1 0 auto;
  133. }
  134. *:focus {
  135. outline: none;
  136. }
  137. a {
  138. transition: all .35s;
  139. color: #000;
  140. }
  141. .button:focus {
  142. border-color: #d74436;
  143. box-shadow: 0 0 0 0;
  144. }
  145. .input, .textarea, .input[type] {
  146. font-size: 1.1rem;
  147. }
  148. .input:focus, .textarea:focus, .input[type]:focus {
  149. border: 2px solid #d74436;
  150. }
  151. /* this is used when inline-styled content
  152. overlaps text backgrounds in a really ugly way */
  153. .buffer {
  154. padding-bottom: 1.1rem;
  155. }
  156. /* navigation */
  157. .nav {
  158. background-color: #0d0c0d;
  159. }
  160. .nav-left {
  161. padding-left: 2rem;
  162. }
  163. .nav-right, .nav-center {
  164. padding-right: 2rem;
  165. }
  166. a.nav-item.is-tab {
  167. font-weight: 700;
  168. font-size: 13px;
  169. text-transform: uppercase;
  170. color: #fff;
  171. padding: 0.4rem;
  172. }
  173. a.nav-item:hover {
  174. color: #d74436;
  175. }
  176. a.nav-item.is-tab:hover {
  177. border-bottom: 4px solid #d74436;
  178. }
  179. /* main content */
  180. .main-content {
  181. padding: 4rem 0 2rem 0;
  182. min-height: 800px
  183. }
  184. .main-content .container {
  185. padding: 0 2rem 2rem 2rem;
  186. }
  187. /* section */
  188. .section {
  189. padding: 0 0 2rem 0;
  190. }
  191. .section-header {
  192. padding-bottom: 3rem;
  193. }
  194. .section-header .title {
  195. text-transform: uppercase;
  196. color: #4a4a4a;
  197. font-size: 1.3rem;
  198. }
  199. .section-header a {
  200. color: #d74436;
  201. font-weight: 700;
  202. }
  203. .section-header a:hover {
  204. color: #e50076;
  205. }
  206. /* sidebar */
  207. .sidebar-header {
  208. border-color: #d74436;
  209. padding-bottom: 1rem;
  210. border-bottom: 4px solid #d74436;
  211. }
  212. .sidebar-header .title, .sidebar-header-single .title {
  213. font-weight: 700;
  214. text-transform: uppercase;
  215. font-size: 1.3rem;
  216. }
  217. .sidebar-list p, .sidebar-list-single p {
  218. font-size: 1.1rem;
  219. font-weight: 300;
  220. padding-bottom: 0.8rem;
  221. }
  222. .sidebar-list a {
  223. color: #4a4a4a;
  224. }
  225. .sidebar-list, .post-content, .sidebar-list-single {
  226. padding-top: 1.4rem;
  227. }
  228. .sidebar-list-nav {
  229. padding-top: 1rem;
  230. }
  231. .sidebar-list-nav .is-tab {
  232. padding-right: 1rem;
  233. }
  234. .sidebar-footer-single {
  235. padding-top: 2rem;
  236. }
  237. .sidebar-footer-single a {
  238. color: #000;
  239. font-weight: 700;
  240. text-transform: uppercase;
  241. font-size: 1.1rem;
  242. border-right: 4px solid #d74436;
  243. padding-right: 1rem;
  244. }
  245. .sidebar-footer-single a:hover {
  246. color: #363636;
  247. }
  248. /* post */
  249. .post-header, .sidebar-header-single {
  250. border-color: #d74436;
  251. padding-left: 1rem;
  252. border-left: 4px solid #d74436;
  253. }
  254. .post-header .title {
  255. font-weight: 700;
  256. font-size: 1.8rem;
  257. color: rgba(0,0,0,.84)!important;
  258. fill: rgba(0,0,0,.84)!important;
  259. }
  260. .post-header .subtitle, .sidebar-header-single .subtitle {
  261. font-size: 1.1rem;
  262. }
  263. .post-content p, .post-single-content p {
  264. margin-bottom: 0.8rem;
  265. }
  266. .post-content, .post-single-content {
  267. font-size: 1.1rem;
  268. font-weight: 300;
  269. }
  270. /* override */
  271. .post-single-content form p:nth-child(even) {
  272. border-right: 0;
  273. }
  274. .post-single-content form label {
  275. text-transform: uppercase;
  276. color: #4a4a4a;
  277. padding-bottom: 0.2rem;
  278. }
  279. .post-single-content form .input[type] {
  280. padding-top: 0.2rem;
  281. }
  282. .post-single-content p:nth-child(even) {
  283. border-right: 4px solid #d74436;
  284. padding-right: 1rem;
  285. }
  286. .post-content a {
  287. color: #d74436;
  288. }
  289. .card-content-form form {
  290. padding-top: 1.5rem;
  291. }
  292. .post-footer {
  293. padding: 1.5rem 0 0 0;
  294. }
  295. /* pagination */
  296. .pagination-content {
  297. border-right: 4px solid #d74436;
  298. padding-right: 1rem;
  299. }
  300. .pagination-link.is-current {
  301. background-color: #d74436;
  302. border-color: #d74436;
  303. }
  304. </style>