Merge pull request #2170 from omnivore-app/fix/username-validation

Fix issue where incorrect username validation message was displayed during signup, add label sorting to cards
This commit is contained in:
Jackson Harper 2023-05-05 13:05:17 +08:00 committed by GitHub
commit f6ba5d90fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 13 deletions

View file

@ -58,6 +58,7 @@ export const DescriptionStyle = {
'-webkit-box-orient': 'vertical',
height: '45px',
alignItems: 'start',
maxWidth: '-webkit-fill-available',
}
export const AuthorInfoStyle = {

View file

@ -18,6 +18,7 @@ import {
timeAgo,
TitleStyle,
} from './LibraryCardStyles'
import { sortedLabels } from '../../../lib/labelsSort'
dayjs.extend(relativeTime)
@ -178,9 +179,11 @@ export function LibraryGridCard(props: LinkedItemCardProps): JSX.Element {
minHeight: '35px',
}}
>
{props.item.labels?.map(({ name, color }, index) => (
<LabelChip key={index} text={name || ''} color={color} />
))}
{sortedLabels(props.item.labels).map(
({ name, color }, index) => (
<LabelChip key={index} text={name || ''} color={color} />
)
)}
</HStack>
<VStack
css={{

View file

@ -14,6 +14,7 @@ import {
timeAgo,
TitleStyle,
} from './LibraryCardStyles'
import { sortedLabels } from '../../../lib/labelsSort'
export function LibraryListCard(props: LinkedItemCardProps): JSX.Element {
const [isHovered, setIsHovered] = useState(false)
@ -118,9 +119,11 @@ export function LibraryListCard(props: LinkedItemCardProps): JSX.Element {
display: 'block',
}}
>
{props.item.labels?.map(({ name, color }, index) => (
<LabelChip key={index} text={name || ''} color={color} />
))}
{sortedLabels(props.item.labels).map(
({ name, color }, index) => (
<LabelChip key={index} text={name || ''} color={color} />
)
)}
</HStack>
</HStack>
</VStack>

View file

@ -16,8 +16,7 @@ export function ProfileLayout(props: ProfileLayoutProps): JSX.Element {
css={{
// bg: '$omnivoreYellow',
height: '100vh',
background:
'-webkit-linear-gradient(-65deg, rgba(255, 255, 255, 1.0) 45%, rgba(255, 210, 52, 1.0) 0%)',
bg: '$omnivoreYellow',
}}
>
{props.children}

View file

@ -0,0 +1,36 @@
import { Label } from './networking/fragments/labelFragment'
export const sortedLabels = (labels: Label[] | undefined): Label[] => {
if (!labels) {
return []
}
const colors = new Map<string, Label[]>()
for (const label of labels) {
const list = colors.get(label.color) ?? []
list.push(label)
colors.set(
label.color,
list.sort((a, b) => a.name.localeCompare(b.name))
)
}
const sortedColors = Array.from(colors.keys()).sort((a, b) => {
// Sort by the first element's name
const aname = colors.get(a)?.find(() => true)?.name ?? a
const bname = colors.get(b)?.find(() => true)?.name ?? b
return aname.localeCompare(bname)
})
const result: Label[] = []
for (const key of sortedColors) {
const items = colors.get(key)
if (!items) {
continue
}
const sorted = items.sort((a, b) => a.name.localeCompare(b.name))
result.push(...sorted)
}
return result
}

View file

@ -24,8 +24,12 @@ export function useValidateUsernameQuery({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const isUsernameValid = (data as any)?.validateUsername ?? false
const usernameErrorMessage = validationErrorMessage(username)
if (isUsernameValid) {
return { isUsernameValid }
}
// Try to figure out why the username is invalid
const usernameErrorMessage = validationErrorMessage(username.toLowerCase())
if (usernameErrorMessage) {
return {
isUsernameValid: false,
@ -33,10 +37,6 @@ export function useValidateUsernameQuery({
}
}
if (isUsernameValid) {
return { isUsernameValid }
}
return {
isUsernameValid: false,
usernameErrorMessage: 'This username is not available',