mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-25 16:40:58 -05:00
feat: handle discover last path properly
This commit is contained in:
parent
1d26beee10
commit
450b404ec5
2 changed files with 24 additions and 8 deletions
|
@ -34,6 +34,11 @@ export default class Layout implements Store, Persistent<Data> {
|
||||||
*/
|
*/
|
||||||
private lastHomePath: string;
|
private lastHomePath: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Volatile last discover path.
|
||||||
|
*/
|
||||||
|
private lastDiscoverPath: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map of last channels viewed in servers.
|
* Map of last channels viewed in servers.
|
||||||
*/
|
*/
|
||||||
|
@ -50,6 +55,7 @@ export default class Layout implements Store, Persistent<Data> {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.lastSection = "home";
|
this.lastSection = "home";
|
||||||
this.lastHomePath = "/";
|
this.lastHomePath = "/";
|
||||||
|
this.lastDiscoverPath = "/discover/servers";
|
||||||
this.lastOpened = new ObservableMap();
|
this.lastOpened = new ObservableMap();
|
||||||
this.openSections = new ObservableMap();
|
this.openSections = new ObservableMap();
|
||||||
makeAutoObservable(this);
|
makeAutoObservable(this);
|
||||||
|
@ -144,9 +150,9 @@ export default class Layout implements Store, Persistent<Data> {
|
||||||
*/
|
*/
|
||||||
@computed getLastPath() {
|
@computed getLastPath() {
|
||||||
return this.lastSection === "discover"
|
return this.lastSection === "discover"
|
||||||
? "/discover"
|
? this.lastDiscoverPath
|
||||||
: this.lastSection === "home"
|
: this.lastSection === "home"
|
||||||
? this.lastHomePath!
|
? this.lastHomePath
|
||||||
: this.getLastOpened(this.lastSection)!;
|
: this.getLastOpened(this.lastSection)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,6 +173,15 @@ export default class Layout implements Store, Persistent<Data> {
|
||||||
this.lastSection = "home";
|
this.lastSection = "home";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the last discover path.
|
||||||
|
* @param path Pathname
|
||||||
|
*/
|
||||||
|
@action setLastDiscoverPath(path: string) {
|
||||||
|
this.lastDiscoverPath = path;
|
||||||
|
this.lastSection = "discover";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param id Section ID
|
* @param id Section ID
|
||||||
|
|
|
@ -61,6 +61,8 @@ const TRUSTED_HOSTS = [
|
||||||
"rvlt.gg",
|
"rvlt.gg",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const REMOTE = "https://rvlt.gg";
|
||||||
|
|
||||||
export default function Discover() {
|
export default function Discover() {
|
||||||
const state = useApplicationState();
|
const state = useApplicationState();
|
||||||
const { openLink } = useIntermediate();
|
const { openLink } = useIntermediate();
|
||||||
|
@ -68,12 +70,10 @@ export default function Discover() {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const { pathname, search } = useLocation();
|
const { pathname, search } = useLocation();
|
||||||
|
|
||||||
const srcURL = useMemo(() => {
|
const path = useMemo(() => {
|
||||||
const query = new URLSearchParams(search);
|
const query = new URLSearchParams(search);
|
||||||
query.set("embedded", "true");
|
query.set("embedded", "true");
|
||||||
const REMOTE = "https://rvlt.gg";
|
return `${pathname}?${query.toString()}`;
|
||||||
// const REMOTE = "http://local.revolt.chat:3001";
|
|
||||||
return `${REMOTE}${pathname}?${query.toString()}`;
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const [loaded, setLoaded] = useState(false);
|
const [loaded, setLoaded] = useState(false);
|
||||||
|
@ -96,7 +96,7 @@ export default function Discover() {
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => state.layout.setLastSection("discover"), []);
|
useEffect(() => state.layout.setLastDiscoverPath(path), []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
function onMessage(message: MessageEvent) {
|
function onMessage(message: MessageEvent) {
|
||||||
|
@ -113,6 +113,7 @@ export default function Discover() {
|
||||||
}
|
}
|
||||||
case "path": {
|
case "path": {
|
||||||
history.replace(data.path);
|
history.replace(data.path);
|
||||||
|
state.layout.setLastDiscoverPath(data.path);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "navigate": {
|
case "navigate": {
|
||||||
|
@ -157,7 +158,7 @@ export default function Discover() {
|
||||||
loaded={loaded}
|
loaded={loaded}
|
||||||
crossOrigin="anonymous"
|
crossOrigin="anonymous"
|
||||||
onLoad={() => setLoaded(true)}
|
onLoad={() => setLoaded(true)}
|
||||||
src={srcURL}
|
src={REMOTE + path}
|
||||||
/>
|
/>
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue