Skip to content

Commit

Permalink
map blog post widget
Browse files Browse the repository at this point in the history
  • Loading branch information
nofurtherinformation committed Aug 7, 2024
1 parent e920959 commit 2766222
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 8 deletions.
2 changes: 0 additions & 2 deletions components/EnhancedMarkdown/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import React from "react"
import { TinaMarkdown } from "tinacms/dist/rich-text"
import PostWidget from "components/PostWidgets"
import { StateConcentrationDataTable } from "./StateConcentrationData"
import { MdTooltip } from "./Tooltip"

const DEFAULT_MARKDOWN_COMPONENTS = {
Tooltip: MdTooltip,
SortableMarketTable: StateConcentrationDataTable,
}

export const PostMarkdown: React.FC<{ content: any }> = ({ content }) => {
Expand Down
3 changes: 2 additions & 1 deletion components/MapSettings/MapSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const contentSectionTitles = [
"highlight advanced",
"filter map",
]
const nullSections: any[] = []

const findContentSections = (contentSections: any[], titles: string[] = contentSectionTitles) => {
const entries: Record<string, React.ReactNode> = {}
Expand All @@ -50,7 +51,7 @@ const findContentSections = (contentSections: any[], titles: string[] = contentS

export const MapSettings: React.FC = () => {
const md = useMarkdownContext()
const contentSections = md.pageInfo.data.page.sections
const contentSections = md?.pageInfo?.data?.page?.sections || nullSections
const sections = useMemo(() => (contentSections ? findContentSections(contentSections) : {}), [contentSections])

const [activeMenuSection, setActiveMenuSection] = useState<string | undefined>(undefined)
Expand Down
15 changes: 14 additions & 1 deletion components/PostWidgets/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
"use client"
import React from "react"
import { StateConcentrationDataTable } from "components/EnhancedMarkdown/StateConcentrationData"
import MapPageInner from "components/Pages/Map"

const PostWidget: React.FC<{ widget: string }> = ({ widget }) => {
const PostWidget: React.FC<{ widget: string; props?: string }> = ({ widget, props }) => {
switch (widget) {
case "SortableMarketTable":
return <StateConcentrationDataTable />
case "test":
return <code className="bg-gray-200 p-2">Test widget</code>
case "Map":
let extraProps: any = {}
try {
typeof props === "string" && (extraProps = JSON.parse(props))
} catch (e) {
console.error("Error parsing props", e, props)
}
return (
<div className="relative h-[50vh] w-full">
<MapPageInner pageInfo={{}} stats={{}} {...extraProps} />
</div>
)
default:
return null
}
Expand Down
6 changes: 5 additions & 1 deletion public/content/post/post-name.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ shortText: Temp
---

Hello world!
1234

<PostWidget widget="Map" props="{&#x22;initialFilter&#x22;: [&#x22;31043&#x22;,&#x22;31051&#x22;,&#x22;31173&#x22;]}" />

1234

<Tooltip
title="Test"
lookupKey="test"
body={<>
# ASDF
</>}
Expand Down
2 changes: 1 addition & 1 deletion tina/__generated__/_graphql.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tina/__generated__/_schema.json

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions tina/__generated__/config.prebuild.jsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tina/__generated__/schema.gql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tina/__generated__/types.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tina/tina-lock.json

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions tina/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,17 @@ export const PostText = {
label: "Test",
value: "test",
},
{
label: "Map",
value: "Map",
},
],
},
{
name: "props",
label: "Extra Props (advanced)",
type: "string",
},
],
},
],
Expand Down

0 comments on commit 2766222

Please sign in to comment.