Add room prefiling setting
This commit is contained in:
1 parent
f6c68aa7d5
commit
e01393c550
3 files changed
+65
-2
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import React, { useState } from 'react'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { api } from '../api.js'
|
||||
import { notifyTelegramEnabled } from '../settings.js'
|
||||
import { notifyTelegramEnabled, prefillLastRoomDisabled } from '../settings.js'
|
||||
|
||||
// Formats a Date as the value a `datetime-local` input expects, in local time
|
||||
// (YYYY-MM-DDTHH:mm).
|
||||
@@ -27,6 +27,27 @@ export default function PlanMeetingPage({ onCreated, onCancel }) {
|
||||
const [saving, setSaving] = useState(false)
|
||||
const [error, setError] = useState('')
|
||||
|
||||
// Offer the most recently joined room as the default unless the device-local
|
||||
// preference disables it. The recent-rooms list is ordered newest first, and
|
||||
// the room field is only filled while it is still empty so a manual edit is
|
||||
// preserved.
|
||||
useEffect(() => {
|
||||
if (prefillLastRoomDisabled()) return
|
||||
let active = true
|
||||
api
|
||||
.listRooms()
|
||||
.then((rooms) => {
|
||||
const last = rooms?.[0]?.roomName
|
||||
if (active && last) setRoom((current) => current || last)
|
||||
})
|
||||
.catch(() => {
|
||||
// Prefilling is best-effort; leave the field empty on failure.
|
||||
})
|
||||
return () => {
|
||||
active = false
|
||||
}
|
||||
}, [])
|
||||
|
||||
const create = async (event) => {
|
||||
event.preventDefault()
|
||||
setError('')
|
||||
|
||||
@@ -2,7 +2,9 @@ import React, { useEffect, useRef, useState } from 'react'
|
||||
import { api } from '../api.js'
|
||||
import {
|
||||
notifyTelegramEnabled,
|
||||
prefillLastRoomDisabled,
|
||||
setNotifyTelegram,
|
||||
setPrefillLastRoomDisabled,
|
||||
setSkipGuard,
|
||||
skipGuardEnabled,
|
||||
} from '../settings.js'
|
||||
@@ -70,6 +72,7 @@ export default function ProfilePage({ user, onUserChange }) {
|
||||
// Device/browser-only preferences (stored in localStorage, not on the account).
|
||||
const [skipGuard, setSkipGuardState] = useState(skipGuardEnabled)
|
||||
const [notifyTelegram, setNotifyTelegramState] = useState(notifyTelegramEnabled)
|
||||
const [disablePrefillLastRoom, setDisablePrefillLastRoomState] = useState(prefillLastRoomDisabled)
|
||||
|
||||
// Query the backend for the avatar limits instead of hardcoding them, so the
|
||||
// file picker, the size hint and the client-side check always match what the
|
||||
@@ -300,6 +303,21 @@ export default function ProfilePage({ user, onUserChange }) {
|
||||
When enabled, the "Send a Telegram notification" checkbox on the
|
||||
plan-meeting page starts checked. Off by default.
|
||||
</p>
|
||||
<label className="checkbox">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={disablePrefillLastRoom}
|
||||
onChange={(e) => {
|
||||
setDisablePrefillLastRoomState(e.target.checked)
|
||||
setPrefillLastRoomDisabled(e.target.checked)
|
||||
}}
|
||||
/>
|
||||
Don't prefill the meeting room with your last joined room
|
||||
</label>
|
||||
<p className="hint">
|
||||
By default the plan-meeting page fills the room field with the most
|
||||
recently joined room. Enable this to leave the field empty instead.
|
||||
</p>
|
||||
</section>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
const SKIP_GUARD_KEY = 'gochat.skipGuard'
|
||||
const NOTIFY_TELEGRAM_KEY = 'gochat.notifyTelegram'
|
||||
const PREFILL_LAST_ROOM_KEY = 'gochat.disablePrefillLastRoom'
|
||||
|
||||
// When enabled, opening a room URL joins it directly instead of running the
|
||||
// recent-room guard.
|
||||
@@ -50,3 +51,26 @@ export function setNotifyTelegram(enabled) {
|
||||
// Ignore: the preference simply will not persist.
|
||||
}
|
||||
}
|
||||
|
||||
// When enabled, the plan-meeting page no longer prefills the room field with
|
||||
// the most recently joined room. Off by default (prefilling is on).
|
||||
export function prefillLastRoomDisabled() {
|
||||
try {
|
||||
return window.localStorage.getItem(PREFILL_LAST_ROOM_KEY) === '1'
|
||||
} catch {
|
||||
// Storage can be unavailable (private mode, disabled cookies).
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export function setPrefillLastRoomDisabled(disabled) {
|
||||
try {
|
||||
if (disabled) {
|
||||
window.localStorage.setItem(PREFILL_LAST_ROOM_KEY, '1')
|
||||
} else {
|
||||
window.localStorage.removeItem(PREFILL_LAST_ROOM_KEY)
|
||||
}
|
||||
} catch {
|
||||
// Ignore: the preference simply will not persist.
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user