falling-fruit / falling-fruit-web

Mobile-friendly website for Falling Fruit
https://beta.fallingfruit.org
GNU General Public License v3.0
30 stars 7 forks source link

refactor: get rid of fromPage #431

Open wbazant opened 1 month ago

wbazant commented 1 month ago

We try to maintain the notion of what page we came from - map or list. It can't possibly work reliably, since it's lost on page refresh.

Look at these uses:

wbazant@wbazant-19-01:~/dev/falling-fruit-web$ ag fromPage
src/components/mobile/Tabs.js
45:  const findMatchingTabIndex = (currentPathname, fromPage) =>
53:          }) || tabPath === fromPage,
58:    const matchedIndex = findMatchingTabIndex(pathname, state?.fromPage)
63:    const matchedIndex = findMatchingTabIndex(pathname, state?.fromPage)
68:  }, [pathname, state?.fromPage])
81:      state?.fromPage === '/list'
85:      // but hard to understand intention or what fromPage is set to throughout the app
86:      history.push(pathname, { state: { fromPage: '/map' } })

src/components/mobile/TopBarSwitch.js
9:  const isFromList = state?.fromPage === '/list'

src/components/map/MapPage.js
156:        state: { fromPage: '/map' },
172:        state: { fromPage: '/map' },

src/components/form/LocationForm.js
403:                  history.push(state?.fromPage ?? '/map')

src/components/entry/EntryMobile.js
146:  const isInDrawer = state?.fromPage !== '/list'
291:                ? () => history.push(state?.fromPage ?? '/map')
303:                    fromPage: '/map',

src/components/entry/EntryReviews.js
38:                    fromPage: history.location.pathname,

src/components/entry/EntryOverview.js
81:      history.push(`/locations/${locationData.id}`, { fromPage: '/map' })
146:                          state: { fromPage: `/locations/${locationData.id}` },

src/components/desktop/NavBack.js
39:      history.push(state?.fromPage ?? '/map')

src/components/desktop/MainPane.js
46:        state: { fromPage: '/map' },
69:            state: { fromPage: '/map' },

src/components/list/InfiniteList.js
24:      state: { fromPage: '/list' },

src/components/table/ImportsTable.jsx
99:          state: { fromPage: '/data' },

Probably related to #364 because I see the code in EntryMobile is using the value.

wbazant commented 1 month ago

360 also related - I think fromPage tries to do a context-specific "back"