Skip to content

Commit

Permalink
posts in trending automatically interact-able from the current users …
Browse files Browse the repository at this point in the history
…instance, and clicking from user profile on remote instance over to trending now selects the current users instance currectly
  • Loading branch information
ghobs91 committed Dec 23, 2023
1 parent a1d9956 commit 8c35fb6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ function App() {
const [isLoggedIn, setIsLoggedIn] = useState(false);
const [uiState, setUIState] = useState('loading');
const instanceURL = store.local.get('instanceURL');
const myCurrentInstance = api().instance;
const { instance } = api();
const formattedShortcuts = [
{
Expand Down Expand Up @@ -282,7 +283,7 @@ function App() {
<Route index element={<Public />} />
<Route path="l" element={<Public local />} />
</Route>
<Route path="/:instance?/trending" element={<Trending />} />
<Route path="/:myCurrentInstance?/trending" element={<Trending />} />
{isLoggedIn && <Route path="/topics" element={<Topics />} />}
<Route path="/:instance?/search" element={<Search />} />
{/* <Route path="/:anything" element={<NotFound />} /> */}
Expand Down
45 changes: 25 additions & 20 deletions src/pages/status.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,30 +248,12 @@ function StatusThread({ id, closeLink = '/', instance: propInstance }) {

const hasStatus = !!snapStates.statuses[sKey];
let heroStatus = snapStates.statuses[sKey];
if (hasStatus && !reloadHero) {
console.debug('Hero status is cached');
} else {
try {
heroStatus = await heroFetch();
saveStatus(heroStatus, instance);
// Give time for context to appear
await new Promise((resolve) => {
setTimeout(resolve, 100);
});
} catch (e) {
console.error(e);
setUIState('error');
return;
}
}

// Automatically switch to users instance to allow interacting with a status

const canAutoLoadThisInstance = () => {
return myCurrentInstance != 'ditto.pub' && myCurrentInstance != 'skybridge.fly.dev' && heroStatus.account.acct.indexOf("mostr.pub") === -1 && heroStatus.account.acct.indexOf("threads.net") === -1;
}
if (canAutoLoadThisInstance()) {

const autoLoadThisInstance = () => {
setUIState('loading');
(async () => {
try {
Expand All @@ -298,6 +280,29 @@ function StatusThread({ id, closeLink = '/', instance: propInstance }) {
}
})();
}
if (hasStatus && !reloadHero) {
if (canAutoLoadThisInstance()) {
autoLoadThisInstance();
}
console.debug('Hero status is cached');
} else {
try {
heroStatus = await heroFetch();
saveStatus(heroStatus, instance);

if (canAutoLoadThisInstance()) {
autoLoadThisInstance();
}
// Give time for context to appear
await new Promise((resolve) => {
setTimeout(resolve, 100);
});
} catch (e) {
console.error(e);
setUIState('error');
return;
}
}

try {
const context = await contextFetch;
Expand Down
3 changes: 2 additions & 1 deletion src/pages/trending.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ function Trending({ columnMode, ...props }) {
const snapStates = useSnapshot(states);
const params = columnMode ? {} : useParams();
const [uiState, setUIState] = useState('default');
const myCurrentInstance = api().instance;

const { masto, instance } = api({
instance: params.instance === 'ditto.pub' ? 'mastodon.social' : params.instance === 'skybridge.fly.dev' ? 'mastodon.social' : props?.instance || params.instance,
});
const title = `Trending`;
useTitle(title, `/:instance?/trending`);
useTitle(title, `/:myCurrentInstance?/trending`);
// const navigate = useNavigate();
const latestItem = useRef();

Expand Down

0 comments on commit 8c35fb6

Please sign in to comment.