Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.formatOnSave": false
}
6 changes: 6 additions & 0 deletions astro-tina-directive/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'astro'
declare module 'astro' {
interface AstroClientDirectives {
'client:tina'?: boolean
}
}
14 changes: 14 additions & 0 deletions astro-tina-directive/register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @type {() => import('astro').AstroIntegration}
*/
export default () => ({
name: "client:tina",
hooks: {
"astro:config:setup": ({ addClientDirective }) => {
addClientDirective({
name: "tina",
entrypoint: "./astro-tina-directive/tina.js",
});
},
},
});
17 changes: 17 additions & 0 deletions astro-tina-directive/tina.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Hydrate on first click on the window
* @type {import('astro').ClientDirective}
*/
export default async (load, options, el) => {
try {
const isInIframe = window.self !== window.top;
if (!isInIframe) {
return;
}

const hydrate = await load();
await hydrate();
} catch (error) {
console.error("An error occurred in the Tina client directive:", error);
}
};
3 changes: 2 additions & 1 deletion astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { defineConfig, envField } from 'astro/config';
import auth from 'auth-astro';
import { loadEnv } from 'vite';
import config from './public/config.json';
import tinaDirective from "./astro-tina-directive/register"

const { locales, default_locale: defaultLocale } = config.i18n;
const { STATIC_BUILD } = loadEnv(process.env.STATIC_BUILD, process.cwd(), '');
Expand All @@ -22,7 +23,7 @@ export default defineConfig({
},
output: STATIC_BUILD === 'true' ? 'static' : 'server',
adapter: netlify(),
integrations: [mdx(), sitemap(), react(), auth()],
integrations: [mdx(), sitemap(), react(), auth(), tinaDirective()],
vite: {
optimizeDeps: {
esbuildOptions: {
Expand Down
135 changes: 100 additions & 35 deletions public/config.json
Original file line number Diff line number Diff line change
@@ -1,51 +1,116 @@
{
"detail_pages": [
"places",
"events"
],
"content": {
"collections": [
"paths",
"posts"
]
"posts",
"paths"
],
"localize_pages": true
},
"core_data": {
"url": "https://staging.coredata.cloud",
"url": "https://app.coredata.cloud",
"project_ids": [
"1",
"2",
"3"
"85"
]
},
"i18n": {
"default_locale": "en",
"locales": ["en"]
"locales": [
"en",
"sp",
"pt-br",
"fr"
]
},
"layers": [{
"name": "Maptiler DataViz Style",
"layer_type": "vector",
"url": "https://api.maptiler.com/maps/dataviz/style.json?key=WLMbLZP1AwK3zUFTeheB"
}],
"search": [{
"name": "places",
"route": "/places",
"geosearch": true,
"map": {
"clusterRadius": 6,
"geometry": "geometry",
"max_zoom": 14,
"zoom_to_place": true
"layers": [
{
"name": "Maptiler DataViz Style",
"layer_type": "vector",
"url": "https://api.maptiler.com/maps/dataviz/style.json?key=WLMbLZP1AwK3zUFTeheB"
},
{
"name": "USGS Imagery Topo (MapServer)",
"layer_type": "raster",
"url": "https://basemap.nationalmap.gov/arcgis/services/USGSImageryTopo/MapServer/WMSServer?bbox={bbox-epsg-3857}&format=image/png&service=WMS&version=1.1.1&request=GetMap&srs=EPSG:3857&transparent=true&width=256&height=256&layers=0&styles=default"
},
"result_card": {
"title": "name"
{
"name": "USGS Topo (MapServer)",
"layer_type": "raster",
"url": "https://basemap.nationalmap.gov/arcgis/services/USGSTopo/MapServer/WMSServer?bbox={bbox-epsg-3857}&format=image/png&service=WMS&version=1.1.1&request=GetMap&srs=EPSG:3857&transparent=true&width=256&height=256&layers=0&styles=default"
},
{
"name": "US States",
"layer_type": "geojson",
"url": "gz_2010_us_040_00_20m.json",
"overlay": true
}
],
"search": [
{
"name": "Places",
"route": "/places",
"geosearch": true,
"map": {
"geometry": "geometry",
"max_zoom": 14,
"zoom_to_place": true
},
"result_card": {
"title": "name"
},
"timeline": {
"date_range_facet": "event_range_facet",
"event_path": "1538d574-7d78-4fcc-959e-ca9f9c86e14f"
},
"typesense": {
"host": "czlf39ts8mj74bq0p-1.a1.typesense.net",
"port": 443,
"protocol": "https",
"api_key": "jGCcfd8YLne4KieMOj6KWbr7NDFHNDVQ",
"index_name": "cdra_places",
"query_by": "name",
"facets": {
"exclude": [
"owner_project.name_facet",
"all_projects.name_facet",
"name_facet"
]
}
}
},
"typesense": {
"host": "example.typesense.com",
"port": 443,
"protocol": "https",
"api_key": "abcdefg",
"index_name": "core_data_places",
"query_by": "name",
"default_sort": "name",
"overrides": {
"geoLocationField": "coordinates"
{
"name": "Events",
"route": "/events",
"geosearch": true,
"map": {
"geometry": "1538d574-7d78-4fcc-959e-ca9f9c86e14f.geometry",
"max_zoom": 14,
"zoom_to_place": true
},
"result_card": {
"title": "name"
},
"timeline": {
"date_range_facet": "event_range_facet"
},
"typesense": {
"host": "czlf39ts8mj74bq0p-1.a1.typesense.net",
"port": 443,
"protocol": "https",
"api_key": "ZVn0DyHllZx7ZeELRiW6KCnLxu0hsv6f",
"index_name": "cdra_events",
"query_by": "name",
"facets": {
"exclude": [
"owner_project.name_facet",
"all_projects.name_facet",
"name_facet"
]
}
}
}
}]
]
}
2 changes: 1 addition & 1 deletion src/apps/pages/RecordDetail/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ for (const modelType of Object.keys(record.relatedRecords)) {
/>
{relations.manifests && (
<MediaContents
client:only="react"
client:only='react'
data={relations.manifests}
lang={lang}
/>
Expand Down
47 changes: 27 additions & 20 deletions src/apps/paths/PathViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,29 @@ import {
} from 'react';
import { TinaMarkdown } from 'tinacms/dist/rich-text';
import Byline from '@components/Byline';
import { tinaField, useTina } from 'tinacms/dist/react';

export interface PathViewerProps {
path: any;
}

const PathViewer = (props: PathViewerProps) => {
const [current, setCurrent] = useState(-1);
const [currentPlace, setCurrentPlace] = useState(-1);

const { path } = props;
const { data } = useTina({
query: props.path.query,
variables: props.path.variables,
data: props.path.data
});
const path = useMemo(() => (data.path), [data])
const contentDiv = useRef(null);

const { t } = useTranslations();

/**
* Memo-izes the current place.
* Memo-izes the currentPlace place.
*/
const place = useMemo(() => path?.path[current] && path.path[current].place, [current, path]);
const place = useMemo(() => path?.path[currentPlace] && path.path[currentPlace].place, [currentPlace, path]);

/**
* Memo-izes the array of place IDs.
Expand All @@ -46,15 +52,15 @@ const PathViewer = (props: PathViewerProps) => {
: path.path.map(({ place: { uuid }}) => uuid), [place]);

/**
* Scrolls to the top of the content div when the current path changes.
* Scrolls to the top of the content div when the currentPlace path changes.
*/
useEffect(() => {
const { current: instance } = contentDiv;

if (instance) {
instance.scroll({ top: 0, behavior: 'smooth' });
}
}, [current]);
}, [currentPlace]);

return (
<RuntimeConfig
Expand All @@ -67,6 +73,7 @@ const PathViewer = (props: PathViewerProps) => {
>
<div
className='w-full flex flex-row grow relative h-[calc(100vh-96px)]'
data-tina-field={tinaField(path, "path")}
>
{ path && (
<div
Expand All @@ -92,26 +99,26 @@ const PathViewer = (props: PathViewerProps) => {
<ArrowUturnLeftIcon
className={clsx(
'h-8 w-8',
{ 'text-gray-500 cursor-default': current < 0 },
{ 'cursor-pointer hover:scale-105 transition': current >= 0 }
{ 'text-gray-500 cursor-default': currentPlace < 0 },
{ 'cursor-pointer hover:scale-105 transition': currentPlace >= 0 }
)}
onClick={() => setCurrent(-1)}
onClick={() => setCurrentPlace(-1)}
/>
<ArrowLeftCircleIcon
className={clsx(
'h-8 w-8',
{ 'text-gray-500 cursor-default': current === 0 },
{ 'cursor-pointer hover:scale-105 transition': current !== 0 }
{ 'text-gray-500 cursor-default': currentPlace === 0 },
{ 'cursor-pointer hover:scale-105 transition': currentPlace !== 0 }
)}
onClick={() => current > 0 && setCurrent((i) => i - 1)}
onClick={() => currentPlace > 0 && setCurrentPlace((i) => i - 1)}
/>
<ArrowRightCircleIcon
className={clsx(
'h-8 w-8',
{ 'text-gray-500 cursor-default': current === path.path.length - 1 },
{ 'cursor-pointer hover:scale-105 transition': current !== path.path.length - 1 }
{ 'text-gray-500 cursor-default': currentPlace === path.path.length - 1 },
{ 'cursor-pointer hover:scale-105 transition': currentPlace !== path.path.length - 1 }
)}
onClick={() => current < path.path.length - 1 && setCurrent((i) => i + 1)}
onClick={() => currentPlace < path.path.length - 1 && setCurrentPlace((i) => i + 1)}
/>
</div>
)}
Expand All @@ -134,18 +141,18 @@ const PathViewer = (props: PathViewerProps) => {
<div
className='flex flex-col py-16 px-12 gap-16'
>
{ current >= 0 && (
{ currentPlace >= 0 && (
<>
<h2
className='text-3xl'
>
{ path.path[current].place.title }
{ path.path[currentPlace].place.title }
</h2>
<article
className='prose prose-invert max-w-none'
>
<TinaMarkdown
content={path.path[current].blurb}
content={path.path[currentPlace].blurb}
components={{
iframe: IframeEmbed,
media: MediaInsert
Expand All @@ -154,7 +161,7 @@ const PathViewer = (props: PathViewerProps) => {
</article>
</>
)}
{ current < 0 && (
{ currentPlace < 0 && (
<>
<h2
className='text-3xl'
Expand Down Expand Up @@ -184,7 +191,7 @@ const PathViewer = (props: PathViewerProps) => {
rounded-full
px-6
`}
onClick={() => setCurrent(0)}
onClick={(e: any) => { e.preventDefault(); e.stopPropagation(); console.log('click!!!'); setCurrentPlace(0); }}
>
<p>
{ t('startTour') }
Expand Down
3 changes: 3 additions & 0 deletions src/apps/posts/PlaceInsert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { parseFeature } from '@utils/map';
import React, { useMemo } from 'react';

const PlaceInsert = (props: any) => {
if (!props?.place || !props?.place?.uuid) {
return null;
}
const { selected, setSelected } = useSelectionState();

/**
Expand Down
Loading