Skip to content

Commit 271df14

Browse files
authored
Merge pull request #52290 from nextcloud/fix/show-better-mtime
refactor(files): share `mtime` for file entry components
2 parents 9bfa1e7 + 9794f90 commit 271df14

File tree

5 files changed

+35
-34
lines changed

5 files changed

+35
-34
lines changed

apps/files/src/components/FileEntry.vue

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@
6464
class="files-list__row-mtime"
6565
data-cy-files-list-row-mtime
6666
@click="openDetailsIfAvailable">
67-
<NcDateTime v-if="mtime" :timestamp="mtime" :ignore-seconds="true" />
67+
<NcDateTime v-if="mtime"
68+
ignore-seconds
69+
:timestamp="mtime" />
6870
<span v-else>{{ t('files', 'Unknown date') }}</span>
6971
</td>
7072

@@ -86,7 +88,6 @@
8688
import { formatFileSize } from '@nextcloud/files'
8789
import { useHotKey } from '@nextcloud/vue/composables/useHotKey'
8890
import { defineComponent } from 'vue'
89-
import moment from '@nextcloud/moment'
9091
import NcDateTime from '@nextcloud/vue/components/NcDateTime'
9192
9293
import { useNavigation } from '../composables/useNavigation.ts'
@@ -206,26 +207,6 @@ export default defineComponent({
206207
color: `color-mix(in srgb, var(--color-main-text) ${ratio}%, var(--color-text-maxcontrast))`,
207208
}
208209
},
209-
210-
mtime() {
211-
// If the mtime is not a valid date, return it as is
212-
if (this.source.mtime && !isNaN(this.source.mtime.getDate())) {
213-
return this.source.mtime
214-
}
215-
216-
if (this.source.crtime && !isNaN(this.source.crtime.getDate())) {
217-
return this.source.crtime
218-
}
219-
220-
return null
221-
},
222-
223-
mtimeTitle() {
224-
if (this.source.mtime) {
225-
return moment(this.source.mtime).format('LLL')
226-
}
227-
return ''
228-
},
229210
},
230211
231212
created() {

apps/files/src/components/FileEntryGrid.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@
5151
class="files-list__row-mtime"
5252
data-cy-files-list-row-mtime
5353
@click="openDetailsIfAvailable">
54-
<NcDateTime v-if="source.mtime" :timestamp="source.mtime" :ignore-seconds="true" />
54+
<NcDateTime v-if="mtime"
55+
ignore-seconds
56+
:timestamp="mtime" />
5557
</td>
5658

5759
<!-- Actions -->

apps/files/src/components/FileEntryMixin.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,21 +191,39 @@ export default defineComponent({
191191
},
192192
},
193193

194-
mtimeOpacity() {
195-
const maxOpacityTime = 31 * 24 * 60 * 60 * 1000 // 31 days
194+
mtime() {
195+
// If the mtime is not a valid date, return it as is
196+
if (this.source.mtime && !isNaN(this.source.mtime.getDate())) {
197+
return this.source.mtime
198+
}
199+
200+
if (this.source.crtime && !isNaN(this.source.crtime.getDate())) {
201+
return this.source.crtime
202+
}
196203

197-
const mtime = this.source.mtime?.getTime?.()
198-
if (!mtime) {
204+
return null
205+
},
206+
207+
mtimeOpacity() {
208+
if (!this.mtime) {
199209
return {}
200210
}
201211

202-
// 1 = today, 0 = 31 days ago
203-
const ratio = Math.round(Math.min(100, 100 * (maxOpacityTime - (Date.now() - mtime)) / maxOpacityTime))
204-
if (ratio < 0) {
212+
// The time when we start reducing the opacity
213+
const maxOpacityTime = 31 * 24 * 60 * 60 * 1000 // 31 days
214+
// everything older than the maxOpacityTime will have the same value
215+
const timeDiff = Date.now() - this.mtime.getTime()
216+
if (timeDiff < 0) {
217+
// this means we have an invalid mtime which is in the future!
205218
return {}
206219
}
220+
221+
// inversed time difference from 0 to maxOpacityTime (which would mean today)
222+
const opacityTime = Math.max(0, maxOpacityTime - timeDiff)
223+
// 100 = today, 0 = 31 days ago or older
224+
const percentage = Math.round(opacityTime * 100 / maxOpacityTime)
207225
return {
208-
color: `color-mix(in srgb, var(--color-main-text) ${ratio}%, var(--color-text-maxcontrast))`,
226+
color: `color-mix(in srgb, var(--color-main-text) ${percentage}%, var(--color-text-maxcontrast))`,
209227
}
210228
},
211229

dist/files-main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)