Skip to content

Commit

Permalink
Merge pull request codeforsapporo#178 from yamanoku/news-page
Browse files Browse the repository at this point in the history
Add News page
  • Loading branch information
MiyukiShirasawa authored Apr 2, 2020
2 parents a59f485 + 10a71f6 commit 2baa7ae
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 30 deletions.
2 changes: 1 addition & 1 deletion components/DataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
border-bottom: 1px solid $gray-4;
white-space: nowrap;
color: $gray-2;
font-size: 12px;
font-size: 14px;
}
tbody {
tr {
Expand Down
6 changes: 6 additions & 0 deletions components/SideNavigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
"Chiba Prefecture": "千葉県",
"Chiba City": "千葉市",
"The latest updates": "県内の最新感染動向",
"Information": "お知らせ一覧",
"for Families with children": "お子様をお持ちの皆様へ",
"for Citizens": "県民の皆様へ",
"for Enterprises and Employees": "企業の皆様・はたらく皆様へ",
Expand Down Expand Up @@ -180,6 +181,11 @@ export default {
// 'https://www.pref.chiba.lg.jp/shippei/kansenshou/2019-ncov.html',
// divider: true
// },
{
icon: 'mdi-information',
title: this.$t('Information'),
link: '/news'
},
{
icon: 'parent',
title: this.$t('for Families with children'),
Expand Down
40 changes: 12 additions & 28 deletions components/WhatsNew.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@
</a>
</li>
</ul>
</div>
<div class="WhatsNew-expander" alt="すべて見る" @click="onExpand">
<v-icon size="24">
mdi-chevron-down
</v-icon>
<nuxt-link class="WhatsNew-archive" :to="localePath('/news')">
{{ $t('過去のお知らせを見る') }}
</nuxt-link>
</div>
</div>
</template>
Expand All @@ -62,9 +60,6 @@ export default Vue.extend({
methods: {
isInternalLink(path: string) {
return !/^https?:\/\//.test(path)
},
onExpand() {
this.expanded = !this.expanded
}
}
})
Expand All @@ -74,16 +69,11 @@ export default Vue.extend({
.WhatsNew {
@include card-container();
margin-bottom: 20px;
position: relative;
max-height: 225px;
overflow: hidden;
&-wrapper {
padding: 10px 10px 40px 10px;
padding: 10px;
position: relative;
}
}
.WhatsNew.expanded {
max-height: unset;
}
.WhatsNew-heading {
display: flex;
Expand Down Expand Up @@ -137,19 +127,13 @@ export default Vue.extend({
}
}
.WhatsNew-expander {
height: 30px;
width: 100%;
background-color: #ffffff;
.v-application .WhatsNew-archive {
@include button-text('md');
padding: 3px 12px;
color: $green-1;
text-decoration: none;
position: absolute;
bottom: 0;
border-top: 0.5px solid #d9d9d9 !important;
cursor: pointer;
display: flex;
justify-content: center;
}
.WhatsNew.expanded .WhatsNew-expander i {
transform: rotateX(180deg);
top: 10px;
right: 10px;
}
</style>
2 changes: 1 addition & 1 deletion pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export default {
title: '県内の最新感染動向',
date: Data.lastUpdate
},
newsItems: News.newsItems,
newsItems: News.newsItems.slice(0, 5),
metroGraphOption: {
responsive: true,
legend: {
Expand Down
99 changes: 99 additions & 0 deletions pages/news.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<template>
<div class="Parent">
<h2>
<v-icon size="24" class="WhatsNew-heading-icon">
mdi-information
</v-icon>
お知らせ一覧
</h2>
<v-card>
<v-data-table
:headers="headers"
:items="newsItems"
:hide-default-footer="true"
:fixed-header="true"
:items-per-page="itemsPerPage"
:page.sync="page"
class="cardTable"
@page-count="pageCount = $event"
>
<template v-slot:item.title="{ item }">
<a v-if="item.link" :href="item.link" target="_blank" rel="noopener">
{{ item.title }}
<v-icon size="12">mdi-open-in-new</v-icon>
</a>
<span v-else>{{ item.title }}</span>
</template>
<template v-slot:item.date="{ item }">
{{ formatDate(item.date) }}
</template>
</v-data-table>
<v-container class="py-4">
<v-pagination v-model="page" :length="pageCount" class="pagination" />
</v-container>
</v-card>
</div>
</template>

<script lang="ts">
import Vue from 'vue'
import News from '@/data/news.json'
import { convertDateToISO8601Format } from '@/utils/formatDate'
import * as NewsUtils from '@/utils/newsUtils'
export default Vue.extend({
components: {},
data() {
return {
page: 1,
pageCount: 0,
itemsPerPage: 10,
headers: [
{
text: '日付',
value: 'date',
sortable: false,
sort(as: string, bs: string): number {
const a = new Date(convertDateToISO8601Format(as))
const b = new Date(convertDateToISO8601Format(bs))
return a > b ? 1 : a < b ? -1 : 0
}
},
{
text: 'タイトル',
value: 'title',
sortable: false
}
],
newsItems: News.newsItems
}
},
methods: {
formatDate(datestr: string): string {
return NewsUtils.formatDate(datestr, this.$i18n.locale)
}
}
})
</script>

<style lang="scss" scoped>
h2 {
margin-bottom: 1em;
}
a {
color: $link !important;
text-decoration: none;
&:hover {
text-decoration: underline;
}
}
</style>

<style lang="scss">
.v-data-table-header-mobile {
display: none;
}
.v-application .pagination .primary {
background-color: $green-1 !important;
border-color: $green-1 !important;
}
</style>
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"dom"
],
"esModuleInterop": true,
"resolveJsonModule": true,
"allowJs": true,
"sourceMap": true,
"strict": true,
Expand Down
12 changes: 12 additions & 0 deletions types/news/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
interface newsItem {
title?: string | { [key: string]: string }
link?: string | URL | { [key: string]: string | URL }
primaryLang?: string
}
declare module '*/data/news.json' {
interface news {
newsItems: Array<newsItem>
}
const value: news
export = value
}
8 changes: 8 additions & 0 deletions utils/newsUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { convertDateToISO8601Format } from '@/utils/formatDate'

export function formatDate(datestr: string, locale: string): string {
const ld = new Date(convertDateToISO8601Format(datestr)).toLocaleDateString(
locale
)
return ld
}

0 comments on commit 2baa7ae

Please sign in to comment.