Skip to content

Commit

Permalink
feat(ltFileDetails): save all
Browse files Browse the repository at this point in the history
  • Loading branch information
simon04 committed Aug 9, 2024
1 parent 3ddf346 commit 05fe70e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
5 changes: 2 additions & 3 deletions app/api/ltDataAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ export function getUserInfo() {
}).json();
}

export function editLocation(title: CommonsFile, coordinates: LatLng) {
export function editLocation(title: CommonsFile, coordinates: LatLng[]) {
const {pageid} = title;
const {type, lat, lng} = coordinates;
return useFetch<EditApiResponse>(
'/edit',
{
Expand All @@ -32,7 +31,7 @@ export function editLocation(title: CommonsFile, coordinates: LatLng) {
'Content-Type': 'application/json',
'X-XSRF-TOKEN': xsrfToken() || ''
},
body: JSON.stringify({type, lat, lng, pageid})
body: JSON.stringify(coordinates.map(({type, lat, lng}) => ({type, lat, lng, pageid})))
},
{
afterFetch(ctx) {
Expand Down
40 changes: 31 additions & 9 deletions app/components/ltFileDetails.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<template>
<div class="card">
<button
class="btn btn-success form-control"
type="button"
:disabled="!(file.coordinates?.isChanged || file.objectLocation?.isChanged)"
@click="editLocation()"
>
<svg class="octicon">
<use xlink:href="#git-commit"></use>
</svg>
{{ t('Save') }}
</button>
<div class="card mt-2">
<div class="card-body p-2">
<div>
<label @click="collapseCameraLocation = !collapseCameraLocation">
Expand Down Expand Up @@ -117,17 +128,28 @@ const msgErrorStatusText = computed(() =>
watch(props.file.coordinates, (c1, c2) => console.log(c1, c2));
function editLocation(coordinates: LatLng) {
function editLocation(coordinates: LatLng[]) {
error.value = undefined;
if (coordinates === undefined) {
coordinates = [];
if (props.file?.coordinates?.isChanged) {
coordinates.push(props.file.coordinates);
}
if (props.file?.objectLocation?.isChanged) {
coordinates.push(props.file.objectLocation);
}
}
return ltDataAuth.editLocation(props.file, coordinates).then(
() => {
if (coordinates.type === 'Location') {
// eslint-disable-next-line vue/no-mutating-props
props.file.coordinates = coordinates.commit();
} else if (coordinates.type === 'Object location') {
// eslint-disable-next-line vue/no-mutating-props
props.file.objectLocation = coordinates.commit();
}
coordinates.forEach(c => {
if (c.type === 'Location') {
// eslint-disable-next-line vue/no-mutating-props
props.file.coordinates = c.commit();
} else if (c.type === 'Object location') {
// eslint-disable-next-line vue/no-mutating-props
props.file.objectLocation = c.commit();
}
});
},
e => {
error.value = e;
Expand Down
4 changes: 2 additions & 2 deletions app/components/ltLocationInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"
/>
<button
class="btn btn-secondary"
class="btn btn-outline-secondary"
type="button"
:title="t('Discard')"
@click="modelValue && emit('update:modelValue', modelValue.rollback())"
Expand All @@ -22,7 +22,7 @@
</svg>
</button>
<button
class="btn btn-success"
class="btn btn-outline-success"
type="button"
:title="t('Save')"
:disabled="!modelValue?.isChanged"
Expand Down
10 changes: 9 additions & 1 deletion backend/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import logging
import os
import typing

from flask import Flask, abort, jsonify, request
from flask_mwoauth import MWOAuth
Expand Down Expand Up @@ -49,12 +50,19 @@ def user():
return r


class EditRequest(typing.TypedDict):
type: typing.Literal["Location", "Object location"]
lat: int
lng: int
pageid: int


@app.route("/edit", methods=["POST"])
def edit():
if not mwoauth.get_current_user():
abort(401)

data = request.get_json()
data: list[EditRequest] = request.get_json()
if (
"pageid" not in data
or "type" not in data
Expand Down

0 comments on commit 05fe70e

Please sign in to comment.