Skip to content

Commit

Permalink
Remove obsolete autosave draft feature (#263)
Browse files Browse the repository at this point in the history
SweClockers just [announced] the addition of a native autosave draft feature inspired by the one in BSC! Unlike our feature, [it's server-side][server] (an improvement if anything) and [loads autosaved drafts automatically][automatically] (seems like an improvement), but just like us, [it autosaves every three seconds][seconds] and [doesn't save very short drafts][short].

We probably won't be able to force the draft to be cleared when a user with the `prevent_accidental_unload` preference enabled confirms that they do want to navigate away from a not-yet-finished post, but not much we can do about that. The prevent accidental unload feature isn't going anywhere; in my opinion, a confirmation dialog is a great UX improvement over the all-but-guaranteed heart attack that an accidental unload usually causes.

Also, from now on, we won't be hard-wrapping commit messages at 72 characters anymore.

[announced]: https://www.sweclockers.com/artikel/38846-sweclockers-far-efterlangtade-forumfunktioner
[server]: https://www.sweclockers.com/forum/post/20472342
[automatically]: https://www.sweclockers.com/forum/post/20471829
[seconds]: https://www.sweclockers.com/forum/post/20471829
[short]: https://www.sweclockers.com/forum/post/20472044
  • Loading branch information
SimonAlling authored May 20, 2024
1 parent 7df2ab9 commit ec53f73
Show file tree
Hide file tree
Showing 10 changed files with 0 additions and 288 deletions.
3 changes: 0 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export const CLASS = {
quoteSignatureButton: c("quote-signature-button"),
mentionEveryoneButton: c("mention-everyone-button"),
shibe: c("shibe"),
button_restoreDraft: c("button-restore-draft"),
button_color: c("button-color"),
button_blockquote: c("button-blockquote"),
button_spoiler: c("button-spoiler"),
Expand Down Expand Up @@ -86,9 +85,7 @@ export const PATH = {
} as const;

export const KEY = {
autosaved_draft: i("autosaved_draft"),
caret_position: i("caret_position_in_textarea"),
last_time_user_tried_to_submit: i("last_time_user_tried_to_submit"),
developer_tools_open: i("developer_tools_open"),
draft_mode: i("draft_mode"),
} as const;
Expand Down
2 changes: 0 additions & 2 deletions src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ export const isInEditMode_marketContact = pathMatches(SITE.PATH.EDIT_MODE_MARKET
export const isInEditMode_PM = pathMatches(SITE.PATH.EDIT_MODE_PM);
export const isInEditMode_report = pathMatches(SITE.PATH.EDIT_MODE_REPORT);
export const isInEditMode_signature = pathMatches(SITE.PATH.EDIT_MODE_SIGNATURE);
export const mayHaveJustSubmittedForumPost = pathMatches(SITE.PATH.SUCCESSFULLY_SUBMITTED_FORUM_POST);
export const mayHaveJustSubmittedPM = pathMatches(SITE.PATH.SUCCESSFULLY_SUBMITTED_PM);

export const isInEditMode = [
isInEditMode_forum,
Expand Down
24 changes: 0 additions & 24 deletions src/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ import {
isReadingEditorialContent,
isReadingForumThread,
isReadingThread,
mayHaveJustSubmittedForumPost,
mayHaveJustSubmittedPM,
} from "~src/environment";
import { P, Preferences } from "~src/preferences";
import SELECTOR from "~src/selectors";
import * as SITE from "~src/site";

import * as autosaveDraft from "./operations/autosave-draft";
import manageCaretPosition from "./operations/caret-position";
import insertDraftModeToggle from "./operations/draft-mode-toggle";
import insertEditingTools from "./operations/editing-tools";
Expand Down Expand Up @@ -280,27 +277,6 @@ const OPERATIONS: readonly Operation<any>[] = [
},
action: insertDraftModeToggle,
}),
operation({
description: "enable autosave draft watchdog",
condition: () => (isInEditMode_forum || isInEditMode_PM) && Preferences.get(P.edit_mode._.autosave_draft),
dependencies: {
saveButton: SELECTOR.saveButton,
textarea: SELECTOR.textarea,
toolbarInner: SELECTOR.textareaToolbarInner,
},
action: autosaveDraft.manageAutosaveWatchdog(undoSupport),
}),
operation({
description: "delete any obsolete autosaved draft",
condition: () => (mayHaveJustSubmittedForumPost || mayHaveJustSubmittedPM) && Preferences.get(P.edit_mode._.autosave_draft),
dependencies: { post: SELECTOR.linkedForumPost },
action: autosaveDraft.clearAutosavedDraftIfObsolete,
}),
operation({
description: "delete any leftover autosaved draft",
condition: () => false === Preferences.get(P.edit_mode._.autosave_draft),
action: autosaveDraft.clearAutosavedDraft,
}),

// Keyboard shortcuts
operation({
Expand Down
190 changes: 0 additions & 190 deletions src/operations/autosave-draft.ts

This file was deleted.

11 changes: 0 additions & 11 deletions src/operations/edit-mode.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
import * as SITE from "~src/site";

// Examples include `@Alling: `, `@Alling:` and `@"---": `.
const REGEX_POSSIBLY_CLEAN_SLATE_REPLY = /^@("?)([^"]+)\1: ?$/;

// Examples include `@Alling: `, `@Alling:` and `@"Better SweClockers": `.
export function isCleanSlate_reply(text: string): boolean {
const match = text.match(REGEX_POSSIBLY_CLEAN_SLATE_REPLY);
return match === null ? false : SITE.isValidUsername(match[2]);
}

export function mention(username: string): string {
// It's non-trivial to write a sound and complete predicate that decides whether a username needs quotes or not.
// One complicating factor is that some disallowed usernames have been allowed before (e.g. "simon.alling").
Expand Down
6 changes: 0 additions & 6 deletions src/preferences/edit-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ const DEFAULT_TEXTAREA_SIZE = 360;
const SPACE = " ", TAB = "\t";

export default {
autosave_draft: new BooleanPreference({
key: "autosave_draft",
default: true,
label: T.preferences.edit_mode.autosave_draft,
description: T.preferences.edit_mode.autosave_draft_description,
}),
draft_mode_toggle: new BooleanPreference({
key: "draft_mode_toggle",
default: true,
Expand Down
16 changes: 0 additions & 16 deletions src/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,8 @@ export const PATH = {
PROFILE: (userId: number | "\\d+") => new RegExp(`^/medlem/${userId}$`),
THREAD: /^\/(?:forum|medlem\/\d+\/meddelanden)\/trad\//,
POST: /^\/(?:forum|medlem\/\d+\/meddelanden)\/post\//,
SUCCESSFULLY_SUBMITTED_FORUM_POST: /^\/forum\/post\/\d+$/,
SUCCESSFULLY_SUBMITTED_PM: /^\/medlem\/\d+\/meddelanden\/(?:post\/\d+(?:#preview)?|trad\/\d+-.+)$/,
newPrivateMessage: (sender: number) => `/medlem/${sender}/meddelanden/nytt-meddelande`,
forumPost: (postID: string) => `/forum/post/${postID}`,
editPost: (postID: number) => `/forum/post/${postID}/redigera`,
} as const;

export const TAG = {
Expand Down Expand Up @@ -181,16 +178,3 @@ export function getUserInfo(): UserInfo {
: { tag: "LoggedIn", userID }
);
}

export function isValidUsername(s: string): boolean {
// https://www.sweclockers.com/konto/registrera
// "Namnet kan innehålla 3–32 tecken: bokstäver, siffror, mellanslag samt binde- och understreck."
// My experiments show that e.g. Å and ß are valid characters, and that the name cannot start or end with " ", "-" or "_".
// That a username is "valid" does not necessarily mean that it can be used for registering a _new_ account, only that it might be in use by someone.
// For example, "." is forbidden, but has been allowed earlier: https://www.sweclockers.com/medlem/197838
// So has '"': https://www.sweclockers.com/medlem/26129
// Weird Unicode intervals are \u00C0-\u00FF with × and ÷ excluded.
// Regex matches "Alling ", "Alling-" and "Alling_", so the reverse of the string must also be checked.
const REGEX_ALMOST_USERNAME = /^(?![ \-_"])[\w\d \-.\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF]{3,32}$/;
return REGEX_ALMOST_USERNAME.test(s) && REGEX_ALMOST_USERNAME.test(s.split("").reverse().join(""));
}
5 changes: 0 additions & 5 deletions src/stylesheets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import * as SITE from "~src/site";
import { hideByClass, hideById, hideBySelector } from "~src/stylesheets/hide";
import { timeIsWithin } from "~src/time";

import autosaveDraft from "./stylesheets/autosave-draft.scss";
import developerMode from "./stylesheets/developer-mode.scss";
import doge from "./stylesheets/doge.scss";
import downForMaintenance from "./stylesheets/down-for-maintenance.scss";
Expand Down Expand Up @@ -102,10 +101,6 @@ const STYLESHEETS = {
condition: () => isInEditMode && Preferences.get(P.edit_mode._.textarea_size_toggle),
css: `#${CONFIG.ID.document} ${SELECTOR.textarea} { height: ${Preferences.get(P.edit_mode._.textarea_size)}px; }`,
}),
autosave_draft: stylesheet({
condition: () => isInEditMode && Preferences.get(P.edit_mode._.autosave_draft),
css: autosaveDraft,
}),
improved_image_controls: stylesheet({
condition: () => Preferences.get(P.advanced._.improved_image_controls),
css: improvedImageControls,
Expand Down
25 changes: 0 additions & 25 deletions src/stylesheets/autosave-draft.scss

This file was deleted.

6 changes: 0 additions & 6 deletions src/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ export const general = {
draft_mode_enabled_tooltip: `Kryssa ur "${draft_mode_toggle_label}" för att posta`,
improved_url_button_url: `Adress (URL):`,
improved_url_button_text: `Länktext:`,
restore_draft_label: `Återställ`,
restore_draft_tooltip: `Återställ autosparat utkast`,
restore_draft_question: `Vill du återställa följande utkast?`,
restore_draft_confirm: `Din nuvarande text kommer ersättas. Är du säker?`,
nbsps_confirm: (n: number) => `${n} mellanslag kommer ersättas med hårda mellanslag. Är du säker?`,
generic_lines_confirm: (n: number) => `${n} markerad${n > 1 ? "e rader" : " rad"} kommer formateras. Är du säker?`,
quote_signature_label: `Citera med sign.`,
Expand Down Expand Up @@ -94,8 +90,6 @@ export const preferences = {

edit_mode: {
label: `Redigeringsläge`,
autosave_draft: `Spara utkast automatiskt`,
autosave_draft_description: `Skydda dina inlägg mot blåskärmar, strömavbrott och andra missöden`,
draft_mode_toggle: `Kryssrutan <em>${draft_mode_toggle_label}</em>`,
draft_mode_toggle_description: draft_mode_description,
textarea_size_save: `Kom ihåg textrutans storlek`,
Expand Down

0 comments on commit ec53f73

Please sign in to comment.