1
1
<script setup lang="ts">
2
- import type {GameInstance } from " @/helpers/types" ;
3
- import type ContextMenu from " @/components/ui/ContextMenu.vue" ;
4
- import {DropdownIcon } from " @modrinth/assets" ;
5
- import type {Version } from " @modrinth/utils" ;
6
- import {computed , onMounted , ref } from ' vue' ;
7
- import dayjs from " dayjs" ;
8
- import advancedFormat from ' dayjs/plugin/advancedFormat.js' ;
9
- import type {Screenshot } from " @/helpers/screenshots.ts" ;
10
- import {getAllProfileScreenshots } from " @/helpers/screenshots.ts" ;
11
- import ScreenshotCard from " @/components/ui/ScreenshotCard.vue" ;
2
+ import type {GameInstance } from ' @/helpers/types'
3
+ import type ContextMenu from ' @/components/ui/ContextMenu.vue'
4
+ import {DropdownIcon } from ' @modrinth/assets'
5
+ import type {Version } from ' @modrinth/utils'
6
+ import {computed , onMounted , ref } from ' vue'
7
+ import dayjs from ' dayjs'
8
+ import advancedFormat from ' dayjs/plugin/advancedFormat.js'
9
+ import type {Screenshot } from ' @/helpers/screenshots.ts'
10
+ import {getAllProfileScreenshots } from ' @/helpers/screenshots.ts'
11
+ import ScreenshotCard from ' @/components/ui/ScreenshotCard.vue'
12
12
13
- dayjs .extend (advancedFormat );
13
+ dayjs .extend (advancedFormat )
14
14
15
15
const props = defineProps <{
16
- instance: GameInstance ;
17
- options: InstanceType <typeof ContextMenu > | null ;
18
- offline: boolean ;
19
- playing: boolean ;
20
- versions: Version [];
21
- installed: boolean ;
22
- }>();
16
+ instance: GameInstance
17
+ options: InstanceType <typeof ContextMenu > | null
18
+ offline: boolean
19
+ playing: boolean
20
+ versions: Version []
21
+ installed: boolean
22
+ }>()
23
23
24
- const screenshots = ref <Screenshot []>([]);
24
+ const screenshots = ref <Screenshot []>([])
25
25
26
26
onMounted (async () => {
27
- screenshots .value = (await getAllProfileScreenshots (props .instance .path )) ?? [];
28
- });
27
+ screenshots .value = (await getAllProfileScreenshots (props .instance .path )) ?? []
28
+ })
29
29
30
30
function groupAndSortByDate(items : Screenshot []) {
31
- const today = dayjs ().startOf (' day' );
32
- const yesterday = today .subtract (1 , ' day' );
33
- const map = new Map <string , { labelDate: dayjs .Dayjs ; items: any [] }>();
31
+ const today = dayjs ().startOf (' day' )
32
+ const yesterday = today .subtract (1 , ' day' )
33
+ const map = new Map <string , { labelDate: dayjs .Dayjs ; items: Screenshot [] }>()
34
34
35
35
for (const shot of items ) {
36
- const d = dayjs (shot .creation_date ).startOf (' day' );
37
- let label: string ;
38
- if (d .isSame (today )) label = ' Today' ;
39
- else if (d .isSame (yesterday )) label = ' Yesterday' ;
40
- else label = dayjs (shot .creation_date ).format (" MMMM Do, YYYY" );
36
+ const d = dayjs (shot .creation_date ).startOf (' day' )
37
+ let label: string
38
+ if (d .isSame (today )) label = ' Today'
39
+ else if (d .isSame (yesterday )) label = ' Yesterday'
40
+ else label = dayjs (shot .creation_date ).format (' MMMM Do, YYYY' )
41
41
42
42
if (! map .has (label )) {
43
- map .set (label , {labelDate: d , items: []});
43
+ map .set (label , {labelDate: d , items: []})
44
44
}
45
45
46
- map .get (label )! .items .push (shot );
46
+ map .get (label )! .items .push (shot )
47
47
}
48
48
49
49
return Array .from (map .entries ())
50
50
.sort (([a , aData ], [b , bData ]) => {
51
- if (a === ' Today' ) return - 1 ;
52
- if (b === ' Today' ) return 1 ;
53
- if (a === ' Yesterday' ) return - 1 ;
54
- if (b === ' Yesterday' ) return 1 ;
55
- return bData .labelDate .unix () - aData .labelDate .unix ();
51
+ if (a === ' Today' ) return - 1
52
+ if (b === ' Today' ) return 1
53
+ if (a === ' Yesterday' ) return - 1
54
+ if (b === ' Yesterday' ) return 1
55
+ return bData .labelDate .unix () - aData .labelDate .unix ()
56
56
})
57
- .map (([label , {items }]) => [label , items ] as const );
57
+ .map (([label , {items }]) => [label , items ] as const )
58
58
}
59
59
60
- const screenshotsByDate = computed (() => groupAndSortByDate (screenshots .value ));
61
- const hasToday = computed (() => screenshotsByDate .value .some (([label ]) => label === ' Today' ));
60
+ const screenshotsByDate = computed (() => groupAndSortByDate (screenshots .value ))
61
+ const hasToday = computed (() => screenshotsByDate .value .some (([label ]) => label === ' Today' ))
62
62
</script >
63
63
64
64
<template >
65
65
<div class =" w-full p-5" >
66
- <div v-if =" !screenshots.length" class =" flex flex-col items-center justify-center py-12 text-center" >
66
+ <div
67
+ v-if =" !screenshots.length"
68
+ class =" flex flex-col items-center justify-center py-12 text-center"
69
+ >
67
70
<div class =" text-lg font-medium mb-2" >No screenshots yet</div >
68
71
<div class =" text-sm text-gray-500 dark:text-gray-400" >
69
72
Screenshots taken in-game will appear here
@@ -74,30 +77,36 @@ const hasToday = computed(() => screenshotsByDate.value.some(([label]) => label
74
77
<template v-if =" ! hasToday " >
75
78
<details class =" group space-y-2" open >
76
79
<summary class =" cursor-pointer flex items-center justify-between" >
77
- <h2 class =" text-xxl font-bold underline decoration-4 decoration-brand-green underline-offset-8" >Today</h2 >
78
- <DropdownIcon class =" w-5 h-5 transform transition-transform duration-200 group-open:rotate-180" />
80
+ <h2
81
+ class =" text-xxl font-bold underline decoration-4 decoration-brand-green underline-offset-8"
82
+ >
83
+ Today
84
+ </h2 >
85
+ <DropdownIcon
86
+ class =" w-5 h-5 transform transition-transform duration-200 group-open:rotate-180"
87
+ />
79
88
</summary >
80
89
<p class =" text-lg font-medium mb-2" >You haven't taken any screenshots today.</p >
81
90
</details >
82
91
</template >
83
92
84
- <template v-for =" ( [date , shots ]) in screenshotsByDate " :key =" date " >
93
+ <template v-for =" [date , shots ] in screenshotsByDate " :key =" date " >
85
94
<details class =" group space-y-2" open >
86
95
<summary class =" cursor-pointer flex items-center justify-between" >
87
- <h2 class =" text-xxl font-bold underline decoration-4 decoration-brand-green underline-offset-8" >{{
88
- date
89
- }}</h2 >
90
- <DropdownIcon class =" w-5 h-5 transform transition-transform duration-200 group-open:rotate-180" />
96
+ <h2
97
+ class =" text-xxl font-bold underline decoration-4 decoration-brand-green underline-offset-8"
98
+ >
99
+ {{ date }}
100
+ </h2 >
101
+ <DropdownIcon
102
+ class =" w-5 h-5 transform transition-transform duration-200 group-open:rotate-180"
103
+ />
91
104
</summary >
92
105
<div class =" grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 pt-2" >
93
- <ScreenshotCard
94
- v-for =" s in shots"
95
- :key =" s.path"
96
- :screenshot =" s"
97
- />
106
+ <ScreenshotCard v-for =" s in shots" :key =" s.path" :screenshot =" s" />
98
107
</div >
99
108
</details >
100
109
</template >
101
110
</div >
102
111
</div >
103
- </template >
112
+ </template >
0 commit comments