Skip to content
Open
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
18 changes: 10 additions & 8 deletions src/models/pathResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,28 +113,30 @@ function getContext(router, options = {}) {
const match = pathname.match(MAP_URL_PATTERN);
const matchV2 = pathname.match(MAP_URL_PATTERNV2);

if (match) {
if (match && match[2]) {
const context = {
name: match[2],
id: match[3],
};
return context;
}

if (matchV2) {
if (matchV2 && matchV2[2]) {
const context = {
name: matchV2[2],
id: matchV2[3],
};
return context;
}

const match2 = pathname.match(/^\/wallets\/([a-z0-9-]+)\/tokens\?.*$/);
const context = {
name: 'wallets',
id: match2[1],
};
return context;
const match2 = pathname.match(/^\/wallets\/([a-z0-9-]+)\/tokens(\?.*)?$/);
if (match2) {
const context = {
name: 'wallets',
id: match2[1],
};
return context;
}

return null;
}
Expand Down
8 changes: 6 additions & 2 deletions src/pages/organizations/[organizationid].js
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,9 @@ export default function Organization(props) {
<Box
component="span"
dangerouslySetInnerHTML={{
__html: marked.parse(organization.about || 'NO DATA YET'),
__html: marked.parse(organization.about || 'NO DATA YET', {
breaks: true,
}),
}}
/>
</Typography>
Expand All @@ -455,7 +457,9 @@ export default function Organization(props) {
letterSpacing: '0.04em',
}}
dangerouslySetInnerHTML={{
__html: marked.parse(organization.mission || 'NO DATA YET'),
__html: marked.parse(organization.mission || 'NO DATA YET', {
breaks: true,
}),
}}
/>
</Typography>
Expand Down
4 changes: 3 additions & 1 deletion src/pages/planters/[planterid].js
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,9 @@ export default function Planter(props) {
>
<span
dangerouslySetInnerHTML={{
__html: marked.parse(planter.about || 'NO DATA YET'),
__html: marked.parse(planter.about || 'NO DATA YET', {
breaks: true,
}),
}}
/>
</Typography>
Expand Down
40 changes: 23 additions & 17 deletions src/pages/tokens/[tokenid].js
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,16 @@ export default function Token(props) {
const mapContext = useMapContext();
const isMobile = useMobile();
const router = useRouter();
const userCameFromWalletPage = router.asPath.includes('wallets');
const userCameFromWalletPage =
router.asPath.includes('wallets') || !!router.query.walletId;
const context = pathResolver.getContext(router, {
base: process.env.NEXT_PUBLIC_BASE,
});

log.warn('map:', mapContext);

useEffect(() => {
let cancelled = false;
async function reload() {
// manipulate the map
// const { map } = mapContext;
Expand Down Expand Up @@ -115,26 +117,29 @@ export default function Token(props) {
// manipulate the map
log.warn('map ,tree, context in tree page:', map, tree, context);
if (map && tree?.lat && tree?.lon) {
if (context && context.name) {
if (context.name === 'wallets') {
log.warn('set wallet filter', context.id);
await map.setFilters({
wallet: wallet.name,
});
await focusTree(map, tree);
const treeDataForMap = {
...tree,
lat: parseFloat(tree.lat.toString()),
lon: parseFloat(tree.lon.toString()),
};
map.selectTree(treeDataForMap);
} else {
throw new Error(`unknown context name: ${context.name}`);
}
const isWalletContext =
(context && context.name === 'wallets') || !!router.query.walletId;
if (isWalletContext && wallet) {
log.warn(
'set wallet filter',
context?.id || router.query.walletId,
);
await map.setFilters({
wallet: wallet.name,
});
await focusTree(map, tree);
if (cancelled) return;
const treeDataForMap = {
...tree,
lat: parseFloat(tree.lat.toString()),
lon: parseFloat(tree.lon.toString()),
};
map.selectTree(treeDataForMap);
} else {
log.warn('set treeid filter', tree.id);
await map.setFilters({});
await focusTree(map, tree);
if (cancelled) return;
const treeDataForMap = {
...tree,
lat: parseFloat(tree.lat.toString()),
Expand All @@ -145,6 +150,7 @@ export default function Token(props) {
}
}
reload();
return () => { cancelled = true; };
}, [mapContext, token]);
log.warn('token:', token);

Expand Down
1 change: 1 addition & 0 deletions src/pages/top.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function Top(props) {
React.useEffect(() => {
async function reload() {
if (mapContext.map) {
await mapContext.map.clearSelection();
await mapContext.map.setFilters({});
const bounds = pathResolver.getBounds(router);
if (bounds) {
Expand Down
14 changes: 5 additions & 9 deletions src/pages/trees/[treeid].js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export default function Tree({
// draw();
// }, [mapContext.map, tree.lat, tree.lon]);
useEffect(() => {
let cancelled = false;
async function reload() {
async function focusTree(map2, tree2) {
const currentView = map2.getCurrentView();
Expand All @@ -131,6 +132,7 @@ export default function Tree({
userid: context.id,
});
await focusTree(map, tree);
if (cancelled) return;
const treeDataForMap = {
...tree,
lat: parseFloat(tree.lat.toString()),
Expand All @@ -143,6 +145,7 @@ export default function Tree({
map_name: organization.map_name,
});
await focusTree(map, tree);
if (cancelled) return;
const treeDataForMap = {
...tree,
lat: parseFloat(tree.lat.toString()),
Expand All @@ -156,25 +159,18 @@ export default function Tree({
log.warn('set treeid filter', tree.id);
await map.setFilters({});
await focusTree(map, tree);
if (cancelled) return;
const treeDataForMap = {
...tree,
lat: parseFloat(tree.lat.toString()),
lon: parseFloat(tree.lon.toString()),
};
map.selectTree(treeDataForMap);
}

// // select the tree
// const treeDataForMap = {
// ...tree,
// lat: parseFloat(tree.lat.toString()),
// lon: parseFloat(tree.lon.toString()),
// };
// mapContext.map.selectTree(treeDataForMap);
// // log.warn('filter of map:', mapContext.map.getFilters());
}
}
reload();
return () => { cancelled = true; };
}, [map, tree.lat, tree.lon]);

log.warn(planter, 'planter');
Expand Down
14 changes: 5 additions & 9 deletions src/pages/v2/captures/[captureid].js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export default function Capture({
// draw();
// }, [mapContext.map, tree.lat, tree.lon]);
useEffect(() => {
let cancelled = false;
async function reload() {
async function focusTree(map2, tree2) {
const currentView = map2.getCurrentView();
Expand All @@ -139,6 +140,7 @@ export default function Capture({
userid: context.id,
});
await focusTree(map, tree);
if (cancelled) return;
const treeDataForMap = {
...tree,
lat: parseFloat(tree.lat.toString()),
Expand All @@ -151,6 +153,7 @@ export default function Capture({
map_name: organization.map_name,
});
await focusTree(map, tree);
if (cancelled) return;
const treeDataForMap = {
...tree,
lat: parseFloat(tree.lat.toString()),
Expand All @@ -164,25 +167,18 @@ export default function Capture({
log.warn('set treeid filter', tree.id);
await map.setFilters({});
await focusTree(map, tree);
if (cancelled) return;
const treeDataForMap = {
...tree,
lat: parseFloat(tree.lat.toString()),
lon: parseFloat(tree.lon.toString()),
};
map.selectTree(treeDataForMap);
}

// // select the tree
// const treeDataForMap = {
// ...tree,
// lat: parseFloat(tree.lat.toString()),
// lon: parseFloat(tree.lon.toString()),
// };
// mapContext.map.selectTree(treeDataForMap);
// // log.warn('filter of map:', mapContext.map.getFilters());
}
}
reload();
return () => { cancelled = true; };
}, [map, tree.lat, tree.lon]);

log.warn(grower, 'grower');
Expand Down
4 changes: 3 additions & 1 deletion src/pages/wallets/[walletid].js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,9 @@ export default function Wallet(props) {
sx={{ mt: [2.5, 5] }}
variant="body2"
dangerouslySetInnerHTML={{
__html: marked.parse(wallet.about || 'NO DATA YET'),
__html: marked.parse(wallet.about || 'NO DATA YET', {
breaks: true,
}),
}}
/>
<Divider
Expand Down