@kompasid/lit-web-components 0.8.6 → 0.8.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. package/demo/index.html +13 -14
  2. package/dist/src/components/kompasid-grace-period/KompasGracePeriod.d.ts +1 -0
  3. package/dist/src/components/kompasid-grace-period/KompasGracePeriod.js +20 -6
  4. package/dist/src/components/kompasid-grace-period/KompasGracePeriod.js.map +1 -1
  5. package/dist/src/components/kompasid-paywall-body/KompasPaywallBody.js +2 -1
  6. package/dist/src/components/kompasid-paywall-body/KompasPaywallBody.js.map +1 -1
  7. package/dist/src/components/kompasid-widget-recirculations-default/KompasWidgetRecirculationsDefault.d.ts +0 -4
  8. package/dist/src/components/kompasid-widget-recirculations-default/KompasWidgetRecirculationsDefault.js +13 -12
  9. package/dist/src/components/kompasid-widget-recirculations-default/KompasWidgetRecirculationsDefault.js.map +1 -1
  10. package/dist/src/components/kompasid-widget-recirculations-list/KompasWidgetRecirculationsList.d.ts +1 -1
  11. package/dist/src/components/kompasid-widget-recirculations-list/KompasWidgetRecirculationsList.js +15 -10
  12. package/dist/src/components/kompasid-widget-recirculations-list/KompasWidgetRecirculationsList.js.map +1 -1
  13. package/dist/src/utils/useTimeDIfference.d.ts +1 -0
  14. package/dist/src/utils/useTimeDIfference.js +27 -0
  15. package/dist/src/utils/useTimeDIfference.js.map +1 -0
  16. package/dist/tsconfig.tsbuildinfo +1 -1
  17. package/package.json +1 -1
  18. package/src/components/kompasid-grace-period/KompasGracePeriod.ts +24 -6
  19. package/src/components/kompasid-paywall-body/KompasPaywallBody.ts +2 -1
  20. package/src/components/kompasid-widget-recirculations-default/KompasWidgetRecirculationsDefault.ts +13 -12
  21. package/src/components/kompasid-widget-recirculations-list/KompasWidgetRecirculationsList.ts +19 -15
  22. package/src/utils/useTimeDIfference.ts +37 -0
@@ -1,8 +1,7 @@
1
1
  import { html, css, LitElement } from 'lit'
2
2
  import { customElement, property } from 'lit/decorators.js'
3
- import { format } from 'date-fns'
4
- import { id } from 'date-fns/locale/id'
5
3
  import { TWStyles } from '../../../tailwind/tailwind.js'
4
+ import { useTimeDifference } from '../../utils/useTimeDIfference.js'
6
5
 
7
6
  interface PostTag {
8
7
  slug: string
@@ -13,6 +12,7 @@ interface ListItem {
13
12
  isAnalisis?: boolean
14
13
  isEksklusif?: boolean
15
14
  isFreemium?: boolean
15
+ isKompasBrief?: boolean
16
16
  permalink: string
17
17
  publishedDate?: string
18
18
  postTag?: PostTag[]
@@ -121,11 +121,15 @@ export class KompasWidgetRecirculationsList extends LitElement {
121
121
  const isEksklusif = postTag.some(
122
122
  (tag: { slug: string }) => tag.slug === 'eksklusif'
123
123
  )
124
+ const isKompasBrief = postTag.some(
125
+ (tag: { slug: string }) => tag.slug === 'kompas-brief'
126
+ )
124
127
 
125
128
  return {
126
129
  isAnalisis,
127
130
  isEksklusif,
128
131
  isFreemium,
132
+ isKompasBrief,
129
133
  title,
130
134
  permalink,
131
135
  publishedDate,
@@ -137,10 +141,6 @@ export class KompasWidgetRecirculationsList extends LitElement {
137
141
  }
138
142
  }
139
143
 
140
- formatDate(date: string) {
141
- return format(new Date(date), "dd MMMM yyyy' · 'HH:mm' WIB", { locale: id })
142
- }
143
-
144
144
  handleFetchError(error: unknown) {
145
145
  const errorMessage =
146
146
  error instanceof Error ? error.message : 'Kesalahan tidak diketahui'
@@ -150,17 +150,15 @@ export class KompasWidgetRecirculationsList extends LitElement {
150
150
  renderChips(item: ListItem) {
151
151
  const chips = []
152
152
 
153
- if (item.isAnalisis) {
153
+ if (item.isKompasBrief) {
154
154
  chips.push(
155
155
  html`
156
156
  <div class="flex">
157
- <div class="chip bg-orange-100 text-orange-500">Analisis</div>
157
+ <div class="chip bg-red-100 text-red-600">Kompas Brief</div>
158
158
  </div>
159
159
  `
160
160
  )
161
- }
162
-
163
- if (item.isEksklusif) {
161
+ } else if (item.isEksklusif) {
164
162
  chips.push(
165
163
  html`
166
164
  <div class="flex">
@@ -175,9 +173,7 @@ export class KompasWidgetRecirculationsList extends LitElement {
175
173
  </div>
176
174
  `
177
175
  )
178
- }
179
-
180
- if (item.isFreemium) {
176
+ } else if (item.isFreemium) {
181
177
  chips.push(
182
178
  html`
183
179
  <div class="flex">
@@ -185,6 +181,14 @@ export class KompasWidgetRecirculationsList extends LitElement {
185
181
  </div>
186
182
  `
187
183
  )
184
+ } else if (item.isAnalisis) {
185
+ chips.push(
186
+ html`
187
+ <div class="flex">
188
+ <div class="chip bg-orange-100 text-orange-500">Analisis</div>
189
+ </div>
190
+ `
191
+ )
188
192
  }
189
193
 
190
194
  return chips
@@ -228,7 +232,7 @@ export class KompasWidgetRecirculationsList extends LitElement {
228
232
  : 'text-grey-500'}"
229
233
  >
230
234
  ${item.publishedDate
231
- ? this.formatDate(item.publishedDate)
235
+ ? useTimeDifference(item.publishedDate, true)
232
236
  : 'Tanggal tidak tersedia'}
233
237
  </div>
234
238
  </div>
@@ -0,0 +1,37 @@
1
+ import { id } from 'date-fns/locale/id'
2
+ import {
3
+ differenceInMinutes,
4
+ differenceInHours,
5
+ format,
6
+ isToday,
7
+ } from 'date-fns'
8
+
9
+ export const useTimeDifference = (dt: string, showTime = false) => {
10
+ const currentDate = new Date()
11
+
12
+ if (isToday(dt)) {
13
+ // If the date is today
14
+ const minutesDifference = differenceInMinutes(currentDate, dt)
15
+
16
+ if (minutesDifference < 60) {
17
+ return `${minutesDifference} menit lalu` // If less than 1 hour
18
+ }
19
+ const hoursDifference = differenceInHours(currentDate, dt)
20
+ return `${hoursDifference} jam lalu` // If more than 1 hour
21
+ }
22
+ const hoursDifference = differenceInHours(currentDate, dt)
23
+
24
+ if (hoursDifference < 24) {
25
+ // If the date is within the last 24 hours
26
+ return `${hoursDifference} jam lalu`
27
+ }
28
+ // If the date is more than 24 hours ago
29
+ const formattedDate = format(dt, 'dd MMMM yyyy', { locale: id })
30
+
31
+ if (showTime) {
32
+ const formattedTime = format(dt, "HH:mm 'WIB'") // Format time to include WIB
33
+ return `${formattedDate} · ${formattedTime}` // Return date and time
34
+ }
35
+
36
+ return formattedDate // Return only the date if showTime is false
37
+ }