Skip to content

Commit

Permalink
hacked together the linking between the feedbackbutton and the intera…
Browse files Browse the repository at this point in the history
…ctive map
  • Loading branch information
CommanderStorm committed Oct 8, 2022
1 parent f15618c commit ccaf6ad
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
19 changes: 13 additions & 6 deletions webclient/src/components/DetailsFeedbackButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@ import { useDetailsStore } from "@/stores/details";
import { useGlobalStore } from "@/stores/global";
import { TokenRequest } from "@/codegen";
import FeedbackCategory = TokenRequest.CategoryEnum;
import { defineExpose } from "vue";
import { useI18n } from "vue-i18n";
const { t } = useI18n();
const state = useDetailsStore();
function _getFeedbackSubject(currentEdits) {
if (Object.keys(currentEdits).length > 1) {
return (
`[${state.data.id} et.al.]: ` +
$t("feedback.coordinatepicker.edit_coordinates_subject")
t("feedback.coordinatepicker.edit_coordinates_subject")
);
}
const subjectPrefix = `[${state.data.id}]: `;
const subjectMsg =
Object.keys(currentEdits).length === 0
? ""
: $t("feedback.coordinatepicker.edit_coordinate_subject");
: t("feedback.coordinatepicker.edit_coordinate_subject");
// The subject backup is only loaded (and supported) when a single
// entry is being edited
Expand Down Expand Up @@ -59,14 +62,14 @@ function _getFeedbackBody(currentEdits) {
const defaultActionMsg =
state.data.coords.accuracy === "building"
? $t("feedback.coordinatepicker.add_coordinate")
: $t("feedback.coordinatepicker.correct_coordinate");
? t("feedback.coordinatepicker.add_coordinate")
: t("feedback.coordinatepicker.correct_coordinate");
actionMsg = actionMsg || defaultActionMsg;
if (Object.keys(currentEdits).length > 1) {
// The body backup is discarded if more than a single entry
// is being edited (because then it is not supported).
actionMsg = $t("feedback.coordinatepicker.edit_multiple_coordinates");
actionMsg = t("feedback.coordinatepicker.edit_multiple_coordinates");
}
let editStr = "";
Expand All @@ -76,7 +79,11 @@ function _getFeedbackBody(currentEdits) {
return `${actionMsg}\n\`\`\`\n${editStr}\`\`\``;
}
function openFeedbackForm() {
defineExpose({
openFeedbackForm: openFeedbackForm,
});
function openFeedbackForm(addLocationPicker) {
// The feedback form is opened. This may be prefilled with previously corrected coordinates.
// Maybe get the old coordinates from localstorage
const currentEdits = getLocalStorageWithExpiry("feedback-coords", {});
Expand Down
22 changes: 12 additions & 10 deletions webclient/src/components/DetailsInteractiveMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ type Coord = {
lon: number | undefined;
};
};
const emit = defineEmits(["openFeedbackForm"]);
function confirmLocationPicker() {
// add the current edits to the feedback
const currentEdits = getLocalStorageWithExpiry<{[index: string]: Coord}>("feedback-coords", {});
const currentEdits = getLocalStorageWithExpiry<{ [index: string]: Coord }>(
"feedback-coords",
{}
);
const location = marker2.value?.getLngLat();
currentEdits[state.data!.id] = {
coords: { lat: location?.lat, lon: location?.lng },
Expand All @@ -57,7 +61,7 @@ function confirmLocationPicker() {
state.coord_picker.force_reopen
) {
state.coord_picker.force_reopen = false;
openFeedbackForm();
emit("openFeedbackForm", () => addLocationPicker());
}
// The helptext (which says thet you can edit multiple coordinates in bulk)
Expand All @@ -74,22 +78,20 @@ function cancelLocationPicker() {
if (state.coord_picker.force_reopen) {
state.coord_picker.force_reopen = false;
openFeedbackForm();
emit("openFeedbackForm", () => addLocationPicker());
}
}
// TODO: make this interactive from other components
defineExpose({
addLocationPicker: addLocationPicker,
});
function addLocationPicker() {
// If this is called from the feedback form using the edit coordinate
// button, we temporarily save the current subject and body, so it is
// not lost when being reopened
if (global.feedback.open) {
coord_picker.value.backup_id = state.data!.id;
coord_picker.value.subject_backup = (
document.getElementById("feedback-subject") as HTMLInputElement
).value;
coord_picker.value.body_backup = (
document.getElementById("feedback-body") as HTMLTextAreaElement
).value;
coord_picker.value.subject_backup = global.feedback.subject;
coord_picker.value.body_backup = global.feedback.body;
coord_picker.value.force_reopen = true; // reopen after confirm
global.temprarilyCloseFeedback();
Expand Down
4 changes: 2 additions & 2 deletions webclient/src/views/DetailsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ onMounted(() => {
v-if="state.data.coords.accuracy === 'building'"
>
{{ $t("view_view.msg.inaccurate_only_building.msg") }}
<button class="btn btn-sm" @click="addLocationPicker">
<button class="btn btn-sm" @click="$refs.interactiveMap.addLocationPicker()">
{{ $t("view_view.msg.inaccurate_only_building.btn") }}
</button>
</div>
Expand All @@ -298,7 +298,7 @@ onMounted(() => {
</div>
</div>

<DetailsInteractiveMap ref="interactiveMap" />
<DetailsInteractiveMap ref="interactiveMap" @open-feedback-form="$refs.feedbackButton.openFeedbackForm" />
<DetailsRoomfinderMap ref="roomfinderMap" />
<div class="btn-group btn-group-block">
<button
Expand Down

0 comments on commit ccaf6ad

Please sign in to comment.