Skip to content

Commit

Permalink
Fix bunch of small issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kossnocorp committed Dec 16, 2023
1 parent 4380a3e commit 7ccbb9e
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/ui/components/TypeDocType/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ export const TypeDocType: FunctionComponent<TypeDocTypeProps> = ({
case 'inferred':
case 'unknown':
case 'typeOperator':
case 'template-literal':
case 'named-tuple-member':
case 'templateLiteral':
case 'namedTupleMember':
case 'optional':
case 'rest':
return <Missing data={type} />
Expand Down
8 changes: 5 additions & 3 deletions src/ui/screens/Docs/Doc/TypeDoc/Constants/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ function Constant({ item, query }: ConstantProps) {

if (constant.kind !== DateFnsDocs.ReflectionKind.Variable) return null

const { usage, usageTabs } = useMemo(() => generateUsage(name, 'constants'), [
item,
])
const { usage, usageTabs } = useMemo(
() =>
generateUsage(name, { submodule: 'constants', alwaysSubmodule: true }),
[item]
)

const examples = useMemo(
() => findExamples(constant).map(extractCodeFromTagString),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { IgnoreParentTypesSourceContext } from '~/ui/contexts/IgnoreParentTypesS
import { Arguments } from '../Arguments'
import { Generics } from '../Generics'
import { Returns } from '../Returns'
import { Throws } from '../Throws'
import { Type } from '../Type'
import { Debug } from '~/ui/components/Debug'
import { DocExamples } from '~/ui/components/DocExamples'
import { extractCodeFromTagString } from '~/utils/docs'
import { Throws } from '../Throws'

interface SignatureProps {
name: string
Expand Down
6 changes: 0 additions & 6 deletions src/ui/screens/Docs/Doc/TypeDoc/Function/Throws/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Fragment, FunctionComponent, h } from 'preact'
import { InlineCode } from '~/ui/components/InlineCode'
import { Markdown } from '~/ui/components/Markdown'
import { SectionHeader } from '~/ui/components/SectionHeader'

export interface TypeDocThrow {
type: string | undefined
description: string
}

Expand All @@ -26,17 +24,13 @@ export const Throws: FunctionComponent<TypeDocThrowsProps> = ({
<table>
<thead>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
</thead>

<tbody>
{throws.map((throwData, index) => (
<tr key={index}>
<td>
{throwData.type && <InlineCode>{throwData.type}</InlineCode>}
</td>
<td>
<Markdown value={throwData.description} />
</td>
Expand Down
5 changes: 4 additions & 1 deletion src/ui/screens/Docs/Doc/TypeDoc/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ import { matchTypeHash } from '~/utils/docs'
import { TypeDocConstants } from './Constants'
import { TypeDocFunction } from './Function'
import { useTypesModal } from './Types'
import type { DeclarationReflection } from 'typedoc'

interface TypeDocProps {
page: DateFnsDocs.TypeDocPage
}

export const TypeDoc: FunctionComponent<TypeDocProps> = ({ page }) => {
const { location, navigate } = useContext(RouterContext)
const doc = useMemo(() => parse(page.doc), [page.slug])
const doc = useMemo(() => parse(page.doc) as DeclarationReflection, [
page.slug,
])
const showTypesModal = useTypesModal()

useEffect(() => {
Expand Down
2 changes: 0 additions & 2 deletions src/ui/screens/Docs/Finder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ export const Finder: FunctionComponent<FinderProps> = ({
const { pages, categories } = versions[0].data
const filteredPages = filterPages(pages, query, selectedSubmodule)

console.log({ filteredPages })

return (
<div class={styles.container}>
<Search query={[query, setQuery]} inputRef={searchRef} />
Expand Down
22 changes: 17 additions & 5 deletions src/utils/docs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,33 @@ export interface UsageMap {
usageTabs: string[]
}

export function generateUsage(name: string, module = name): UsageMap {
export interface GenerateUsageOptions {
submodule?: string
alwaysSubmodule?: boolean
}

export function generateUsage(
name: string,
options?: GenerateUsageOptions
): UsageMap {
const submodule = options?.submodule || name
const path = `date-fns${options?.alwaysSubmodule ? `/${submodule}` : ''}`

const usage: Usage = {
esm: {
code: `import { ${name} } from "date-fns";`,
code: `import { ${name} } from "${path}";`,
title: 'ESM',
},

commonjs: {
code: `const ${name} = require("date-fns/${module}");`,
code: `const { ${name} } = require("${path}");`,
title: 'CommonJS',
},

cdn: {
title: 'CDN',
code: (cdn) => `import ${name} from "${cdn}/date-fns/${name}.mjs";`,
code: (cdn) =>
`import { ${name} } from "${cdn}/date-fns/${submodule}.mjs";`,
options: {
unpkg: 'https://unpkg.com',
Skypack: 'https://cdn.skypack.dev',
Expand Down Expand Up @@ -85,7 +97,7 @@ export function findSource(
| undefined,
trimHash = false
) {
const url = ref?.sources?.[0].url
const url = ref && 'sources' in ref && ref?.sources?.[0].url
if (!url) return
return trimHash ? url.replace(/#.*$/, '') : url
}
Expand Down

0 comments on commit 7ccbb9e

Please sign in to comment.