Sort socials

This commit is contained in:
Ahmed Al-Taiar
2024-10-06 18:54:26 -04:00
parent fb542bb5b5
commit 49c943c9f3
3 changed files with 104 additions and 80 deletions

View File

@@ -1,12 +1,11 @@
import { FindSocials } from 'types/graphql'
import { baseUrls, getLogoComponent } from 'src/lib/handle'
import { baseUrls, getLogoComponent, sortOrder } from 'src/lib/handle'
const SocialLinks = ({ socials }: FindSocials) => {
return (
const SocialLinks = ({ socials }: FindSocials) => (
<div className={`grid max-w-68 grid-cols-[repeat(auto-fit,3rem)] gap-2`}>
{[...socials]
.sort((a, b) => (a.type > b.type ? 1 : -1))
.sort((a, b) => sortOrder.indexOf(a.type) - sortOrder.indexOf(b.type))
.map((social, i) => (
<div key={i} className="tooltip" data-tip={social.name}>
<a
@@ -20,7 +19,6 @@ const SocialLinks = ({ socials }: FindSocials) => {
</div>
))}
</div>
)
}
)
export default SocialLinks

View File

@@ -13,7 +13,7 @@ import { toast } from '@redwoodjs/web/toast'
import { QUERY } from 'src/components/Social/SocialsCell'
import { truncate } from 'src/lib/formatters'
import { getLogoComponent } from 'src/lib/handle'
import { getLogoComponent, sortOrder } from 'src/lib/handle'
const DELETE_SOCIAL_MUTATION: TypedDocumentNode<
DeleteSocialMutation,
@@ -58,7 +58,11 @@ const SocialsList = ({ socials }: FindSocials) => {
</tr>
</thead>
<tbody>
{socials.map((social) => {
{[...socials]
.sort(
(a, b) => sortOrder.indexOf(a.type) - sortOrder.indexOf(b.type)
)
.map((social) => {
const actionButtons = (
<>
<Link

View File

@@ -20,7 +20,7 @@ import {
} from '@icons-pack/react-simple-icons'
import { mdiEmail, mdiLink, mdiPhone } from '@mdi/js'
import Icon from '@mdi/react'
import type { Handle } from 'types/graphql'
import type { Handle, Social } from 'types/graphql'
export const baseUrls: Record<Handle, string> = {
x: 'https://x.com/',
@@ -76,4 +76,26 @@ const logoComponents: Record<Handle, ReactElement> = {
custom: <Icon path={mdiLink} className="size-7" />,
}
export const sortOrder: Social['type'][] = [
'phone',
'email',
'custom',
'linkedin',
'leetcode',
'github',
'gitea',
'forgejo',
'gitlab',
'bitbucket',
'youtube',
'x',
'instagram',
'tiktok',
'facebook',
'threads',
'twitch',
'discord',
'steam',
]
export const getLogoComponent = (type: Handle) => logoComponents[type]