Allow settings for unauthenticated sessions

This commit is contained in:
Lim Chee Aun 2023-09-15 00:28:20 +08:00
parent dac07a35d8
commit 020d8e3631
2 changed files with 72 additions and 57 deletions

View file

@ -234,6 +234,13 @@ function NavMenu(props) {
<MenuLink to="/login"> <MenuLink to="/login">
<Icon icon="user" size="l" /> <span>Log in</span> <Icon icon="user" size="l" /> <span>Log in</span>
</MenuLink> </MenuLink>
<MenuItem
onClick={() => {
states.showSettings = true;
}}
>
<Icon icon="gear" size="l" /> <span>Settings&hellip;</span>
</MenuItem>
</> </>
)} )}
</section> </section>

View file

@ -34,6 +34,7 @@ function Settings({ onClose }) {
const currentTextSize = store.local.get('textSize') || DEFAULT_TEXT_SIZE; const currentTextSize = store.local.get('textSize') || DEFAULT_TEXT_SIZE;
const [prefs, setPrefs] = useState(store.account.get('preferences') || {}); const [prefs, setPrefs] = useState(store.account.get('preferences') || {});
const { masto, authenticated } = api();
// Get preferences every time Settings is opened // Get preferences every time Settings is opened
// NOTE: Disabled for now because I don't expect this to change often. Also for some reason, the /api/v1/preferences endpoint is cached for a while and return old prefs if refresh immediately after changing them. // NOTE: Disabled for now because I don't expect this to change often. Also for some reason, the /api/v1/preferences endpoint is cached for a while and return old prefs if refresh immediately after changing them.
// useEffect(() => { // useEffect(() => {
@ -169,50 +170,55 @@ function Settings({ onClose }) {
</li> </li>
</ul> </ul>
</section> </section>
<h3>Posting</h3> {authenticated && (
<section> <>
<ul> <h3>Posting</h3>
<li> <section>
<div> <ul>
<label for="posting-privacy-field">Default visibility</label> <li>
</div> <div>
<div> <label for="posting-privacy-field">
<select Default visibility
id="posting-privacy-field" </label>
value={prefs['posting:default:visibility'] || 'public'} </div>
onChange={(e) => { <div>
const { value } = e.target; <select
const { masto } = api(); id="posting-privacy-field"
(async () => { value={prefs['posting:default:visibility'] || 'public'}
try { onChange={(e) => {
await masto.v1.accounts.updateCredentials({ const { value } = e.target;
source: { (async () => {
privacy: value, try {
}, await masto.v1.accounts.updateCredentials({
}); source: {
setPrefs({ privacy: value,
...prefs, },
'posting:default:visibility': value, });
}); setPrefs({
store.account.set('preferences', { ...prefs,
...prefs, 'posting:default:visibility': value,
'posting:default:visibility': value, });
}); store.account.set('preferences', {
} catch (e) { ...prefs,
alert('Failed to update posting privacy'); 'posting:default:visibility': value,
console.error(e); });
} } catch (e) {
})(); alert('Failed to update posting privacy');
}} console.error(e);
> }
<option value="public">Public</option> })();
<option value="unlisted">Unlisted</option> }}
<option value="private">Followers only</option> >
</select> <option value="public">Public</option>
</div> <option value="unlisted">Unlisted</option>
</li> <option value="private">Followers only</option>
</ul> </select>
</section> </div>
</li>
</ul>
</section>
</>
)}
<h3>Experiments</h3> <h3>Experiments</h3>
<section> <section>
<ul> <ul>
@ -384,21 +390,23 @@ function Settings({ onClose }) {
</small> </small>
</div> </div>
</li> </li>
<li> {authenticated && (
<button <li>
type="button" <button
class="light" type="button"
onClick={() => { class="light"
states.showDrafts = true; onClick={() => {
states.showSettings = false; states.showDrafts = true;
}} states.showSettings = false;
> }}
Unsent drafts >
</button> Unsent drafts
</li> </button>
</li>
)}
</ul> </ul>
</section> </section>
<PushNotificationsSection onClose={onClose} /> {authenticated && <PushNotificationsSection onClose={onClose} />}
<h3>About</h3> <h3>About</h3>
<section> <section>
<div <div