From 12b9daec80b94be0895d80f4e81fa452efdd3e75 Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Sun, 12 Dec 2021 01:28:31 +0000 Subject: [PATCH] Add user deletability as a thing. --- client/package.json | 2 +- client/pnpm-lock.yaml | 8 ++-- .../dashboard/users/UserSettingsPage.tsx | 14 ++++++ .../tables/dropdowns/GenericScoreDropdown.tsx | 13 +++++- .../dropdowns/components/ManageScore.tsx | 45 +++++++++++++++++++ 5 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 client/src/components/tables/dropdowns/components/ManageScore.tsx diff --git a/client/package.json b/client/package.json index f191f66ff..a119078a6 100644 --- a/client/package.json +++ b/client/package.json @@ -82,7 +82,7 @@ "resolve": "1.12.0", "resolve-url-loader": "3.1.0", "socicon": "3.0.5", - "tachi-common": "0.3.10" + "tachi-common": "0.3.18" }, "devDependencies": { "@types/humanize-duration": "3.25.1", diff --git a/client/pnpm-lock.yaml b/client/pnpm-lock.yaml index 4a9356f88..73a9297ee 100644 --- a/client/pnpm-lock.yaml +++ b/client/pnpm-lock.yaml @@ -84,7 +84,7 @@ specifiers: serve: 11.2.0 socicon: 3.0.5 style-loader: 1.0.0 - tachi-common: 0.3.10 + tachi-common: 0.3.18 terser-webpack-plugin: 1.4.1 ts-pnp: 1.1.4 typescript: 4.3.5 @@ -156,7 +156,7 @@ dependencies: resolve: 1.12.0 resolve-url-loader: 3.1.0 socicon: 3.0.5 - tachi-common: 0.3.10 + tachi-common: 0.3.18 devDependencies: '@types/humanize-duration': 3.25.1 @@ -11241,8 +11241,8 @@ packages: strip-ansi: 6.0.0 dev: true - /tachi-common/0.3.10: - resolution: {integrity: sha512-OiEnRz8b7ix+m/W5bFwaN+0fgupmbYHKhsn4/IaFb8f2rCEHY/i3t8TGuYAx212Uo2hOsDSX5/yxVOrgcxZ1AA==} + /tachi-common/0.3.18: + resolution: {integrity: sha512-Qom4IbPtLv83+6mW2OU3+thdqZIGrcUJaH9vhTWN6FoFTw60l0FjtBGsB7343qwsuK7l9JqcEaEJ/psKTDZb1w==} dependencies: monk: 7.3.4 transitivePeerDependencies: diff --git a/client/src/app/pages/dashboard/users/UserSettingsPage.tsx b/client/src/app/pages/dashboard/users/UserSettingsPage.tsx index 2ca2bcb98..768da0ad4 100644 --- a/client/src/app/pages/dashboard/users/UserSettingsPage.tsx +++ b/client/src/app/pages/dashboard/users/UserSettingsPage.tsx @@ -172,6 +172,7 @@ function PreferencesForm({ reqUser }: { reqUser: PublicUserDocument }) { invisible: settings?.preferences.invisible ?? false, contentiousContent: settings?.preferences.contentiousContent ?? false, advancedMode: settings?.preferences.advancedMode ?? false, + deletableScores: settings?.preferences.deletableScores ?? false, }, onSubmit: async values => { const res = await APIFetchV1( @@ -224,6 +225,19 @@ function PreferencesForm({ reqUser }: { reqUser: PublicUserDocument }) { /> Hide your last seen status. */} + + + + Enables the option to delete scores. Turn this off if the thought of deleting a + score gives you anxiety. + + ({ user: PublicUserDocument; chart: ChartDocument; scoreState: ScoreState; - defaultView?: "vsPB" | "moreInfo" | "history" | "debug"; + defaultView?: "vsPB" | "moreInfo" | "history" | "debug" | "manage"; thisScore: ScoreDocument; DocComponent?: (props: { score: ScoreDocument | PBScoreDocument; @@ -55,6 +56,8 @@ export default function GenericScoreDropdown({ }) => JSX.Element; } & GamePT) { const [view, setView] = useState(defaultView); + const { user: currentUser } = useContext(UserContext); + const { settings } = useContext(UserSettingsContext); const { isLoading, error, data } = useApiQuery>( `/users/${user.id}/games/${game}/${playtype}/pbs/${chart.chartID}?getComposition=true` @@ -94,6 +97,8 @@ export default function GenericScoreDropdown({ body = ; } else if (view === "vsPB") { body = ; + } else if (view === "manage") { + body = ; } return ( @@ -112,6 +117,12 @@ export default function GenericScoreDropdown({ Play History + {currentUser?.id === user.id && settings?.preferences.deletableScores && ( + + + Manage Score + + )} diff --git a/client/src/components/tables/dropdowns/components/ManageScore.tsx b/client/src/components/tables/dropdowns/components/ManageScore.tsx new file mode 100644 index 000000000..c1271743d --- /dev/null +++ b/client/src/components/tables/dropdowns/components/ManageScore.tsx @@ -0,0 +1,45 @@ +import React, { useMemo, useReducer, useState } from "react"; +import { ScoreDocument } from "tachi-common"; +import { APIFetchV1 } from "util/api"; +import { DelayedPageReload } from "util/misc"; + +export default function ManageScore({ score }: { score: ScoreDocument }) { + const [warn, upgWarn] = useReducer(r => r + 1, 0); + const message = useMemo(() => { + if (warn === 0) { + return "Delete Score (Requires Further Confirmation)"; + } else if (warn === 1) { + return "Are you absolutely sure? This score will be gone. Permanently."; + } else if (warn === 2) { + return "I'm serious. You will lose this score. It will be gone. Are you REALLY sure you want to do this?"; + } else if (warn === 3) { + return "OK. Click me one last time, then."; + } + + return "lol unknown state"; + }, [warn]); + + return ( +
+
{ + if (warn < 3) { + upgWarn(); + } else { + APIFetchV1( + `/scores/${score.scoreID}`, + { + method: "DELETE", + }, + true, + true + ).then(() => DelayedPageReload()); + } + }} + > + {message} +
+
+ ); +}