Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<script setup lang="ts">
import { computed, onMounted, reactive } from "vue";
import { useResourceStore } from "@/stores/resources";
import ResourceCard from "@/components/resources/ResourceCard.vue";
import CardTransitionGroup from "@/components/transitions/CardTransitionGroup.vue";
import { useAuthStore } from "@/stores/users";
import FontAwesomeIcon from "@/components/FontAwesomeIcon.vue";
import type { ResourceOut } from "@/client/resource";
const resourceRepository = useResourceStore();
const userRepository = useAuthStore();
const resourceState = reactive<{
loading: boolean;
filterString: string;
sortDesc: boolean;
}>({
loading: true,
filterString: "",
sortDesc: true,
});
const sortedResourcesByName = computed<ResourceOut[]>(() => {
return [...resourceRepository.resources].sort((a, b) =>
a.name < b.name ? 1 : -1,
);
});
const sortedResources = computed<ResourceOut[]>(() => {
if (resourceState.sortDesc) {
return [...sortedResourcesByName.value].reverse();
}
return sortedResourcesByName.value;
});
const filteredSortedResources = computed<ResourceOut[]>(() => {
return sortedResources.value.filter((resource) => {
return resourceState.filterString.length > 0
? resource.name.includes(resourceState.filterString)
: true;
});
});
onMounted(() => {
resourceRepository
.fetchPublicResources(() => {
resourceState.loading = false;
})
.then((resources) => {
userRepository.fetchUsernames(resources.map((r) => r.maintainer_id));
});
});
</script>
<template>
<div class="row border-bottom mb-4">
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<h2 class="mb-2">Available Resources</h2>
</div>
<div class="d-flex m-2 mb-3 align-items-center justify-content-start">
<div class="col-5">
<div class="input-group rounded shadow-sm">
<span class="input-group-text" id="resources-search-wrapping"
><font-awesome-icon icon="fa-solid fa-magnifying-glass"
/></span>
<input
type="text"
id="filterResourcesInput"
class="form-control"
placeholder="Filter Resources"
aria-label="Filter Resources"
aria-describedby="resources-search-wrapping"
:disabled="resourceState.loading"
v-model.trim="resourceState.filterString"
maxlength="20"
/>
</div>
</div>
<font-awesome-icon
:icon="
resourceState.sortDesc
? 'fa-solid fa-arrow-down-wide-short'
: 'fa-solid fa-arrow-up-wide-short'
"
@click="resourceState.sortDesc = !resourceState.sortDesc"
class="fs-5 ms-3 cursor-pointer"
/>
</div>
<div v-if="!resourceState.loading">
<div
v-if="resourceRepository.resources.length === 0"
class="text-center fs-2 mt-5"
>
<font-awesome-icon
icon="fa-solid fa-x"
class="my-5 fs-0"
style="color: var(--bs-secondary)"
/>
<p>There are no resources in the system. Please come again later.</p>
</div>
<div
v-else-if="filteredSortedResources.length === 0"
class="text-center fs-2 mt-5"
>
<font-awesome-icon
icon="fa-solid fa-magnifying-glass"
class="my-5 fs-0"
style="color: var(--bs-secondary)"
/>
<p>
Could not find any Resources containing<br />'{{
resourceState.filterString
}}'
</p>
</div>
<CardTransitionGroup
v-else
class="d-flex flex-wrap align-items-center justify-content-between"
>
<resource-card
v-for="resource in filteredSortedResources"
:key="resource.resource_id"
:resource="resource"
:loading="false"
style="min-width: 47%; max-width: 48%"
/>
</CardTransitionGroup>
</div>
<div
v-else
class="d-flex flex-wrap align-items-center justify-content-between"
>
<resource-card
v-for="resource in 4"
:key="resource"
:resource="{
name: '',
description: '',
source: '',
resource_id: '',
versions: [],
maintainer_id: '',
}"
style="min-width: 48%"
loading
/>
</div>
</template>
<style scoped></style>