diff --git a/composer.json b/composer.json
index 2ce0718..3d720e5 100644
--- a/composer.json
+++ b/composer.json
@@ -1,7 +1,7 @@
{
"name": "fwdekker/death-notifier",
"description": "Get notified when a famous person dies.",
- "version": "0.11.0", "_comment_version": "Also update version in `package.json`!",
+ "version": "0.11.1", "_comment_version": "Also update version in `package.json`!",
"type": "project",
"license": "MIT",
"homepage": "https://git.fwdekker.com/tools/death-notifier",
diff --git a/composer.lock b/composer.lock
index 1a13e4a..aeb5484 100644
Binary files a/composer.lock and b/composer.lock differ
diff --git a/package-lock.json b/package-lock.json
index ce1b0f3..97ba3cc 100644
Binary files a/package-lock.json and b/package-lock.json differ
diff --git a/package.json b/package.json
index b0da9fa..96bc710 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "death-notifier",
- "version": "0.11.0", "_comment_version": "Also update version in `composer.json`!",
+ "version": "0.11.1", "_comment_version": "Also update version in `composer.json`!",
"description": "Get notified when a famous person dies.",
"author": "Florine W. Dekker",
"browser": "dist/bundle.js",
diff --git a/src/main/js/Main.ts b/src/main/js/Main.ts
index 0d3640d..5fc7561 100644
--- a/src/main/js/Main.ts
+++ b/src/main/js/Main.ts
@@ -1,7 +1,7 @@
// @ts-ignore
const {$, $a, doAfterLoad, footer, header, nav} = window.fwdekker;
-import {csrfToken, emptyFunction, getApi, postApi, sharedMessageElement} from "./API";
+import {csrfToken, emptyFunction, getApi, postApi, ServerResponse, sharedMessageElement} from "./API";
import {CustomEventHandler} from "./CustomEventHandler";
import {clearMessage, clearMessages, showError, showInfo, showSuccess, showWarning} from "./Message";
@@ -552,9 +552,19 @@ doAfterLoad(() => {
person_name: $("#addTrackingPersonName").value,
},
addTrackingForm,
- () => {
+ (response: ServerResponse) => {
addTrackingForm.reset();
refreshTrackings();
+
+ showSuccess(
+ $("#addTrackingFormValidationInfo"),
+ response.payload["renamed"]
+ ? (
+ `Successfully added ${response.payload["input"]} as ` +
+ `${response.payload["name"]}!`
+ )
+ : `Successfully added ${response.payload["name"]}!`
+ );
}
);
});
diff --git a/src/main/php/TrackingManager.php b/src/main/php/TrackingManager.php
index 54ada2f..5b5f470 100644
--- a/src/main/php/TrackingManager.php
+++ b/src/main/php/TrackingManager.php
@@ -95,7 +95,6 @@ class TrackingManager
*/
public function add_tracking(string $user_uuid, string $person_name): Response
{
- // TODO: Add "partially satisfied" response if normalized name is added, to prevent confusion
$info = $this->mediawiki->query_statuses([$person_name]);
$normalized_name = $info->redirects[$person_name];
$status = $info->results[$normalized_name]["status"];
@@ -103,59 +102,64 @@ class TrackingManager
if (in_array($normalized_name, $info->missing))
return Response::unsatisfied(
- "Wikipedia does not have an article about " . htmlentities($person_name) . ".",
+ "Wikipedia does not have an article about " .
+ "" . htmlentities($person_name) . ".",
"person_name"
);
if ($type === ArticleType::Disambiguation)
return Response::unsatisfied(
- "" .
- htmlentities($normalized_name) .
- " refers to multiple articles. " .
- "" .
- "Check Wikipedia" .
- " to see if the right article is listed.",
+ "" .
+ htmlentities($normalized_name) . " refers to multiple articles. " .
+ "Check Wikipedia " .
+ "to see if the right article is listed.",
"person_name"
);
if ($type === ArticleType::Other)
return Response::unsatisfied(
"The Wikipedia article about " .
- "" .
- htmlentities($normalized_name) .
- " is not about a person.",
+ "" .
+ htmlentities($normalized_name) . " is not about a person.",
"person_name"
);
// Insert person and tracking
- return Database::transaction($this->conn, function () use ($user_uuid, $normalized_name, $status) {
- $stmt = $this->conn->prepare("SELECT EXISTS(SELECT 1
- FROM trackings
- WHERE user_uuid=:uuid AND person_name=:name);");
- $stmt->bindValue(":uuid", $user_uuid);
- $stmt->bindValue(":name", $normalized_name);
- $stmt->execute();
- if ($stmt->fetch()[0] === 1)
- return Response::unsatisfied(
- "You are already tracking " . htmlentities($normalized_name) . ".",
- "person_name"
- );
+ return Database::transaction(
+ $this->conn,
+ function () use ($user_uuid, $person_name, $normalized_name, $status) {
+ $stmt = $this->conn->prepare("SELECT EXISTS(SELECT 1
+ FROM trackings
+ WHERE user_uuid=:uuid AND person_name=:name);");
+ $stmt->bindValue(":uuid", $user_uuid);
+ $stmt->bindValue(":name", $normalized_name);
+ $stmt->execute();
+ if ($stmt->fetch()[0] === 1)
+ return Response::unsatisfied(
+ "You are already tracking " . htmlentities($normalized_name) . ".",
+ "person_name"
+ );
- $stmt = $this->conn->prepare("INSERT OR IGNORE INTO people (name) VALUES (:name);");
- $stmt->bindValue(":name", $normalized_name);
- $stmt->execute();
+ $stmt = $this->conn->prepare("INSERT OR IGNORE INTO people (name) VALUES (:name);");
+ $stmt->bindValue(":name", $normalized_name);
+ $stmt->execute();
- $stmt = $this->conn->prepare("UPDATE people SET status=:status WHERE name=:name;");
- $stmt->bindValue(":name", $normalized_name);
- $stmt->bindValue(":status", $status->value);
- $stmt->execute();
+ $stmt = $this->conn->prepare("UPDATE people SET status=:status WHERE name=:name;");
+ $stmt->bindValue(":name", $normalized_name);
+ $stmt->bindValue(":status", $status->value);
+ $stmt->execute();
- $stmt = $this->conn->prepare("INSERT OR IGNORE INTO trackings (user_uuid, person_name)
+ $stmt = $this->conn->prepare("INSERT OR IGNORE INTO trackings (user_uuid, person_name)
VALUES (:user_uuid, :person_name);");
- $stmt->bindValue(":user_uuid", $user_uuid);
- $stmt->bindValue(":person_name", $normalized_name);
- $stmt->execute();
+ $stmt->bindValue(":user_uuid", $user_uuid);
+ $stmt->bindValue(":person_name", $normalized_name);
+ $stmt->execute();
- return Response::satisfied();
- });
+ return Response::satisfied([
+ "name" => $normalized_name,
+ "input" => $person_name,
+ "renamed" => $person_name !== $normalized_name
+ ]);
+ });
}
/**