2
2
import type { PropType } from ' vue'
3
3
import { computed } from ' vue'
4
4
import { useI18n } from ' vue-i18n'
5
- import { useUrlSearchParams } from ' @vueuse/core'
6
5
import type { Project } from ' ../../core/types'
7
6
import ProjectList from ' ../components/ProjectList.vue'
8
7
import { useSlug , useSlugFilter } from ' ../composables'
9
8
10
9
const props = defineProps ({
10
+ projectPage: {
11
+ type: String ,
12
+ required: false ,
13
+ default: ' /projects.html'
14
+ },
11
15
projects: {
12
16
type: Object as PropType <Project []>,
13
17
required: true ,
14
18
default: []
19
+ },
20
+ technology: {
21
+ type: String ,
22
+ required: false
15
23
}
16
24
})
17
25
18
26
const { t } = useI18n ()
19
- const params = useUrlSearchParams (' history' )
20
- const tech = params .tech
27
+ const tech = props .technology
21
28
const hasTechParam = typeof tech === ' string' && tech .length > 0
22
- const byTech: (project : Project ) => boolean = project => ! hasTechParam || project .techs .some (useSlugFilter (tech ))
29
+ const byTech: (project : Project ) => boolean = (project ) =>
30
+ ! hasTechParam || project .techs .some (useSlugFilter (tech ))
23
31
const projectsByTech = computed (() => props .projects .filter (byTech ))
24
32
const technologies = computed (() => {
25
- const uniqueTechnologies = [... new Set (props .projects .flatMap (project => project .techs ))]
26
- return uniqueTechnologies .map (name => ({
27
- name ,
28
- slug: useSlug (name ),
29
- selected: hasTechParam && useSlug (name ) === tech
30
- })).sort ((a , b ) => b .selected === a .selected ? 0 : b .selected ? 1 : - 1 )
33
+ const uniqueTechnologies = [
34
+ ... new Set (props .projects .flatMap ((project ) => project .techs ))
35
+ ]
36
+ return uniqueTechnologies
37
+ .map ((name ) => ({
38
+ name ,
39
+ slug: useSlug (name ),
40
+ selected: hasTechParam && useSlug (name ) === tech
41
+ }))
42
+ .sort ((a , b ) => (b .selected === a .selected ? 0 : b .selected ? 1 : - 1 ))
31
43
})
32
44
</script >
33
45
@@ -36,12 +48,17 @@ const technologies = computed(() => {
36
48
<div >
37
49
<p >
38
50
<span class =" mr-2" >Technologies</span >
39
- <a v-if =" hasTechParam" href =" /projects.html " >Reset</a >
51
+ <a v-if =" hasTechParam" : href =" projectPage " >Reset</a >
40
52
</p >
41
53
<p class =" flex flex-row flex-wrap" >
42
- <a v-for =" technology in technologies"
43
- :class =" ['border rounded-md m-1 p-1', technology.selected ? 'bg-primary text-white! border-primary' : '']"
44
- :href =" `/projects.html?tech=${technology.slug}`" >
54
+ <a
55
+ v-for =" technology in technologies"
56
+ :class =" [
57
+ 'border rounded-md m-1 p-1',
58
+ technology.selected ? 'bg-primary text-white! border-primary' : ''
59
+ ]"
60
+ :href =" `/projects-by-tech/${technology.slug}`"
61
+ >
45
62
{{ technology.name }}
46
63
</a >
47
64
</p >
0 commit comments