Allow closing Maproulette tasks

This commit is contained in:
Robin van der Linde 2022-07-13 08:03:09 +00:00 committed by GitHub
parent a1bffc7b7f
commit 65997291bb
12 changed files with 309 additions and 165 deletions

39
Logic/Maproulette.ts Normal file
View file

@ -0,0 +1,39 @@
import Constants from "../Models/Constants";
export default class Maproulette {
/**
* The API endpoint to use
*/
endpoint: string;
/**
* The API key to use for all requests
*/
private apiKey: string;
/**
* Creates a new Maproulette instance
* @param endpoint The API endpoint to use
*/
constructor(endpoint: string = "https://maproulette.org/api/v2") {
this.endpoint = endpoint;
this.apiKey = Constants.MaprouletteApiKey;
}
/**
* Close a task
* @param taskId The task to close
*/
async closeTask(taskId: number): Promise<void> {
const response = await fetch(`${this.endpoint}/task/${taskId}/1`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
"apiKey": this.apiKey,
},
});
if (response.status !== 304) {
console.log(`Failed to close task: ${response.status}`);
}
}
}

View file

@ -13,6 +13,7 @@ import ChangeToElementsActor from "../Actors/ChangeToElementsActor";
import PendingChangesUploader from "../Actors/PendingChangesUploader";
import * as translators from "../../assets/translators.json"
import {post} from "jquery";
import Maproulette from "../Maproulette";
/**
* The part of the state which keeps track of user-related stuff, e.g. the OSM-connection,
@ -34,6 +35,11 @@ export default class UserRelatedState extends ElementsState {
*/
public mangroveIdentity: MangroveIdentity;
/**
* Maproulette connection
*/
public maprouletteConnection: Maproulette;
public readonly isTranslator : Store<boolean>;
public readonly installedUserThemes: Store<string[]>
@ -80,6 +86,8 @@ export default class UserRelatedState extends ElementsState {
this.osmConnection.GetLongPreference("identity", "mangrove")
);
this.maprouletteConnection = new Maproulette();
if (layoutToUse?.hideFromOverview) {
this.osmConnection.isLoggedIn.addCallbackAndRunD(loggedIn => {
if (loggedIn) {