-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #260 from Southclaws/tags-ui
Tags UI
- Loading branch information
Showing
26 changed files
with
1,256 additions
and
236 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { tagGet } from "@/api/openapi-server/tags"; | ||
import { UnreadyBanner } from "@/components/site/Unready"; | ||
import { TagScreen } from "@/screens/tags/TagScreen"; | ||
|
||
type Props = { | ||
params: Promise<{ | ||
tag: string; | ||
}>; | ||
}; | ||
|
||
export default async function Page(props: Props) { | ||
const params = await props.params; | ||
try { | ||
const { tag } = params; | ||
|
||
const { data } = await tagGet(tag); | ||
return <TagScreen initialTag={data} slug={tag} />; | ||
} catch (e) { | ||
return <UnreadyBanner error={e} />; | ||
} | ||
} |
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,12 @@ | ||
import { tagList } from "@/api/openapi-server/tags"; | ||
import { UnreadyBanner } from "@/components/site/Unready"; | ||
import { TagsIndexScreen } from "@/screens/tags/TagsIndexScreen"; | ||
|
||
export default async function Page() { | ||
try { | ||
const { data } = await tagList(); | ||
return <TagsIndexScreen initialTagList={data} />; | ||
} catch (e) { | ||
return <UnreadyBanner error={e} />; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
web/src/components/library/LibraryPageTagsList/LibraryPageTagsList.tsx
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,58 @@ | ||
import { handle } from "@/api/client"; | ||
import { tagList } from "@/api/openapi-client/tags"; | ||
import { Node, TagNameList } from "@/api/openapi-schema"; | ||
import { TagBadgeList } from "@/components/tag/TagBadgeList"; | ||
import { Combotags } from "@/components/ui/combotags"; | ||
import { useLibraryMutation } from "@/lib/library/library"; | ||
|
||
export type Props = { | ||
editing: boolean; | ||
node: Node; | ||
}; | ||
|
||
export function LibraryPageTagsList(props: Props) { | ||
const { updateNode, revalidate } = useLibraryMutation(props.node); | ||
|
||
const currentTags = props.node.tags.map((t) => t.name); | ||
|
||
async function handleChange(values: string[]) { | ||
await handle( | ||
async () => { | ||
await updateNode(props.node.slug, { tags: values }); | ||
}, | ||
{ | ||
cleanup: async () => await revalidate(), | ||
}, | ||
); | ||
} | ||
|
||
async function handleQuery(q: string): Promise<TagNameList> { | ||
const tags = | ||
(await handle(async () => { | ||
const { tags } = await tagList({ q }); | ||
return tags.map((t) => t.name); | ||
})) ?? []; | ||
|
||
const filtered = tags.filter((t) => !currentTags.includes(t)); | ||
|
||
return filtered; | ||
} | ||
|
||
if (props.editing) { | ||
return ( | ||
<> | ||
<Combotags | ||
initialValue={currentTags} | ||
onQuery={handleQuery} | ||
onChange={handleChange} | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
if (props.node.tags.length === 0) { | ||
return null; | ||
} | ||
|
||
return <TagBadgeList tags={props.node.tags} />; | ||
} |
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,92 @@ | ||
import chroma from "chroma-js"; | ||
import Link from "next/link"; | ||
|
||
import { TagReference } from "@/api/openapi-schema"; | ||
import { css, cx } from "@/styled-system/css"; | ||
import { styled } from "@/styled-system/jsx"; | ||
import { badge } from "@/styled-system/recipes"; | ||
|
||
import { BadgeProps } from "../ui/badge"; | ||
|
||
export type Props = BadgeProps & { | ||
tag: TagReference; | ||
showItemCount?: boolean; | ||
}; | ||
|
||
// tags are always lowercase, which means most ascenders and descenders are | ||
// slightly mis-aligned to the optical center of the badge. | ||
const OPTICAL_ALIGNMENT_ADJUSTMENT = 1.5; | ||
|
||
const badgeStyles = css({ | ||
bgColor: "colorPalette", | ||
borderColor: "colorPalette.muted", | ||
color: "colorPalette.text", | ||
}); | ||
|
||
export function TagBadge({ tag, showItemCount, ...props }: Props) { | ||
const cssVars = badgeColourCSS(tag.colour); | ||
|
||
const styles = { | ||
...cssVars, | ||
"--optical-adjustment-top": `${-OPTICAL_ALIGNMENT_ADJUSTMENT}px`, | ||
"--optical-adjustment-bot": `${OPTICAL_ALIGNMENT_ADJUSTMENT}px`, | ||
"--optical-adjustment-count-right": "0.4rem", | ||
}; | ||
|
||
const titleLabel = `${tag.item_count} items tagged with ${tag.name}`; | ||
|
||
return ( | ||
<Link | ||
className={cx( | ||
badge({ | ||
size: "sm", | ||
...props, | ||
}), | ||
badgeStyles, | ||
)} | ||
style={styles} | ||
title={titleLabel} | ||
href={`/tags/${tag.name}`} | ||
> | ||
{showItemCount && ( | ||
<styled.span | ||
borderRightStyle="solid" | ||
borderRightWidth="thin" | ||
borderRightColor="colorPalette.muted" | ||
paddingRight="var(--optical-adjustment-count-right)" | ||
> | ||
{tag.item_count} | ||
</styled.span> | ||
)} | ||
|
||
<styled.span | ||
mb="var(--optical-adjustment-bot)" | ||
mt="var(--optical-adjustment-top)" | ||
> | ||
{tag.name} | ||
</styled.span> | ||
</Link> | ||
); | ||
} | ||
|
||
function badgeColourCSS(c: string) { | ||
const { bg, bo, fg } = badgeColours(c); | ||
|
||
return { | ||
"--colors-color-palette-text": fg, | ||
"--colors-color-palette-muted": bo, | ||
"--colors-color-palette": bg, | ||
} as React.CSSProperties; | ||
} | ||
|
||
function badgeColours(c: string) { | ||
const colour = chroma(c); | ||
|
||
const hue = colour.lch()[2]; | ||
|
||
const bg = chroma(0.95, 0.1, hue, "oklch").css(); | ||
const bo = chroma(0.85, 0.2, hue, "oklch").css(); | ||
const fg = chroma(0.55, 0.2, hue, "oklch").css(); | ||
|
||
return { bg, bo, fg }; | ||
} |
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,19 @@ | ||
import { TagReferenceList } from "@/api/openapi-schema"; | ||
import { HStack } from "@/styled-system/jsx"; | ||
|
||
import { TagBadge } from "./TagBadge"; | ||
|
||
export type Props = { | ||
tags: TagReferenceList; | ||
showItemCount?: boolean; | ||
}; | ||
|
||
export function TagBadgeList({ tags, showItemCount }: Props) { | ||
return ( | ||
<HStack flexWrap="wrap"> | ||
{tags.map((r) => ( | ||
<TagBadge key={r.name} tag={r} showItemCount={showItemCount} /> | ||
))} | ||
</HStack> | ||
); | ||
} |
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,65 @@ | ||
import { ChevronRightIcon } from "@heroicons/react/24/outline"; | ||
import { Fragment } from "react"; | ||
|
||
import { LinkButton } from "@/components/ui/link-button"; | ||
import { Box, HStack, styled } from "@/styled-system/jsx"; | ||
|
||
type Props = { | ||
index: Breadcrumb; | ||
crumbs: Breadcrumb[]; | ||
}; | ||
|
||
type Breadcrumb = { | ||
label: string; | ||
href: string; | ||
}; | ||
|
||
export function Breadcrumbs({ index, crumbs }: Props) { | ||
return ( | ||
<HStack | ||
w="full" | ||
color="fg.subtle" | ||
overflowX="scroll" | ||
pt="scrollGutter" | ||
mt="-scrollGutter" | ||
> | ||
<LinkButton | ||
size="xs" | ||
variant="subtle" | ||
flexShrink="0" | ||
minW="min" | ||
href={index.href} | ||
> | ||
{index.label} | ||
</LinkButton> | ||
{crumbs.map((c) => { | ||
return ( | ||
<Fragment key={c.href}> | ||
<Box flexShrink="0"> | ||
<ChevronRightIcon width="1rem" /> | ||
</Box> | ||
|
||
<BreadcrumbButton crumb={c} /> | ||
</Fragment> | ||
); | ||
})} | ||
</HStack> | ||
); | ||
} | ||
|
||
function BreadcrumbButton({ crumb }: { crumb: Breadcrumb }) { | ||
return ( | ||
<LinkButton | ||
size="xs" | ||
variant="subtle" | ||
flexShrink="0" | ||
maxW="64" | ||
overflow="hidden" | ||
href={crumb.href} | ||
> | ||
<styled.span overflowX="hidden" textWrap="nowrap" textOverflow="ellipsis"> | ||
{crumb.label} | ||
</styled.span> | ||
</LinkButton> | ||
); | ||
} |
Oops, something went wrong.