feat: handle discover last path properly

This commit is contained in:
Paul Makles 2022-01-10 18:43:27 +00:00
parent 1d26beee10
commit 450b404ec5
2 changed files with 24 additions and 8 deletions

View file

@ -34,6 +34,11 @@ export default class Layout implements Store, Persistent<Data> {
*/
private lastHomePath: string;
/**
* Volatile last discover path.
*/
private lastDiscoverPath: string;
/**
* Map of last channels viewed in servers.
*/
@ -50,6 +55,7 @@ export default class Layout implements Store, Persistent<Data> {
constructor() {
this.lastSection = "home";
this.lastHomePath = "/";
this.lastDiscoverPath = "/discover/servers";
this.lastOpened = new ObservableMap();
this.openSections = new ObservableMap();
makeAutoObservable(this);
@ -144,9 +150,9 @@ export default class Layout implements Store, Persistent<Data> {
*/
@computed getLastPath() {
return this.lastSection === "discover"
? "/discover"
? this.lastDiscoverPath
: this.lastSection === "home"
? this.lastHomePath!
? this.lastHomePath
: this.getLastOpened(this.lastSection)!;
}
@ -167,6 +173,15 @@ export default class Layout implements Store, Persistent<Data> {
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

View file

@ -61,6 +61,8 @@ const TRUSTED_HOSTS = [
"rvlt.gg",
];
const REMOTE = "https://rvlt.gg";
export default function Discover() {
const state = useApplicationState();
const { openLink } = useIntermediate();
@ -68,12 +70,10 @@ export default function Discover() {
const history = useHistory();
const { pathname, search } = useLocation();
const srcURL = useMemo(() => {
const path = useMemo(() => {
const query = new URLSearchParams(search);
query.set("embedded", "true");
const REMOTE = "https://rvlt.gg";
// const REMOTE = "http://local.revolt.chat:3001";
return `${REMOTE}${pathname}?${query.toString()}`;
return `${pathname}?${query.toString()}`;
}, []);
const [loaded, setLoaded] = useState(false);
@ -96,7 +96,7 @@ export default function Discover() {
[],
);
useEffect(() => state.layout.setLastSection("discover"), []);
useEffect(() => state.layout.setLastDiscoverPath(path), []);
useEffect(() => {
function onMessage(message: MessageEvent) {
@ -113,6 +113,7 @@ export default function Discover() {
}
case "path": {
history.replace(data.path);
state.layout.setLastDiscoverPath(data.path);
break;
}
case "navigate": {
@ -157,7 +158,7 @@ export default function Discover() {
loaded={loaded}
crossOrigin="anonymous"
onLoad={() => setLoaded(true)}
src={srcURL}
src={REMOTE + path}
/>
</Container>
);