diff --git a/frontend/static/profile.js b/frontend/static/profile.js index b8a6adf..d578ef3 100644 --- a/frontend/static/profile.js +++ b/frontend/static/profile.js @@ -7,7 +7,6 @@ const passwordForm = document.querySelector('#password-form'); const mastodonForm = document.querySelector('#mastodon-form'); const profileLogoutButton = document.querySelector('#logout-button'); const accessToken = localStorage.getItem('linklogAccessToken'); -const defaultMastodonInstance = 'mastodon.social'; const defaultPostPrefix = 'From my #LinkLog: '; const mastodonConnectButton = document.querySelector('#mastodon-connect'); @@ -46,7 +45,7 @@ async function loadMastodonConfig() { const response = await fetch('/api/user/plugins/mastodon', {headers: authHeaders()}); if (!response.ok) throw new Error('Could not load Mastodon settings'); const config = await response.json(); - document.querySelector('#mastodon-instance').value = config.instance || defaultMastodonInstance; + document.querySelector('#mastodon-instance').value = config.instance || 'mastodon.social'; document.querySelector('#mastodon-post-prefix').value = config.post_prefix || defaultPostPrefix; } @@ -96,8 +95,20 @@ mastodonForm.addEventListener('submit', async (event) => { mastodonConnectButton.addEventListener('click', async () => { mastodonConnectButton.disabled = true; - const instance = document.querySelector('#mastodon-instance').value || defaultMastodonInstance; + const instance = document.querySelector('#mastodon-instance').value.trim(); + if (!instance) { + setStatus('#mastodon-status', 'Enter the Mastodon server you want to use.', true); + mastodonConnectButton.disabled = false; + return; + } try { + const settingsResponse = await fetch('/api/user/plugins/mastodon', { + method: 'PUT', + headers: authHeaders(true), + body: JSON.stringify({instance}), + }); + if (!settingsResponse.ok) throw new Error('Could not save the Mastodon server.'); + setStatus('#mastodon-status', `Authorizing with ${instance}...`); const response = await fetch(`/api/mastodon/oauth/start?instance=${encodeURIComponent(instance)}`, {headers: authHeaders()}); const result = await response.json(); if (!response.ok || !result.authorization_url) throw new Error(result.error || 'Could not start Mastodon authorization.'); diff --git a/frontend/templates/user_profile.html b/frontend/templates/user_profile.html index cd450e6..a7d3edf 100644 --- a/frontend/templates/user_profile.html +++ b/frontend/templates/user_profile.html @@ -81,14 +81,14 @@

Mastodon

- +

@@ -97,6 +97,6 @@ - +