Skip to content

Commit

Permalink
date formatting and some fixes for filters
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmegatelo committed Jan 18, 2025
1 parent f79e06a commit 549f2f8
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 14 deletions.
6 changes: 4 additions & 2 deletions frontend/src/components/FeedItem.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<script setup lang="ts">
import { useFeedStore } from '@/stores/feed.ts'
import { computed, onMounted, useTemplateRef } from 'vue'
import { computed, inject, onMounted, useTemplateRef } from 'vue'
import { useSubscriptionsStore } from '@/stores/subscriptions.ts'
import { useRoute } from 'vue-router'
import IconPaid from '@/components/icons/IconPaid.vue'
import { Injection } from '@/utils/constants.ts'
const emit = defineEmits(['appear'])
const intlService = inject(Injection.Intl)
const route = useRoute()
const { id } = defineProps({ id: Number })
Expand Down Expand Up @@ -89,7 +91,7 @@ function stripTags(htmlString: string) {
<small>{{ feed.title }}</small>
</RouterLink>
<small class="paragraph">
{{ feedItem.pub_date }}
{{ intlService.formatDate(new Date(feedItem.pub_date)) }}
</small>
</div>
<RouterLink :to="getDetailLinkParams()" class="feed-links-list-item-link">
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'
import { DialogsService } from '@/services/dialogs.ts'
import { IntlService } from '@/services/intl'

const app = createApp(App)

app.use(createPinia())
app.use(DialogsService.initPlugin())
app.use(IntlService.initPlugin())
app.use(router)

app.mount('#app')
25 changes: 25 additions & 0 deletions frontend/src/services/intl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { App as AppType, Plugin } from 'vue'
import { Injection } from '@/utils/constants.ts'

export class IntlService {
private readonly _datetime: Intl.DateTimeFormat
constructor() {
this._datetime = new Intl.DateTimeFormat(['en-GB'], {
month: 'short',
year: 'numeric',
day: 'numeric',
})
}

formatDate(date: Date): string {
return this._datetime.format(date)
}

static initPlugin(): Plugin {
return {
install: (app: AppType) => {
app.provide(Injection.Intl, new IntlService())
}
}
}
}
5 changes: 4 additions & 1 deletion frontend/src/stores/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ export const useFeedStore = defineStore('feed', {
this.items = items
},
setFilters(category: string, filters: Record<string, Filter>) {
this.filters[category] = filters
this.filters[category] = {
...this.filters[category],
...filters,
}
},
updateItem(id: number, update: Partial<FeedItem>) {
this.items = this.items.map((item: FeedItem) => {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { InjectionKey } from 'vue'
import type { DialogsService } from '@/services/dialogs.ts'
import type { IntlService } from '@/services/intl.ts'

export const Injection = {
DialogController: Symbol("dialogs-controller") as InjectionKey<DialogsService>,
Intl: Symbol("intl") as InjectionKey<IntlService>,
}
22 changes: 11 additions & 11 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 549f2f8

Please sign in to comment.