Skip to content

Commit

Permalink
Fix home page not using site-level listing type #1612 (#1778)
Browse files Browse the repository at this point in the history
* Fix home page not using site-level listing type

* Use null handling instead
  • Loading branch information
jcgurango committed Jul 4, 2023
1 parent 778c353 commit 26ff0f7
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/shared/components/home/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ interface HomeState {
}

interface HomeProps {
listingType: ListingType;
listingType?: ListingType;
dataType: DataType;
sort: SortType;
page: number;
Expand Down Expand Up @@ -163,12 +163,12 @@ function getDataTypeFromQuery(type?: string): DataType {
return type ? DataType[type] : DataType.Post;
}

function getListingTypeFromQuery(type?: string): ListingType {
function getListingTypeFromQuery(type?: string): ListingType | undefined {
const myListingType =
UserService.Instance.myUserInfo?.local_user_view?.local_user
?.default_listing_type;

return (type ? (type as ListingType) : myListingType) ?? "Local";
return type ? (type as ListingType) : myListingType;
}

function getSortTypeFromQuery(type?: string): SortType {
Expand Down Expand Up @@ -311,11 +311,12 @@ export class Home extends Component<any, HomeState> {
client,
auth,
query: { dataType: urlDataType, listingType, page: urlPage, sort: urlSort },
site,
}: InitialFetchRequest<QueryParams<HomeProps>>): Promise<HomeData> {
const dataType = getDataTypeFromQuery(urlDataType);

// TODO figure out auth default_listingType, default_sort_type
const type_ = getListingTypeFromQuery(listingType);
const type_ =
getListingTypeFromQuery(listingType) ??
site.site_view.local_site.default_post_listing_type;
const sort = getSortTypeFromQuery(urlSort);

const page = urlPage ? Number(urlPage) : 1;
Expand Down Expand Up @@ -761,7 +762,10 @@ export class Home extends Component<any, HomeState> {
</div>
<div className="col-auto">
<ListingTypeSelect
type_={listingType}
type_={
listingType ??
this.state.siteRes.site_view.local_site.default_post_listing_type
}
showLocal={showLocal(this.isoData)}
showSubscribed
onChange={this.handleListingTypeChange}
Expand All @@ -770,7 +774,12 @@ export class Home extends Component<any, HomeState> {
<div className="col-auto">
<SortSelect sort={sort} onChange={this.handleSortChange} />
</div>
<div className="col-auto ps-0">{getRss(listingType)}</div>
<div className="col-auto ps-0">
{getRss(
listingType ??
this.state.siteRes.site_view.local_site.default_post_listing_type
)}
</div>
</div>
);
}
Expand Down

0 comments on commit 26ff0f7

Please sign in to comment.