From 43c5f429548eda8afa9752d67d90bef4492291b6 Mon Sep 17 00:00:00 2001 From: viet nguyen Date: Sun, 26 Nov 2023 07:33:19 -0800 Subject: [PATCH] add subareas table to area page --- src/app/area/[...slug]/page.tsx | 27 +++++++++++- .../[slug]/general/components/AddAreaForm.tsx | 2 +- .../[slug]/general/components/AreaItem.tsx | 43 ++++++++++--------- .../[slug]/general/components/AreaList.tsx | 15 ++++--- src/app/editArea/[slug]/general/page.tsx | 4 +- src/components/cues/Entities.tsx | 3 ++ src/components/editor/MarkdownEditor.tsx | 7 +-- 7 files changed, 64 insertions(+), 37 deletions(-) create mode 100644 src/components/cues/Entities.tsx diff --git a/src/app/area/[...slug]/page.tsx b/src/app/area/[...slug]/page.tsx index 5eb30a0b9..0afc88472 100644 --- a/src/app/area/[...slug]/page.tsx +++ b/src/app/area/[...slug]/page.tsx @@ -1,7 +1,8 @@ +import Link from 'next/link' import { notFound, redirect } from 'next/navigation' import slugify from 'slugify' import { validate } from 'uuid' -import { MapPinLine } from '@phosphor-icons/react/dist/ssr' +import { MapPinLine, PlusCircle } from '@phosphor-icons/react/dist/ssr' import 'mapbox-gl/dist/mapbox-gl.css' import Markdown from 'react-markdown' @@ -13,6 +14,9 @@ import { ArticleLastUpdate } from '@/components/edit/ArticleLastUpdate' import { getMapHref } from '@/js/utils' import AreaMap from '@/components/area/areaMap' import { PageContainer } from '@/app/components/ui/PageContainer' +import { AreaList } from 'app/editArea/[slug]/general/components/AreaList' +import { AreaEntityBullet } from '@/components/cues/Entities' + /** * Cache duration in seconds */ @@ -92,6 +96,27 @@ export default async function Page ({ params }: PageWithCatchAllUuidProps): Prom

Description

{description} + + + +
+
+
+

{area.children.length} Areas

+ {/* + + */} +
+ + + +
+ +
+ +
) diff --git a/src/app/editArea/[slug]/general/components/AddAreaForm.tsx b/src/app/editArea/[slug]/general/components/AddAreaForm.tsx index 3c0e21c84..7f0857478 100644 --- a/src/app/editArea/[slug]/general/components/AddAreaForm.tsx +++ b/src/app/editArea/[slug]/general/components/AddAreaForm.tsx @@ -26,7 +26,7 @@ export const AddAreaForm: React.FC<{ area: AreaType }> = ({ area }) => { initialValues={{ areaName: '' }} keepValuesAfterReset={false} title='Add new area' - helperText='Do not copy description from guidebooks.' + helperText='TIP: Pick “AREA” if not sure. You can still change it later.' submitHandler={async ({ areaName, areaType }) => { const { isBoulder, isLeaf } = areaDesignationToDb(areaType) await addOneAreaCmd({ name: areaName, parentUuid: uuid, isBoulder, isLeaf }) diff --git a/src/app/editArea/[slug]/general/components/AreaItem.tsx b/src/app/editArea/[slug]/general/components/AreaItem.tsx index 38c3d56eb..5f332238f 100644 --- a/src/app/editArea/[slug]/general/components/AreaItem.tsx +++ b/src/app/editArea/[slug]/general/components/AreaItem.tsx @@ -8,7 +8,7 @@ import { DeleteAreaTrigger, DeleteAreaTriggerButtonSm } from '@/components/edit/ export type EType = 'area' | 'crag' | 'boulder' | 'climb' -const CragIcon = forwardRef((props, ref) => ) +const CragIcon = forwardRef((props, ref) => ) // type MyIconProps = Icon & { // class @@ -31,36 +31,39 @@ export const EntityIcon: React.FC<{ type: EType, withLabel?: boolean, size?: 20 ) } -export const AreaItem: React.FC<{ area: AreaType, parentUuid: string, index: number }> = ({ area, index, parentUuid }) => { +export const AreaItem: React.FC<{ + area: AreaType + parentUuid: string + index: number + editMode: boolean +}> = ({ area, index, parentUuid, editMode = false }) => { const { uuid, areaName, children, climbs } = area // undefined array can mean we forget to include the field in GQL so let's make it not editable const canDelete = (children?.length ?? 1) === 0 && (climbs?.length ?? 1) === 0 + const url = editMode ? `/editArea/${uuid}` : `/area/${uuid}` return (
-
-
-
-
{index}
-
-
- + +
+
+
+
{index}
+
+
{areaName} - -
- +
+ +
-
-
- -
+ + {editMode && +
+ +
}
) } diff --git a/src/app/editArea/[slug]/general/components/AreaList.tsx b/src/app/editArea/[slug]/general/components/AreaList.tsx index b142af1d4..105161f0b 100644 --- a/src/app/editArea/[slug]/general/components/AreaList.tsx +++ b/src/app/editArea/[slug]/general/components/AreaList.tsx @@ -7,7 +7,7 @@ type AreaListProps = Pick = ({ areaName, uuid, pathTokens, ancestors, areas }) => { +export const AreaListForm: React.FC = ({ areaName, uuid, pathTokens, ancestors, areas }) => { return (
@@ -22,14 +22,15 @@ export const AreaList: React.FC = ({ areaName, uuid, pathTokens,
- - {/* Child area list */} -
- {areas.map((item, index) => - )} -
+
) } + +export const AreaList: React.FC<{ parentUuid: string, areas: AreaType[], editMode?: boolean }> = ({ areas, parentUuid, editMode = false }) => ( +
+ {areas.map((item, index) => + )} +
) diff --git a/src/app/editArea/[slug]/general/page.tsx b/src/app/editArea/[slug]/general/page.tsx index e6ba01f92..3bc114738 100644 --- a/src/app/editArea/[slug]/general/page.tsx +++ b/src/app/editArea/[slug]/general/page.tsx @@ -8,7 +8,7 @@ import { AreaNameForm } from './components/AreaNameForm' import { AreaDescriptionForm } from './components/AreaDescriptionForm' import { AreaLatLngForm } from './components/AreaLatLngForm' import { AddAreaForm } from './components/AddAreaForm' -import { AreaList } from './components/AreaList' +import { AreaListForm } from './components/AreaList' import { AreaTypeForm } from './components/AreaTypeForm' // Opt out of caching for all data requests in the route segment @@ -58,7 +58,7 @@ export default async function AreaEditPage ({ params }: DashboardPageProps): Pro - diff --git a/src/components/editor/MarkdownEditor.tsx b/src/components/editor/MarkdownEditor.tsx index ef91f8c40..2004d94db 100644 --- a/src/components/editor/MarkdownEditor.tsx +++ b/src/components/editor/MarkdownEditor.tsx @@ -23,14 +23,9 @@ export interface MarkdownEditorProps { } /** - * Multiline inplace editor with react-hook-form support. + * Multiline markdown editor with react-hook-form support. */ export const MarkdownEditor: React.FC = ({ fieldName, initialValue = '', preview = false, placeholder = 'Enter some text', rules }) => { - // const { field, fieldState: { error } } = useController({ name: fieldName, rules }) - - // const onChangeHandler = (arg0: EditorState, arg1: LexicalEditor): void => { - // onChange(arg0, arg1, field) - // } const config = mdeditorConfig(initialValue, !preview) return (