forked from Mirrors/gomuks
web/mainscreen: handle url hashes and update states consistently
This commit is contained in:
parent
5638adf6bc
commit
d8ee580817
1 changed files with 16 additions and 13 deletions
|
@ -149,7 +149,7 @@ class ContextFields implements MainScreenContextFields {
|
||||||
|
|
||||||
const SYNC_ERROR_HIDE_DELAY = 30 * 1000
|
const SYNC_ERROR_HIDE_DELAY = 30 * 1000
|
||||||
|
|
||||||
const handleURLHash = (client: Client, context: ContextFields) => {
|
const handleURLHash = (client: Client) => {
|
||||||
if (!location.hash.startsWith("#/uri/")) {
|
if (!location.hash.startsWith("#/uri/")) {
|
||||||
if (location.search) {
|
if (location.search) {
|
||||||
const currentETag = (
|
const currentETag = (
|
||||||
|
@ -181,28 +181,31 @@ const handleURLHash = (client: Client, context: ContextFields) => {
|
||||||
newURL.hash = ""
|
newURL.hash = ""
|
||||||
newURL.search = ""
|
newURL.search = ""
|
||||||
if (uri.identifier.startsWith("@")) {
|
if (uri.identifier.startsWith("@")) {
|
||||||
const right_panel = {
|
const newState = {
|
||||||
|
right_panel: {
|
||||||
type: "user",
|
type: "user",
|
||||||
userID: uri.identifier,
|
userID: uri.identifier,
|
||||||
} as RightPanelProps
|
},
|
||||||
history.replaceState({ right_panel }, "", newURL.toString())
|
}
|
||||||
context.setRightPanel(right_panel, false)
|
history.replaceState(newState, "", newURL.toString())
|
||||||
|
return newState
|
||||||
} else if (uri.identifier.startsWith("!")) {
|
} else if (uri.identifier.startsWith("!")) {
|
||||||
history.replaceState({ room_id: uri.identifier }, "", newURL.toString())
|
const newState = { room_id: uri.identifier }
|
||||||
context.setActiveRoom(uri.identifier, false)
|
history.replaceState(newState, "", newURL.toString())
|
||||||
|
return newState
|
||||||
} else if (uri.identifier.startsWith("#")) {
|
} else if (uri.identifier.startsWith("#")) {
|
||||||
// TODO loading indicator or something for this?
|
// TODO loading indicator or something for this?
|
||||||
client.rpc.resolveAlias(uri.identifier).then(
|
client.rpc.resolveAlias(uri.identifier).then(
|
||||||
res => {
|
res => {
|
||||||
history.replaceState({ room_id: res.room_id }, "", newURL.toString())
|
history.pushState({ room_id: res.room_id }, "", newURL.toString())
|
||||||
context.setActiveRoom(res.room_id, false)
|
|
||||||
},
|
},
|
||||||
err => window.alert(`Failed to resolve room alias ${uri.identifier}: ${err}`),
|
err => window.alert(`Failed to resolve room alias ${uri.identifier}: ${err}`),
|
||||||
)
|
)
|
||||||
|
return null
|
||||||
} else {
|
} else {
|
||||||
console.error("Invalid matrix URI", uri)
|
console.error("Invalid matrix URI", uri)
|
||||||
}
|
}
|
||||||
return null
|
return history.state
|
||||||
}
|
}
|
||||||
|
|
||||||
const MainScreen = () => {
|
const MainScreen = () => {
|
||||||
|
@ -227,7 +230,7 @@ const MainScreen = () => {
|
||||||
}
|
}
|
||||||
window.addEventListener("popstate", listener)
|
window.addEventListener("popstate", listener)
|
||||||
const initHandle = () => {
|
const initHandle = () => {
|
||||||
const state = handleURLHash(client, context)
|
const state = handleURLHash(client)
|
||||||
listener({ state } as PopStateEvent)
|
listener({ state } as PopStateEvent)
|
||||||
}
|
}
|
||||||
let cancel = () => {}
|
let cancel = () => {}
|
||||||
|
|
Loading…
Add table
Reference in a new issue