-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement search based on @hankolsen previous PR
- Loading branch information
Showing
8 changed files
with
122 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<script lang="ts" setup> | ||
import { NInput } from 'naive-ui'; | ||
import useSocksProxies from '@/composables/useSocksProxies/useSocksProxies'; | ||
const { query } = useSocksProxies(); | ||
</script> | ||
|
||
<template> | ||
<NInput v-model:value="query" placeholder="Search" clearable class="mb-3" /> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,43 @@ | ||
import { computed, ref } from 'vue'; | ||
|
||
import { addCountryCode } from '@/composables/useSocksProxies/addCountryCode'; | ||
import { groupByCountryAndCity } from '@/composables/useSocksProxies/groupByCountryAndCity'; | ||
import { SocksProxy } from '@/composables/useSocksProxies/socksProxies.types'; | ||
import { sortProxiesByCountryAndCity } from '@/composables/useSocksProxies/sortProxiesByCountryAndCity'; | ||
|
||
import { SocksProxy } from '@/composables/useSocksProxies/socksProxies.types'; | ||
import useStore from '@/composables/useStore'; | ||
|
||
const { proxiesList } = useStore(); | ||
const { flatProxiesList } = useStore(); | ||
|
||
const query = ref(''); | ||
|
||
const clearFilter = () => { | ||
query.value = ''; | ||
}; | ||
|
||
const useSocksProxies = () => { | ||
const getSocksProxies = async () => { | ||
const response = await fetch('https://api.mullvad.net/network/v1-beta1/socks-proxies'); | ||
const data: SocksProxy[] = await response.json(); | ||
|
||
const onlineProxies = data.filter((proxy: SocksProxy) => proxy.online); | ||
const proxiesWithCountryCode = addCountryCode(onlineProxies); | ||
const groupedProxies = groupByCountryAndCity(proxiesWithCountryCode); | ||
proxiesList.value = sortProxiesByCountryAndCity(groupedProxies); | ||
flatProxiesList.value = data.filter((proxy: SocksProxy) => proxy.online); | ||
}; | ||
|
||
return { getSocksProxies, proxiesList }; | ||
const filteredData = computed(() => | ||
flatProxiesList.value.filter( | ||
(socksProxy) => | ||
!query.value || | ||
socksProxy.location.country.toLowerCase().includes(query.value.toLowerCase()) || | ||
socksProxy.location.city.toLowerCase().includes(query.value.toLowerCase()) || | ||
socksProxy.hostname.toLowerCase().includes(query.value.toLowerCase()), | ||
), | ||
); | ||
|
||
const filteredProxies = computed(() => | ||
sortProxiesByCountryAndCity(groupByCountryAndCity(addCountryCode(filteredData.value))), | ||
); | ||
|
||
return { clearFilter, filteredProxies, getSocksProxies, query }; | ||
}; | ||
|
||
export default useSocksProxies; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters