diff --git a/stockingly-frontend/src/components/CompanyCard.vue b/stockingly-frontend/src/components/CompanyCard.vue
index 96d0694..691e442 100644
--- a/stockingly-frontend/src/components/CompanyCard.vue
+++ b/stockingly-frontend/src/components/CompanyCard.vue
@@ -24,12 +24,12 @@
-
+
{{ company.ticker }}
-
+
{{ formatCurrency(company['market cap']) }}
diff --git a/stockingly-frontend/src/views/Home.vue b/stockingly-frontend/src/views/Home.vue
index e477e2a..965882b 100644
--- a/stockingly-frontend/src/views/Home.vue
+++ b/stockingly-frontend/src/views/Home.vue
@@ -3,12 +3,22 @@
Stockingly
-
mdi-backspace-outline
+
+
+
+
+
+
+ {{ item.title }}
+
+
+
@@ -65,6 +75,45 @@ import CompanyCard from '@/components/CompanyCard.vue';
const MAX_SELECT = 3;
+interface Sorter {
+ title: string,
+ sortBy?: keyof Company
+}
+
+const sortItems: Sorter[] = [
+ {
+ title: 'Best Valuation',
+ sortBy: 'Valuation',
+ },
+ {
+ title: 'Best Financial Health',
+ sortBy: 'Financial Health',
+ },
+ {
+ title: 'Best Estimated Growth',
+ sortBy: 'Estimated Growth',
+ },
+ {
+ title: 'Best Past Performance',
+ sortBy: 'Past Performance',
+ },
+ {
+ title: 'Biggest Market Cap',
+ sortBy: 'market cap'
+ },
+ {
+ title: 'Relevance'
+ }
+];
+
+const naturalOrder = (getKey: (t: T) => Key) => (a: T, b: T) => {
+ const aKey = getKey(a), bKey = getKey(b);
+ // return reverse order since we sort in descending order
+ return aKey > bKey ? -1 : aKey < bKey ? 1 : 0;
+}
+
+const sortSelected = ref(sortItems.length - 1);
+
const loading = ref(true);
const companies = ref([]);
const filteredCompanies = ref<(Company & { score?: number })[]>([]);
@@ -73,14 +122,26 @@ const searchText = ref("");
const router = useRouter();
let fuse: Fuse | undefined = undefined;
+const sortCompanies = () => {
+ const sorter = sortItems[sortSelected.value]!;
+ if (sorter.sortBy !== undefined) {
+ const key: keyof Company = sorter.sortBy;
+ filteredCompanies.value = filteredCompanies.value.sort(naturalOrder(c => c[key]))
+ }
+}
+
const search = debounce(() => setTimeout(() => {
filteredCompanies.value = fuse!.search(searchText.value).map(e => ({ ...e.item, score: e.score }))
-}, 800));
+ sortCompanies();
+}, 0), 1000);
+
+watch(sortSelected, () => sortCompanies());
watch(searchText, () => {
if (!fuse) return;
if (searchText.value === '') {
filteredCompanies.value = companies.value;
+ sortCompanies();
loading.value = false;
return;
}