Skip to content

Commit

Permalink
feat: add share via WebShare API
Browse files Browse the repository at this point in the history
  • Loading branch information
toniengelhardt committed Feb 14, 2023
1 parent 1e68791 commit 24c6cd2
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 54 deletions.
2 changes: 1 addition & 1 deletion app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default defineAppConfig({
interaction: 'icon-park-solid:click',
encryption: 'carbon:encryption',
vibration: 'ph:vibrate',
share: 'ph-share-network-fill',
share: 'ph:share-network',
fullscreen: 'ph:arrows-out-simple',
eyedropper: 'ph:eyedropper-sample-duotone',
pwa: 'logos:pwa',
Expand Down
2 changes: 1 addition & 1 deletion components/ThemeSelector.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<span
class="flex-center lt-md:(w-8 h-8) footer-link "
class="flex-center lt-md:(w-8 h-8) footer-item "
@click="onClick(); useTrackEvent('click: Theme switcher');"
>
<ClientOnly>
Expand Down
2 changes: 1 addition & 1 deletion components/api/Status.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
defineProps<{
status?: WebAPIStatus
status?: WebAPIStatusInfo
}>()
</script>

Expand Down
4 changes: 2 additions & 2 deletions components/api/grid/Grid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

<script setup lang="ts">
defineProps<{
apis: WebAPI[]
apis: WebApi[]
}>()
const webApiStatuses: Ref<{ [key: keyof typeof webApiData]: boolean }> = useState('webApiStatuses')
const webApiStatuses: Ref<WebApiStatuses> = useState('webApiStatuses')
</script>
2 changes: 1 addition & 1 deletion components/api/grid/GridItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<script setup lang="ts">
const props = defineProps<{
api: WebAPI
api: WebApi
available?: boolean
}>()
Expand Down
4 changes: 2 additions & 2 deletions components/api/list/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

<script setup lang="ts">
defineProps<{
apis: WebAPI[]
apis: WebApi[]
}>()
const webApiStatuses: Ref<{ [key: keyof typeof webApiData]: boolean }> = useState('webApiStatuses')
const webApiStatuses: Ref<WebApiStatuses> = useState('webApiStatuses')
</script>
2 changes: 1 addition & 1 deletion components/api/list/ListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<script setup lang="ts">
const props = defineProps<{
api: WebAPI
api: WebApi
available?: boolean
}>()
Expand Down
2 changes: 1 addition & 1 deletion components/api/property/Indicators.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
defineProps<{
api: WebAPI
api: WebApi
}>()
</script>

Expand Down
2 changes: 1 addition & 1 deletion components/api/source/Source.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ApiSourceChrome from '~/components/api/source/Chrome.vue'
import ApiSourceMDN from '~/components/api/source/MDN.vue'
const props = defineProps<{
api: WebAPI
api: WebApi
}>()
const sourceComponent = computed(() => {
Expand Down
83 changes: 52 additions & 31 deletions components/app/Footer.vue
Original file line number Diff line number Diff line change
@@ -1,36 +1,45 @@
<script setup lang="ts">
const webApiStatuses: Ref<WebApiStatuses> = useState('webApiStatuses')
const shareAvailable = computed(() => !!webApiStatuses.value?.['web-share-api'])
</script>

<template>
<div class="flex justify-between text-sm text-dim px-3 md:px-4 h-12 box-border" border="t-solid t-1 base">
<span class="flex-1 flex items-center">
<ThemeSelector />
<NuxtLink
:to="$config.public.repoUrl"
class="footer-link flex-center lt-md:(w-8 h-8) ml-3 md:ml-4"
title="Contribute on GitHub"
target="_blank"
>
<Icon name="github" size="1.25rem" />
<span class="ml-1.5 lt-md:hidden">Contribute</span>
</NuxtLink>
<NuxtLink
:to="`mailto:${$config.public.feedbackEmail}`"
class="footer-link flex-center lt-md:(w-8 h-8) ml-3 md:ml-4"
title="Send feedback via email"
target="_blank"
>
<Icon name="email" size="1.25rem" />
<span class="ml-1.5 lt-md:hidden">Feedback</span>
</NuxtLink>
<NuxtLink
to="/info"
title="Legend and information about WebAPI check"
class="footer-link flex-center lt-md:(w-8 h-8) ml-3 md:ml-4"
>
<Icon name="info" size="1.25rem" />
<span class="ml-1.5 lt-md:hidden">Info</span>
</NuxtLink>
</span>
<div class="flex justify-between items-center text-sm text-dim px-3 md:px-4 h-12 box-border" border="t-solid t-1 base">
<ThemeSelector />
<NuxtLink
:to="$config.public.repoUrl"
class="footer-item"
title="Contribute on GitHub"
target="_blank"
>
<Icon name="github" />
<span>Contribute</span>
</NuxtLink>
<NuxtLink
:to="`mailto:${$config.public.feedbackEmail}`"
class="footer-item"
title="Send feedback via email"
target="_blank"
>
<Icon name="email" />
<span>Feedback</span>
</NuxtLink>
<div v-if="shareAvailable" class="footer-item">
<Icon name="share" />
<span>Share</span>
</div>
<NuxtLink
to="/info"
title="Legend and information about WebAPI check"
class="footer-item"
>
<Icon name="info" />
<span>Info</span>
</NuxtLink>
<span flex-1 lt-md:hidden />
<span class="flex items-center">
<span>by</span>
<span lt-md:hidden>by</span>
<Icon name="logos:twitter" class="ml-1 mr-1" />
<NuxtLink
:to="$config.public.twitterProfile"
Expand Down Expand Up @@ -82,3 +91,15 @@
</span>
</div>
</template>

<style lang="postcss" scoped>
.footer-item {
@apply flex-center lt-md:(w-8 h-8) md:not-first:ml-8;
.icon {
@apply text-1.25rem;
}
span {
@apply ml-1.5 lt-md:hidden;
}
}
</style>
8 changes: 4 additions & 4 deletions composables/webapis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Note that it has to return a ref, otherwise the ShallowRef components break.
*/
export const useWebApiList = () => {
const list = Object.keys(webApiData).reduce((list: WebAPI[], apiKey: string) => {
const list = Object.keys(webApiData).reduce((list: WebApi[], apiKey: string) => {
list.push({
id: apiKey,
...webApiData[apiKey],
Expand All @@ -17,7 +17,7 @@ export const useWebApiList = () => {
/**
* Note: this probably needs some refactoring.
*/
export const useWebApiStatus = (api: WebAPI, available?: boolean) => {
export const useWebApiStatus = (api: WebApi, available?: boolean) => {
return computed(() => {
if (available) {
if (api.experimental) {
Expand Down Expand Up @@ -50,9 +50,9 @@ export const useWebApiStatus = (api: WebAPI, available?: boolean) => {
* @param webApis: list of WebAPIs to test, defaults to all.
* @param force: by default WebAPIs that have been checked already are skipped, unless this flag is set to true.
*/
export const useTestWebApis = (webApis?: WebAPI[], force = false) => {
export const useTestWebApis = (webApis?: WebApi[], force = false) => {
if (navigator) {
const webApiStatuses: Ref<{ [key: keyof typeof webApiData]: boolean }> = useState('webApiStatuses', () => ({}))
const webApiStatuses: Ref<WebApiStatuses> = useState('webApiStatuses', () => ({}))
webApis = webApis || useWebApiList().value
webApis.forEach((webApi) => {
if (force || !webApiStatuses.value[webApi.id]) {
Expand Down
4 changes: 2 additions & 2 deletions pages/apis/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ definePageMeta({
const route = useRoute()
const webAPIStatuses: Ref<{ [key: keyof typeof webApiData]: boolean }> = useState('webApiStatuses', () => ({}))
const webApiStatuses: Ref<WebApiStatuses> = useState('webApiStatuses', () => ({}))
const webApiId = computed(() => route.params.id.toString())
const webApi = computed(() => ({ id: webApiId.value, ...webApiData[webApiId.value] }))
const available = computed(() => webAPIStatuses.value[webApiId.value])
const available = computed(() => webApiStatuses.value[webApiId.value])
useSeoMeta({
title: () => webApi.value.name,
Expand Down
2 changes: 1 addition & 1 deletion pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const webApiStatuses = useState('webApiStatuses', (): { [key: keyof typeof webAp
const fuse = computed(() => new Fuse(webApiList, searchOptions))
const filteredAPIs = computed(() => {
return debouncedSearchTerm.value
? fuse.value.search(debouncedSearchTerm.value).map((result: Fuse.FuseResult<WebAPI>) => result.item)
? fuse.value.search(debouncedSearchTerm.value).map((result: Fuse.FuseResult<WebApi>) => result.item)
: webApiList
})
const supportedAPICount = computed(() => filteredAPIs.value.filter(api => !!webApiStatuses.value[api.id]).length)
Expand Down
8 changes: 6 additions & 2 deletions types/webapis.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare interface WebAPI {
declare interface WebApi {
id: string, // also used as slug.
name: string,
path?: string,
Expand All @@ -23,7 +23,11 @@ declare interface WebAPI {
detail?: any,
}

declare interface WebAPIStatus {
declare interface WebApiStatuses {
[key: keyof typeof webApiData]: boolean
}

declare interface WebAPIStatusInfo {
name: string,
icon: string,
label: string,
Expand Down
2 changes: 1 addition & 1 deletion unocss.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default defineConfig({
'btn-subtle': 'btn bg-element hover:bg-element-active',
'btn-outline': 'btn bg-transparent border-solid border-2 border-zinc-200 hover:border-zinc-300 dark:(bg-transparent border-zinc-700 hover:border-zinc-600)',
'link': 'inline-block font-semibold underline decoration-1 underline-offset-2 decoration-sky-500 dark:decoration-sky-400',
'footer-link': 'text-base hover:(text-zinc-800 dark:text-white) cursor-pointer',
'footer-item': 'text-base hover:(text-zinc-800 dark:text-white) cursor-pointer',
'code-inline': 'font-mono px-1.5 py-0.5 bg-zinc-100 dark:bg-zinc-800 rounded',
},
presets: [
Expand Down
4 changes: 2 additions & 2 deletions utils/webapis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import DetailNetworkConnectionAPI from '~/components/detail/NetworkConnectionAPI
import DetailVisualViewport from '~/components/detail/VisualViewport.vue'
import DetailWebCryptoAPI from '~/components/detail/WebCryptoAPI.vue'

export function defaultWebApiCheck(api: WebAPI) {
export function defaultWebApiCheck(api: WebApi) {
if (api.path) {
const partials = api.path.split('.')
const path = partials[0] === 'window' ? partials.slice(1).join('.') : api.path
Expand All @@ -14,7 +14,7 @@ export function defaultWebApiCheck(api: WebAPI) {
return false
}

export const webApiData: { [slug: string]: Omit<WebAPI, 'id'> } = {
export const webApiData: { [slug: string]: Omit<WebApi, 'id'> } = {
'accelerometer': {
name: 'Accelerometer',
url: 'https://developer.mozilla.org/en-US/docs/Web/API/Accelerometer',
Expand Down

1 comment on commit 24c6cd2

@vercel
Copy link

@vercel vercel bot commented on 24c6cd2 Feb 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.