This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Create VSourcesTable component #1317
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,173 @@ | ||
<template> | ||
<table | ||
:aria-label="$t('sources.aria.table').toString()" | ||
role="region" | ||
class="table table-fixed w-full mt-4 mb-10 not-prose text-base" | ||
> | ||
<thead> | ||
<tr> | ||
<th | ||
tabindex="0" | ||
@click="sortTable('display_name')" | ||
@keypress.enter="sortTable('display_name')" | ||
> | ||
<span class="w-full flex flex-row items-center justify-between"> | ||
{{ $t('sources.providers.source') }} | ||
<TableSortIcon :active="sorting.field === 'display_name'" /> | ||
</span> | ||
</th> | ||
<th | ||
tabindex="0" | ||
@click="sortTable('source_url')" | ||
@keypress.enter="sortTable('source_url')" | ||
> | ||
<span class="w-full flex flex-row items-center justify-between"> | ||
{{ $t('sources.providers.domain') }} | ||
<TableSortIcon :active="sorting.field === 'source_url'" /> | ||
</span> | ||
</th> | ||
<th | ||
tabindex="0" | ||
@click="sortTable('media_count')" | ||
@keypress.enter="sortTable('media_count')" | ||
> | ||
<span class="w-full flex flex-row items-center justify-between"> | ||
{{ $t('sources.providers.item') }} | ||
<TableSortIcon :active="sorting.field === 'media_count'" /> | ||
</span> | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr v-for="(provider, index) in sortedProviders" :key="index"> | ||
<td> | ||
{{ provider.display_name }} | ||
</td> | ||
<td class="font-semibold truncate"> | ||
<VLink :href="provider.source_url"> | ||
{{ cleanSourceUrlForPresentation(provider.source_url) }} | ||
</VLink> | ||
</td> | ||
<td class="text-right"> | ||
{{ getLocaleFormattedNumber(provider.media_count || 0) }} | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import sortBy from 'lodash.sortby' | ||
import { | ||
computed, | ||
defineComponent, | ||
PropType, | ||
reactive, | ||
} from '@nuxtjs/composition-api' | ||
|
||
import { useProviderStore } from '~/stores/provider' | ||
import { useGetLocaleFormattedNumber } from '~/composables/use-get-locale-formatted-number' | ||
|
||
import type { SupportedMediaType } from '~/constants/media' | ||
|
||
import TableSortIcon from '~/components/TableSortIcon.vue' | ||
import VLink from '~/components/VLink.vue' | ||
|
||
import externalLinkIcon from '~/assets/icons/external-link.svg' | ||
|
||
export default defineComponent({ | ||
name: 'VSourcesTable', | ||
components: { | ||
TableSortIcon, | ||
VLink, | ||
}, | ||
props: { | ||
media: { | ||
type: String as PropType<SupportedMediaType>, | ||
required: true, | ||
}, | ||
}, | ||
setup(props) { | ||
const sorting = reactive({ | ||
direction: 'asc', | ||
field: 'display_name', | ||
}) | ||
|
||
function sortTable(field: string) { | ||
let direction = 'asc' | ||
if (field === sorting.field) { | ||
direction = sorting.direction === 'asc' ? 'desc' : 'asc' | ||
} | ||
|
||
sorting.direction = direction | ||
sorting.field = field | ||
} | ||
function cleanSourceUrlForPresentation(url: string) { | ||
const stripProtocol = (s: string) => s.replace(/https?:\/\//, '') | ||
const stripLeadingWww = (s: string) => | ||
s.startsWith('www.') ? s.replace('www.', '') : s | ||
const removeAfterSlash = (s: string) => s.split('/')[0] | ||
|
||
return removeAfterSlash(stripLeadingWww(stripProtocol(url))) | ||
} | ||
const getLocaleFormattedNumber = useGetLocaleFormattedNumber() | ||
const providerStore = useProviderStore() | ||
|
||
const sortedProviders = computed(() => { | ||
const sorted = sortBy(providerStore.providers[props.media], [ | ||
sorting.field, | ||
]) | ||
return sorting.direction === 'asc' ? sorted : sorted.reverse() | ||
}) | ||
return { | ||
getLocaleFormattedNumber, | ||
externalLinkIcon, | ||
sortedProviders, | ||
sorting, | ||
sortTable, | ||
cleanSourceUrlForPresentation, | ||
} | ||
}, | ||
}) | ||
</script> | ||
|
||
<style scoped> | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; | ||
|
||
@layer components { | ||
.table { | ||
@apply border-0 rounded-sm border-separate border-dark-charcoal-20; | ||
} | ||
.table th, | ||
.table td { | ||
@apply border-dark-charcoal-20; | ||
} | ||
.table a { | ||
@apply text-pink hover:underline; | ||
} | ||
.table th { | ||
@apply bg-dark-charcoal-10 border-t cursor-pointer; | ||
} | ||
.table th, | ||
.table td { | ||
@apply p-4 border-r first:border-l; | ||
} | ||
.table td { | ||
@apply break-normal border-y-0; | ||
} | ||
|
||
.table tr { | ||
@apply even:bg-dark-charcoal-06; | ||
} | ||
|
||
.table th { | ||
@apply first:rounded-tl-sm last:rounded-tr-sm; | ||
} | ||
|
||
.table tr:last-child td { | ||
@apply first:rounded-bl-sm last:rounded-br-sm border-b; | ||
} | ||
} | ||
</style> |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL
lodash.sortby
is over 2300 LOC 😱 Good thing we have #1108 😁There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤯