Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/read new markdown fields #624

Merged
merged 3 commits into from
Jan 21, 2025
Merged
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
7 changes: 6 additions & 1 deletion package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"jest-transform-graphql": "^2.1.0",
"lodash": "^4.17.20",
"maplibre-gl": "^1.15.3",
"marked": "^4.3.0",
"moment": "^2.29.4",
"nanoid": "^3.3.4",
"rbush-knn": "^3.0.1",
Expand Down
1 change: 0 additions & 1 deletion src/app/services/createReach.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export async function createReach(data) {
class
county
description
gaugeinfo
geom
id
length
Expand Down
75 changes: 44 additions & 31 deletions src/app/services/getRapids.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,53 @@
import http from "@/app/http"
import { marked } from 'marked';

export async function getRapids(id) {
return http
.post('graphql', {
query: `
query {
reach(id: ${id}) {
pois {
approximate
character
description
difficulty
distance
id
name
rloc
photo {
poi_name
subject
description
author
caption
photo_date
image {
uri {
thumb
medium
big
}
}
id
}
}
}
query {
reach(id: ${id}) {
pois {
approximate
character
description_md
difficulty
distance
id
name
rloc
photo {
poi_name
subject
description
author
caption
photo_date
image {
uri {
thumb
medium
big
}
`
}
id
}
}
}
}
`
})
.then(res => {
// overwrite `description` with a parsed version of the markdown database field
// this allows us to read and render the markdown field while leaving the edit/update
// code unchanged
// TODO: move fully to the _md fields, including with a new editor
if (!res.data.errors) {
res.data.data.reach.pois.forEach((poi) => {
poi.description = marked.parse(poi.description_md);
});

}
return res.data;
})
.then(res => res.data)
}
15 changes: 12 additions & 3 deletions src/app/services/getReach.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import http from "@/app/http";
import { marked } from 'marked';

export async function getReach(id) {
return http
Expand All @@ -11,9 +12,8 @@ export async function getReach(id) {
permitinfo
id
class
description
description_md
edited
gaugeinfo
length
maxgradient
plat
Expand Down Expand Up @@ -59,5 +59,14 @@ export async function getReach(id) {

`,
})
.then((res) => res.data);
.then((res) => {
if (!res.data.errors) {
// overwrite `description` with a parsed version of the markdown database field
// this allows us to read and render the markdown field while leaving the edit/update
// code unchanged
// TODO: move fully to the _md fields, including with a new editor
res.data.data.reach.description = marked.parse(res.data.data.reach.description_md)
}
return res.data;
});
}
16 changes: 14 additions & 2 deletions src/app/services/getReachAlerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export async function getReachAlerts(id) {
data {
id
title
detail
detail_md
post_date
revision
post_type
Expand All @@ -34,5 +34,17 @@ export async function getReachAlerts(id) {
}
}`
})
.then(res => res.data)
.then(res => {
if (!res.data.errors) {
// NOTE: we are *not* processing the _md field here because alerts are, in practice, plain text,
// and converting the field back from markdown to HTML adds <p> tags, but in the interest of
// parity with mobile app, we still want to read the _md field
// TODO: remodel alerts as separate from other post types
res.data.data.posts.data.forEach((report) => {
report.detail = report.detail_md;
});
}

return res.data;
})
}
17 changes: 15 additions & 2 deletions src/app/services/getReachGallery.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import http from "@/app/http"
import { marked } from 'marked';

export async function getReachGallery(id, pagination) {
return http
Expand All @@ -15,7 +16,7 @@ export async function getReachGallery(id, pagination) {
id
author
caption
description
description_md
photo_date
poi_name
poi_id
Expand Down Expand Up @@ -61,5 +62,17 @@ export async function getReachGallery(id, pagination) {
}
}`
})
.then(res => res.data)
.then(res => {
if (!res.data.errors) {
// overwrite `description` with a parsed version of the markdown database field
// this allows us to read and render the markdown field while leaving the edit/update
// code unchanged
// TODO: move fully to the _md fields, including with a new editor
res.data.data.reach.photos.data.forEach((photo) => {
photo.description = marked.parse(photo.description_md);
});
}

return res.data;
})
}
26 changes: 0 additions & 26 deletions src/app/services/getReachMap.js

This file was deleted.

18 changes: 16 additions & 2 deletions src/app/services/getReachReports.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import http from "@/app/http"
import { marked } from 'marked';

export async function getReachReports(id, pagination) {

Expand All @@ -14,7 +15,7 @@ export async function getReachReports(id, pagination) {
orderBy: {field: POST_DATE, order: DESC}
) {
data {
detail
detail_md
id
title
reading
Expand Down Expand Up @@ -62,5 +63,18 @@ export async function getReachReports(id, pagination) {
}
`
})
.then(res => res.data)
.then(res => {
if (!res.data.errors) {
// overwrite `detail` with a parsed version of the markdown database field
// this allows us to read and render the markdown field while leaving the edit/update
// code unchanged
// TODO: move fully to the _md fields, including with a new editor
res.data.data.posts.data.forEach((report) => {
report.detail = marked.parse(report.detail_md);
});
}

return res.data;
})

}
12 changes: 10 additions & 2 deletions src/app/services/getReport.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import http from "@/app/http"
import { marked } from 'marked';

export async function getReport(id) {

Expand All @@ -11,7 +12,7 @@ export async function getReport(id) {
id: "${id}"
) {
data {
detail
detail_md
id
title
reading
Expand Down Expand Up @@ -68,5 +69,12 @@ export async function getReport(id) {
}
`
})
.then(res => res.data.data.posts.data[0])
.then(res => {
const post = res.data.data.posts.data[0];
if (post) {
post.detail = marked.parse(post.detail_md);
}

return post;
})
}
1 change: 0 additions & 1 deletion src/app/services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export * from "./getReachDocuments";
export * from "./getReachGages";
export * from "./getReachGallery";
export * from "./getReachGalleryIndex";
export * from "./getReachMap";
export * from "./getReachNews";
export * from "./getReachProjects";
export * from "./getReport";
Expand Down
30 changes: 0 additions & 30 deletions src/app/store/modules/river-map.js

This file was deleted.

1 change: 0 additions & 1 deletion src/app/views/river-detail/river-creator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ export default {
class: "none",
county: null,
description: null,
gaugeinfo: null,
geom: null,
length: null,
permitinfo: null,
Expand Down
Loading