mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2024-11-25 09:27:28 +00:00
Redesign return from settings page
This commit is contained in:
parent
bec1b9d207
commit
474274740f
@ -4,6 +4,7 @@ const {fetchUser, getOrFetchShortcode, userRequestCache, history, assistantSwitc
|
|||||||
const {render, redirect, getStaticURL} = require("pinski/plugins")
|
const {render, redirect, getStaticURL} = require("pinski/plugins")
|
||||||
const {pugCache} = require("../passthrough")
|
const {pugCache} = require("../passthrough")
|
||||||
const {getSettings} = require("./utils/getsettings")
|
const {getSettings} = require("./utils/getsettings")
|
||||||
|
const {getSettingsReferrer} = require("./utils/settingsreferrer")
|
||||||
|
|
||||||
/** @param {import("../../lib/structures/TimelineEntry")} post */
|
/** @param {import("../../lib/structures/TimelineEntry")} post */
|
||||||
function getPageTitle(post) {
|
function getPageTitle(post) {
|
||||||
@ -16,6 +17,7 @@ module.exports = [
|
|||||||
const settings = getSettings(req)
|
const settings = getSettings(req)
|
||||||
return render(200, "pug/home.pug", {
|
return render(200, "pug/home.pug", {
|
||||||
settings,
|
settings,
|
||||||
|
settingsReferrer: getSettingsReferrer("/"),
|
||||||
rssEnabled: constants.feeds.enabled,
|
rssEnabled: constants.feeds.enabled,
|
||||||
allUnblocked: history.testNoneBlocked() || assistantSwitcher.displaySomeUnblocked(),
|
allUnblocked: history.testNoneBlocked() || assistantSwitcher.displaySomeUnblocked(),
|
||||||
torAvailable: switcher.canUseTor(),
|
torAvailable: switcher.canUseTor(),
|
||||||
@ -76,7 +78,14 @@ module.exports = [
|
|||||||
|
|
||||||
const settings = getSettings(req)
|
const settings = getSettings(req)
|
||||||
|
|
||||||
return render(200, "pug/user.pug", {url, user, followerCountsAvailable, constants, settings})
|
return render(200, "pug/user.pug", {
|
||||||
|
url,
|
||||||
|
user,
|
||||||
|
followerCountsAvailable,
|
||||||
|
constants,
|
||||||
|
settings,
|
||||||
|
settingsReferrer: getSettingsReferrer(req.url)
|
||||||
|
})
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
if (error === constants.symbols.NOT_FOUND || error === constants.symbols.ENDPOINT_OVERRIDDEN) {
|
if (error === constants.symbols.NOT_FOUND || error === constants.symbols.ENDPOINT_OVERRIDDEN) {
|
||||||
return render(404, "pug/friendlyerror.pug", {
|
return render(404, "pug/friendlyerror.pug", {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
const constants = require("../../lib/constants")
|
const constants = require("../../lib/constants")
|
||||||
const {render, redirect} = require("pinski/plugins")
|
const {render, redirect} = require("pinski/plugins")
|
||||||
const {getSettings, getToken, generateCSRF, checkCSRF} = require("./utils/getsettings")
|
const {getSettings, getToken, generateCSRF, checkCSRF} = require("./utils/getsettings")
|
||||||
|
const {getSettingsReferrer} = require("./utils/settingsreferrer")
|
||||||
const crypto = require("crypto")
|
const crypto = require("crypto")
|
||||||
const db = require("../../lib/db")
|
const db = require("../../lib/db")
|
||||||
|
|
||||||
@ -12,11 +13,21 @@ module.exports = [
|
|||||||
const csrf = generateCSRF()
|
const csrf = generateCSRF()
|
||||||
const message = url.searchParams.get("message")
|
const message = url.searchParams.get("message")
|
||||||
const status = url.searchParams.get("status")
|
const status = url.searchParams.get("status")
|
||||||
return render(200, "pug/settings.pug", {constants, settings, csrf, status, message})
|
return render(200, "pug/settings.pug", {
|
||||||
|
stayAction: getSettingsReferrer(url.searchParams.get("referrer"), "/settings/stay"),
|
||||||
|
returnAction: getSettingsReferrer(url.searchParams.get("referrer"), "/settings/return"),
|
||||||
|
returnURL: url.searchParams.get("referrer") || "/",
|
||||||
|
constants,
|
||||||
|
settings,
|
||||||
|
csrf,
|
||||||
|
status,
|
||||||
|
message
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
route: "/settings", methods: ["POST"], upload: true, code: async ({req, body}) => {
|
route: "/settings/(stay|return)", methods: ["POST"], upload: true, code: async ({req, body, fill, url}) => {
|
||||||
|
const action = fill[0]
|
||||||
const oldToken = getToken(req)
|
const oldToken = getToken(req)
|
||||||
const params = new URLSearchParams(body.toString())
|
const params = new URLSearchParams(body.toString())
|
||||||
if (!checkCSRF(params.get("csrf"))) {
|
if (!checkCSRF(params.get("csrf"))) {
|
||||||
@ -53,10 +64,22 @@ module.exports = [
|
|||||||
db.prepare(`INSERT INTO UserSettings (token, created, ${fields.join(", ")}) VALUES (@token, @created, ${fields.map(f => "@"+f).join(", ")})`).run(prepared)
|
db.prepare(`INSERT INTO UserSettings (token, created, ${fields.join(", ")}) VALUES (@token, @created, ${fields.map(f => "@"+f).join(", ")})`).run(prepared)
|
||||||
db.prepare("DELETE FROM UserSettings WHERE token = ?").run(oldToken)
|
db.prepare("DELETE FROM UserSettings WHERE token = ?").run(oldToken)
|
||||||
const expires = new Date(Date.now() + 4000*24*60*60*1000).toUTCString()
|
const expires = new Date(Date.now() + 4000*24*60*60*1000).toUTCString()
|
||||||
|
let location
|
||||||
|
if (action === "return" && url.searchParams.has("referrer")) {
|
||||||
|
location = url.searchParams.get("referrer")
|
||||||
|
} else { // stay
|
||||||
|
const newParams = new URLSearchParams()
|
||||||
|
newParams.append("status", "success")
|
||||||
|
newParams.append("message", "Saved.")
|
||||||
|
if (url.searchParams.has("referrer")) {
|
||||||
|
newParams.append("referrer", url.searchParams.get("referrer"))
|
||||||
|
}
|
||||||
|
location = "/settings?" + newParams.toString()
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
statusCode: 303,
|
statusCode: 303,
|
||||||
headers: {
|
headers: {
|
||||||
"Location": "/settings?status=success&message=Saved.",
|
"Location": location,
|
||||||
"Set-Cookie": `settings=${prepared.token}; Path=/; Expires=${expires}; SameSite=Lax`
|
"Set-Cookie": `settings=${prepared.token}; Path=/; Expires=${expires}; SameSite=Lax`
|
||||||
},
|
},
|
||||||
contentType: "text/html; charset=UTF-8",
|
contentType: "text/html; charset=UTF-8",
|
||||||
|
8
src/site/api/utils/settingsreferrer.js
Normal file
8
src/site/api/utils/settingsreferrer.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
function getSettingsReferrer(current, settingsURL = "/settings") {
|
||||||
|
if (!current) return settingsURL
|
||||||
|
const params = new URLSearchParams()
|
||||||
|
params.append("referrer", current)
|
||||||
|
return settingsURL + "?" + params.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.getSettingsReferrer = getSettingsReferrer
|
@ -36,7 +36,7 @@ html
|
|||||||
|
|
||||||
h2 About this instance
|
h2 About this instance
|
||||||
ul
|
ul
|
||||||
li: a(href="/settings") Settings
|
li: a(href=settingsReferrer) Settings
|
||||||
if hasPrivacyPolicy
|
if hasPrivacyPolicy
|
||||||
li: a(href="/privacy") Privacy policy
|
li: a(href="/privacy") Privacy policy
|
||||||
else
|
else
|
||||||
|
@ -34,9 +34,12 @@ html
|
|||||||
if status && message
|
if status && message
|
||||||
.status-notice(class=status)= message
|
.status-notice(class=status)= message
|
||||||
script.
|
script.
|
||||||
history.replaceState(null, "", "/settings")
|
const params = new URLSearchParams(window.location.search)
|
||||||
|
params.delete("status")
|
||||||
|
params.delete("message")
|
||||||
|
history.replaceState(null, "", "?" + params.toString())
|
||||||
main.settings
|
main.settings
|
||||||
form(action="/settings" method="post" enctype="application/x-www-form-urlencoded")
|
form(action=returnAction method="post" enctype="application/x-www-form-urlencoded")
|
||||||
input(type="hidden" name="csrf" value=csrf)
|
input(type="hidden" name="csrf" value=csrf)
|
||||||
|
|
||||||
h1 Settings
|
h1 Settings
|
||||||
@ -123,5 +126,6 @@ html
|
|||||||
span.fake-checkbox
|
span.fake-checkbox
|
||||||
|
|
||||||
.action-container
|
.action-container
|
||||||
a(href="/").home-link ← Home
|
span.home-link-container: a(href=returnURL).home-link ← Return
|
||||||
button(type="submit").save-button Save settings
|
button(type="submit" formaction=stayAction).save-button Save
|
||||||
|
button(type="submit").save-button Save & return
|
||||||
|
@ -35,7 +35,7 @@ html
|
|||||||
//- Alt text guidelines from https://axesslab.com/alt-texts/
|
//- Alt text guidelines from https://axesslab.com/alt-texts/
|
||||||
a(href="/").nav-icon-link
|
a(href="/").nav-icon-link
|
||||||
img(src="/static/img/logo-circle-min.svg" alt="Bibliogram").logo
|
img(src="/static/img/logo-circle-min.svg" alt="Bibliogram").logo
|
||||||
a(href="/settings").nav-icon-link
|
a(href=settingsReferrer).nav-icon-link
|
||||||
img(src="/static/img/settings.svg" alt="Settings").settings
|
img(src="/static/img/settings.svg" alt="Settings").settings
|
||||||
.main-divider
|
.main-divider
|
||||||
header.profile-overview
|
header.profile-overview
|
||||||
@ -74,7 +74,7 @@ html
|
|||||||
section.bibliogram-meta
|
section.bibliogram-meta
|
||||||
.links
|
.links
|
||||||
a(href="/") Home
|
a(href="/") Home
|
||||||
a(href="/settings") Settings
|
a(href=settingsReferrer) Settings
|
||||||
|
|
||||||
- const hasPosts = !user.data.is_private && user.timeline.pages.length && user.timeline.pages[0].length
|
- const hasPosts = !user.data.is_private && user.timeline.pages.length && user.timeline.pages[0].length
|
||||||
main(class=hasPosts ? "" : "no-posts")#timeline.timeline
|
main(class=hasPosts ? "" : "no-posts")#timeline.timeline
|
||||||
|
@ -691,14 +691,22 @@ body
|
|||||||
|
|
||||||
.action-container
|
.action-container
|
||||||
margin-top: 20px
|
margin-top: 20px
|
||||||
display: flex
|
display: grid
|
||||||
justify-content: space-between
|
grid-template-columns: 1fr auto auto
|
||||||
|
grid-gap: 10px
|
||||||
align-items: center
|
align-items: center
|
||||||
|
|
||||||
.save-button
|
@media screen and (max-width: 400px)
|
||||||
padding: 12px
|
display: flex
|
||||||
width: 180px
|
flex-direction: column
|
||||||
|
align-items: stretch
|
||||||
|
text-align: center
|
||||||
|
|
||||||
|
.home-link-container
|
||||||
|
order: 1
|
||||||
|
|
||||||
|
.save-button
|
||||||
|
padding: 12px 32px
|
||||||
&:not(:active)
|
&:not(:active)
|
||||||
@include forms.curve-out-major
|
@include forms.curve-out-major
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user