diff --git a/src/mobx/stores/Layout.ts b/src/mobx/stores/Layout.ts index a4fd1454..68e6758b 100644 --- a/src/mobx/stores/Layout.ts +++ b/src/mobx/stores/Layout.ts @@ -34,6 +34,11 @@ export default class Layout implements Store, Persistent { */ 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 { 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 { */ @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 { 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 diff --git a/src/pages/discover/Discover.tsx b/src/pages/discover/Discover.tsx index 29e93f06..c8398161 100644 --- a/src/pages/discover/Discover.tsx +++ b/src/pages/discover/Discover.tsx @@ -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} /> );