Sharing settings and public profile pages (phase 1, step 5)
- sharing.html: switch sharing on/off, see the handle (with the "permanent once followed" warning and a note that following comes later), choose who sees posts (followers only by default; help text on why approval matters), follower approval, directory and search opt-ins, display name and bio; save status shown by the button - profile.html?u=<name>: the public page browsers land on from an actor URL: name, handle (with copy), bio and how to follow; never asks the visitor to sign in - "Sharing" appears in the nav only when the server federates (remembered per tab) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
This commit is contained in:
1 parent
0b10469514
commit
c0b9e85519
6 files changed
+361
No files matched your search
@@ -844,3 +844,104 @@ input {
|
||||
transition: width 0.4s ease-out;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- Sharing & profile ---------------------------------------------------- */
|
||||
.sharing {
|
||||
max-width: 44rem;
|
||||
}
|
||||
|
||||
.share-switch {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
font-size: var(--step-1);
|
||||
font-weight: 650;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.share-switch input {
|
||||
width: 1.4rem;
|
||||
height: 1.4rem;
|
||||
accent-color: var(--ok);
|
||||
}
|
||||
|
||||
.handle-panel {
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.handle {
|
||||
font-size: clamp(1.1rem, 4vw, var(--step-2));
|
||||
margin: 0.4rem 0 0.75rem;
|
||||
}
|
||||
|
||||
.handle-panel .notice {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.choices {
|
||||
border: 0;
|
||||
border-top: 1px solid var(--rule);
|
||||
margin: 0 0 1.5rem;
|
||||
padding: 1.25rem 0 0;
|
||||
min-inline-size: 0;
|
||||
}
|
||||
|
||||
.choices legend {
|
||||
font-weight: 650;
|
||||
font-size: var(--step-1);
|
||||
padding: 0 0.5rem 0 0;
|
||||
}
|
||||
|
||||
.choice {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 0.9rem;
|
||||
}
|
||||
|
||||
.choice input {
|
||||
margin-top: 0.3rem;
|
||||
accent-color: var(--ink);
|
||||
}
|
||||
|
||||
.choice label {
|
||||
display: grid;
|
||||
gap: 0.1rem;
|
||||
}
|
||||
|
||||
.choice label .muted {
|
||||
font-size: var(--step--1);
|
||||
}
|
||||
|
||||
.choices .hint {
|
||||
color: var(--ink-soft);
|
||||
font-size: var(--step--1);
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.field textarea {
|
||||
min-height: 5rem;
|
||||
padding: 0.5rem 0.75rem;
|
||||
border: 1px solid var(--rule);
|
||||
border-radius: var(--radius-control);
|
||||
background: var(--paper-raised);
|
||||
font: inherit;
|
||||
color: inherit;
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
.field textarea:focus-visible {
|
||||
border-color: var(--focus);
|
||||
}
|
||||
|
||||
.profile-bio {
|
||||
white-space: pre-line;
|
||||
}
|
||||
|
||||
.profile-follow {
|
||||
margin: 2rem 0 0.4rem;
|
||||
}
|
||||
|
||||
.save-row {
|
||||
align-items: center;
|
||||
}
|
||||
@@ -20,6 +20,7 @@ export async function signedInPage(active) {
|
||||
const header = document.getElementById("site-header");
|
||||
replace(header, brand(), nav(active));
|
||||
const user = await api("/auth/me");
|
||||
addSharingLink(header.querySelector("nav ul"), active);
|
||||
header.append(
|
||||
h(
|
||||
"div",
|
||||
@@ -61,3 +62,35 @@ async function signOut() {
|
||||
location.href = "login.html";
|
||||
}
|
||||
}
|
||||
|
||||
// "Sharing" only appears when the server federates. Remembered per tab.
|
||||
const FEDERATION_KEY = "scrobbler.federation";
|
||||
|
||||
async function federationAvailable() {
|
||||
try {
|
||||
const cached = sessionStorage.getItem(FEDERATION_KEY);
|
||||
if (cached !== null) return cached === "1";
|
||||
} catch {
|
||||
// Storage unavailable: just ask.
|
||||
}
|
||||
let available = false;
|
||||
try {
|
||||
await api("/federation/settings");
|
||||
available = true;
|
||||
} catch {
|
||||
available = false;
|
||||
}
|
||||
try {
|
||||
sessionStorage.setItem(FEDERATION_KEY, available ? "1" : "0");
|
||||
} catch {
|
||||
// Not remembered; asked again next page.
|
||||
}
|
||||
return available;
|
||||
}
|
||||
|
||||
async function addSharingLink(list, active) {
|
||||
if (!list || !(await federationAvailable())) return;
|
||||
const href = "sharing.html";
|
||||
list.append(h("li", {}, h("a", { href, "aria-current": href === active ? "page" : false }, "Sharing")));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import { api } from "./api.js";
|
||||
import { errorBox, h, replace } from "./dom.js";
|
||||
import { publicPage } from "./layout.js";
|
||||
|
||||
const root = document.getElementById("profile");
|
||||
const username = new URLSearchParams(location.search).get("u") ?? "";
|
||||
|
||||
// A public page: never sends visitors to sign in.
|
||||
publicPage();
|
||||
|
||||
try {
|
||||
const profile = await api(`/federation/profiles/${encodeURIComponent(username)}`, { auth: false });
|
||||
document.title = `${profile.display_name} · Scrobbler`;
|
||||
const copy = h("button", { type: "button", class: "button button-quiet" }, "Copy handle");
|
||||
copy.addEventListener("click", async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(profile.handle);
|
||||
copy.textContent = "Copied";
|
||||
} catch {
|
||||
copy.textContent = "Select and copy it above";
|
||||
}
|
||||
});
|
||||
replace(
|
||||
root,
|
||||
h("h1", {}, profile.display_name),
|
||||
h("div", { class: "approve-app handle" }, profile.handle),
|
||||
profile.bio ? h("p", { class: "lede profile-bio" }, profile.bio) : null,
|
||||
h("h2", { class: "profile-follow" }, "Follow from the fediverse"),
|
||||
h(
|
||||
"p",
|
||||
{ class: "muted" },
|
||||
"Search for the handle above in Mastodon or any other fediverse app, then follow.",
|
||||
),
|
||||
h("div", { class: "button-row" }, copy),
|
||||
);
|
||||
} catch (error) {
|
||||
replace(
|
||||
root,
|
||||
error.status === 404
|
||||
? [h("h1", {}, "No profile here"), h("p", { class: "lede" }, "No one on this server shares their listening under that name.")]
|
||||
: errorBox(error.message),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import { api, describeError } from "./api.js";
|
||||
import { errorBox, h, replace } from "./dom.js";
|
||||
import { signedInPage } from "./layout.js";
|
||||
|
||||
const form = document.getElementById("sharing");
|
||||
const messages = document.getElementById("messages");
|
||||
const handlePanel = document.getElementById("handle-panel");
|
||||
const FIELDS = ["enabled", "visibility", "manually_approves_followers", "discoverable", "indexable", "display_name", "bio"];
|
||||
|
||||
await signedInPage("sharing.html");
|
||||
|
||||
let settings;
|
||||
try {
|
||||
settings = await api("/federation/settings");
|
||||
} catch (error) {
|
||||
replace(
|
||||
messages,
|
||||
error.status === 404
|
||||
? h("p", { class: "notice" }, "This server doesn't share to the fediverse. Ask whoever runs it to turn it on.")
|
||||
: errorBox(error.message),
|
||||
);
|
||||
}
|
||||
|
||||
if (settings) {
|
||||
fill(settings);
|
||||
form.hidden = false;
|
||||
form.elements.enabled.addEventListener("change", () => showHandle(form.elements.enabled.checked));
|
||||
form.addEventListener("submit", save);
|
||||
}
|
||||
|
||||
function fill(values) {
|
||||
for (const name of FIELDS) {
|
||||
const field = form.elements[name];
|
||||
if (name === "visibility") {
|
||||
form.querySelector(`input[name=visibility][value="${values.visibility}"]`).checked = true;
|
||||
} else if (field.type === "checkbox") {
|
||||
field.checked = Boolean(values[name]);
|
||||
} else {
|
||||
field.value = values[name] ?? "";
|
||||
}
|
||||
}
|
||||
document.getElementById("handle").textContent = values.handle;
|
||||
replace(
|
||||
document.getElementById("profile-link"),
|
||||
"Your public profile page: ",
|
||||
h("a", { href: values.profile_url }, values.profile_url.replace(/^https?:\/\//, "")),
|
||||
);
|
||||
showHandle(values.enabled);
|
||||
}
|
||||
|
||||
function showHandle(on) {
|
||||
handlePanel.hidden = !on;
|
||||
}
|
||||
|
||||
async function save(event) {
|
||||
event.preventDefault();
|
||||
const button = form.querySelector("button[type=submit]");
|
||||
const changes = {
|
||||
enabled: form.elements.enabled.checked,
|
||||
visibility: form.querySelector("input[name=visibility]:checked").value,
|
||||
manually_approves_followers: form.elements.manually_approves_followers.checked,
|
||||
discoverable: form.elements.discoverable.checked,
|
||||
indexable: form.elements.indexable.checked,
|
||||
display_name: form.elements.display_name.value.trim() || null,
|
||||
bio: form.elements.bio.value.trim() || null,
|
||||
};
|
||||
const status = document.getElementById("save-status");
|
||||
button.disabled = true;
|
||||
status.textContent = "Saving";
|
||||
replace(messages);
|
||||
try {
|
||||
const saved = await api("/federation/settings", { method: "PATCH", body: changes });
|
||||
fill(saved);
|
||||
status.textContent = saved.enabled ? `Saved. You're sharing as ${saved.handle}.` : "Saved. Sharing is off.";
|
||||
} catch (error) {
|
||||
status.textContent = "";
|
||||
replace(messages, errorBox(describeError(error)));
|
||||
messages.scrollIntoView({ behavior: "smooth", block: "start" });
|
||||
} finally {
|
||||
button.disabled = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Profile · Scrobbler</title>
|
||||
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='7' fill='%231c2330'/%3E%3Ccircle cx='8' cy='8' r='3.5' fill='%23f2a541'/%3E%3C/svg%3E">
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
<script src="config.js"></script>
|
||||
<script type="module" src="js/profile.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<header class="site-header" id="site-header"></header>
|
||||
<main id="main">
|
||||
<div class="auth profile" id="profile" aria-live="polite"></div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,84 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Sharing · Scrobbler</title>
|
||||
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='7' fill='%231c2330'/%3E%3Ccircle cx='8' cy='8' r='3.5' fill='%23f2a541'/%3E%3C/svg%3E">
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
<script src="config.js"></script>
|
||||
<script type="module" src="js/sharing.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<header class="site-header" id="site-header"></header>
|
||||
<main id="main">
|
||||
<h1 class="page-title">Sharing</h1>
|
||||
<p class="lede">Let people on Mastodon and other fediverse apps follow your listening.</p>
|
||||
<div id="messages"></div>
|
||||
<form id="sharing" class="sharing" hidden>
|
||||
<div class="share-switch">
|
||||
<input type="checkbox" id="enabled" name="enabled" role="switch">
|
||||
<label for="enabled">Share my listening on the fediverse</label>
|
||||
</div>
|
||||
<div class="handle-panel" id="handle-panel" hidden>
|
||||
<p class="display-status">Your fediverse handle</p>
|
||||
<p class="approve-app handle" id="handle"></p>
|
||||
<p class="muted">People can follow you by searching for this in their app. It can't be changed once people follow you.</p>
|
||||
<p class="notice">Following arrives in a coming update. Until then people can find your profile, and follows wait as requests.</p>
|
||||
</div>
|
||||
|
||||
<fieldset class="choices">
|
||||
<legend>Who can see posts</legend>
|
||||
<div class="choice">
|
||||
<input type="radio" id="vis-followers" name="visibility" value="followers">
|
||||
<label for="vis-followers"><strong>Only your followers</strong><span class="muted">Posts go to followers and nowhere else.</span></label>
|
||||
</div>
|
||||
<div class="choice">
|
||||
<input type="radio" id="vis-unlisted" name="visibility" value="unlisted">
|
||||
<label for="vis-unlisted"><strong>Anyone who visits your profile</strong><span class="muted">Kept out of public timelines.</span></label>
|
||||
</div>
|
||||
<div class="choice">
|
||||
<input type="radio" id="vis-public" name="visibility" value="public">
|
||||
<label for="vis-public"><strong>Everyone</strong><span class="muted">Including public timelines and search.</span></label>
|
||||
</div>
|
||||
<p class="hint">"Only your followers" is only as private as who can follow you. To choose who sees your posts, turn on <em>Approve followers</em> below.</p>
|
||||
</fieldset>
|
||||
|
||||
<fieldset class="choices">
|
||||
<legend>Followers and discovery</legend>
|
||||
<div class="choice">
|
||||
<input type="checkbox" id="manually_approves_followers" name="manually_approves_followers">
|
||||
<label for="manually_approves_followers"><strong>Approve followers</strong><span class="muted">New followers need your OK.</span></label>
|
||||
</div>
|
||||
<div class="choice">
|
||||
<input type="checkbox" id="discoverable" name="discoverable">
|
||||
<label for="discoverable"><strong>List me in directories</strong><span class="muted">Fediverse apps may suggest your profile to others.</span></label>
|
||||
</div>
|
||||
<div class="choice">
|
||||
<input type="checkbox" id="indexable" name="indexable">
|
||||
<label for="indexable"><strong>Allow search</strong><span class="muted">Your public posts may be found by full-text search.</span></label>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset class="choices">
|
||||
<legend>Profile</legend>
|
||||
<div class="field">
|
||||
<label for="display_name">Display name</label>
|
||||
<input id="display_name" name="display_name" maxlength="100" autocomplete="off">
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="bio">Bio</label>
|
||||
<textarea id="bio" name="bio" maxlength="500" rows="3"></textarea>
|
||||
<span class="hint">Shown on your fediverse profile. Plain text.</span>
|
||||
</div>
|
||||
<p class="muted" id="profile-link"></p>
|
||||
</fieldset>
|
||||
|
||||
<div class="button-row save-row">
|
||||
<button class="button" type="submit">Save sharing settings</button>
|
||||
<span class="muted" id="save-status" role="status"></span>
|
||||
</div>
|
||||
</form>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user