From 109cae9c1929f9eb0b44b67454612dfd8d227aa3 Mon Sep 17 00:00:00 2001
From: Lim Chee Aun <cheeaun@gmail.com>
Date: Thu, 9 Feb 2023 23:01:33 +0800
Subject: [PATCH] More path fixes

---
 src/pages/status.jsx | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/pages/status.jsx b/src/pages/status.jsx
index e7d53cd8..2285a595 100644
--- a/src/pages/status.jsx
+++ b/src/pages/status.jsx
@@ -6,7 +6,7 @@ import pRetry from 'p-retry';
 import { useEffect, useMemo, useRef, useState } from 'preact/hooks';
 import { useHotkeys } from 'react-hotkeys-hook';
 import { InView } from 'react-intersection-observer';
-import { useNavigate, useParams } from 'react-router-dom';
+import { matchPath, useNavigate, useParams } from 'react-router-dom';
 import { useDebouncedCallback } from 'use-debounce';
 import { useSnapshot } from 'valtio';
 
@@ -319,12 +319,18 @@ function StatusPage() {
     heroDisplayName && heroContentText
       ? `${heroDisplayName}: "${heroContentText}"`
       : 'Status',
-    '/s/:id',
+    '/:instance?/s/:id',
   );
 
   const closeLink = useMemo(() => {
     const pathname = snapStates.prevLocation?.pathname;
-    if (!pathname || pathname.startsWith('/s/')) return '/';
+    if (
+      !pathname ||
+      matchPath('/:instance/s/:id', pathname) ||
+      matchPath('/s/:id', pathname)
+    ) {
+      return '/';
+    }
     return pathname;
   }, []);
   const onClose = () => {
@@ -575,7 +581,11 @@ function StatusPage() {
                           });
                           if (results.statuses.length) {
                             const status = results.statuses[0];
-                            navigate(`/s/${status.id}`);
+                            navigate(
+                              instance
+                                ? `/${instance}/s/${status.id}`
+                                : `/s/${status.id}`,
+                            );
                           } else {
                             throw new Error('No results');
                           }