Skip to content

Commit

Permalink
feat(pano): allow filters to be used in home page feed
Browse files Browse the repository at this point in the history
  • Loading branch information
usirin committed Aug 18, 2023
1 parent 09f26ce commit 01fa30b
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 76 deletions.
9 changes: 5 additions & 4 deletions apps/kampus/app/pano/PanoFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ const fragment = graphql`
fragment PanoFeedFragment on Viewer
@argumentDefinitions(
after: { type: "String" }
first: { type: "Int", defaultValue: 10 }
first: { type: "Int", defaultValue: 20 }
before: { type: "String" }
last: { type: "Int" }
filter: { type: "PanoPostFilter" }
)
@refetchable(queryName: "PanoFeedPaginationQuery") {
panoFeed(first: $first, after: $after, last: $last, before: $before)
panoFeed(first: $first, after: $after, last: $last, before: $before, filter: $filter)
@connection(key: "PanoFeedFragment__panoFeed") {
__id
edges {
Expand Down Expand Up @@ -82,10 +83,10 @@ export function PanoFeed(props: Props) {
})}

<div className="flex gap-2">
<Button variant="secondary" onClick={() => loadPrevious(10)} disabled={!hasPrevious}>
<Button variant="secondary" onClick={() => loadPrevious(20)} disabled={!hasPrevious}>
{"< Prev"}
</Button>
<Button variant="secondary" onClick={() => loadNext(10)} disabled={!hasNext}>
<Button variant="secondary" onClick={() => loadNext(20)} disabled={!hasNext}>
{"Next >"}
</Button>
</div>
Expand Down
4 changes: 2 additions & 2 deletions apps/kampus/app/pano/PostListContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ interface Props {
}

const query = graphql`
query PostListContainerQuery {
query PostListContainerQuery($filter: PanoPostFilter) {
viewer {
...PanoFeedFragment
...PanoFeedFragment @arguments(filter: $filter)
...PanoFeed_viewer
}
}
Expand Down
19 changes: 15 additions & 4 deletions apps/kampus/app/pano/__generated__/PanoFeedFragment.graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 6 additions & 10 deletions apps/kampus/app/pano/features/post-filter/PanoFilterLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,16 @@ const createQueryString = (key: string, value: string) => {
return searchParams.toString();
};

export function PanoFilterLink({
query,
children,
activeQuery,
}: {
query: string;
activeQuery: PanoPostFilterType;
interface Props {
isActive: boolean;
filter: PanoPostFilterType;
children: React.ReactNode;
}) {
const isActive = query === activeQuery;
}

export function PanoFilterLink({ isActive, children, filter }: Props) {
return (
<Link
href={"/pano/posts?" + createQueryString("filter", query)}
href={"/?" + createQueryString("filter", filter)}
style={{ fontWeight: isActive ? "bold" : "normal" }}
>
{children}
Expand Down
20 changes: 10 additions & 10 deletions apps/kampus/app/pano/features/post-filter/PostSortFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ import {
type PanoPostFilterType,
} from "~/app/pano/features/post-filter/utils";

export const PostSortFilters = () => {
const searchParams = useSearchParams();
let filterQuery = searchParams.get("filter") ?? "all";

if (!isPanoPostSortFilter(filterQuery)) {
console.log(filterQuery);
filterQuery = "all";
}
interface Props {
selected: PanoPostFilterType;
}

export const PostSortFilters = (props: Props) => {
return (
<div className="flex items-center space-x-2">
{Object.entries(filters).map(([query, label]) => (
<PanoFilterLink key={query} query={query} activeQuery={filterQuery as PanoPostFilterType}>
{Object.entries(filters).map(([filter, label]) => (
<PanoFilterLink
key={filter}
filter={filter as PanoPostFilterType}
isActive={filter === props.selected}
>
{label}
</PanoFilterLink>
))}
Expand Down
Loading

0 comments on commit 01fa30b

Please sign in to comment.