Skip to content

Commit

Permalink
TEMP fix for desc to be default - also removed null
Browse files Browse the repository at this point in the history
  • Loading branch information
ugtthis committed Jul 12, 2024
1 parent e6e3361 commit 4a5c020
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
13 changes: 6 additions & 7 deletions src/components/RouteSorter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ interface RouteSorterProps {

export const RouteSorter: Component<RouteSorterProps> = (props) => {
const [sortOptions] = createStore<SortOption[]>([
{ label: 'Date', key: 'date', order: null },
{ label: 'Duration', key: 'duration', order: null },
{ label: 'Miles', key: 'miles', order: null },
{ label: 'Engaged', key: 'engaged', order: null },
{ label: 'User Flags', key: 'userFlags', order: null },
{ label: 'Date', key: 'date', order: 'asc' },
{ label: 'Duration', key: 'duration', order: 'asc' },
{ label: 'Miles', key: 'miles', order: 'asc' },
{ label: 'Engaged', key: 'engaged', order: 'asc' },
{ label: 'User Flags', key: 'userFlags', order: 'asc' },
])

// Allows mouse wheel to scroll through filters
Expand All @@ -31,8 +31,7 @@ export const RouteSorter: Component<RouteSorterProps> = (props) => {
// If the same button is clicked, toggle the order
newOrder = props.currentSort.order === 'desc' ? 'asc' : 'desc'
} else {
// If a new button is clicked, always start with descending order
newOrder = 'desc'
newOrder = 'asc' // ! Changed to 'asc' so it descends by default... TEMP Solution find out why not working
}
props.onSortChange(clickedOption.key, newOrder)
}
Expand Down
13 changes: 11 additions & 2 deletions src/pages/dashboard/components/RouteList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface RouteListProps {
}

const RouteList: Component<RouteListProps> = (props) => {
const [sortOption, setSortOption] = createSignal<SortOption>({ label: 'Date', key: 'date', order: 'desc' })
const [sortOption, setSortOption] = createSignal<SortOption>({ label: 'Date', key: 'date', order: 'asc' })
const [page, setPage] = createSignal(1)
const [allRoutes, setAllRoutes] = createSignal<RouteSegments[]>([])
const [sortedRoutes, setSortedRoutes] = createSignal<RouteSegments[]>([])
Expand Down Expand Up @@ -60,7 +60,9 @@ const RouteList: Component<RouteListProps> = (props) => {
}

const loadMore = () => {
console.log('loadMore called', { loading: routesData.loading, hasMore: hasMore() })
if (!routesData.loading && hasMore()) {
console.log('Incrementing page')
setPage(p => p + 1)
}
}
Expand All @@ -69,6 +71,7 @@ const RouteList: Component<RouteListProps> = (props) => {
const observer = new IntersectionObserver(
(entries) => {
if (entries[0].isIntersecting) {
console.log('Bottom of list visible')
loadMore()
}
},
Expand All @@ -84,6 +87,11 @@ const RouteList: Component<RouteListProps> = (props) => {
}
})

createEffect(() => {
page()
void refetch()
})

onCleanup(() => observer.disconnect())

return (
Expand All @@ -92,11 +100,12 @@ const RouteList: Component<RouteListProps> = (props) => {
<For each={sortedRoutes()}>
{(route: RouteSegments) => <RouteCard route={route} />}
</For>
<div ref={bottomRef}>
<div>
{routesData.loading && <div>Loading...</div>}
{!routesData.loading && !hasMore() && sortedRoutes().length === 0 && <div>No routes found</div>}
{!routesData.loading && !hasMore() && sortedRoutes().length > 0 && <div>All routes loaded</div>}
</div>
<div ref={bottomRef} style={{ height: '1px' }} />
</div>
)
}
Expand Down
3 changes: 1 addition & 2 deletions src/utils/sorting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { RouteSegments } from '~/types'
import { getTimelineStatistics, TimelineStatistics } from '~/api/derived'

export type SortKey = 'date' | 'miles' | 'duration' | 'engaged' | 'userFlags'
export type SortOrder = 'asc' | 'desc' | null // ? Do I need null?

export type SortOrder = 'asc' | 'desc'
export interface SortOption {
label: string
key: SortKey
Expand Down

0 comments on commit 4a5c020

Please sign in to comment.