-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
163 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,22 @@ | ||
'use client'; | ||
import React from 'react'; | ||
|
||
import React, { useEffect, useState } from 'react'; | ||
|
||
import PostFeed from '@/components/post-feed'; | ||
import sublinksClient from '@/utils/client'; | ||
|
||
import { | ||
GetPostsResponse, ListingType, SortType | ||
} from 'sublinks-js-client'; | ||
import PostFeedOptions from '@/components/post-feed-sort'; | ||
import { GetPostsResponse } from 'sublinks-js-client'; | ||
import Feed from '@/components/front-page-feed'; | ||
import * as testData from '../../test-data.json'; | ||
|
||
const Feed = () => { | ||
const page = async () => { | ||
// @todo: Allow test data when in non-docker dev env | ||
// as Sublinks Core doesn't yet handle all post features | ||
const [postFeed, setPostFeed] = useState<GetPostsResponse>( | ||
testData as unknown as GetPostsResponse | ||
); | ||
|
||
// @todo: Set this to the users default feed type | ||
const [postFeedType, setPostFeedType] = useState<ListingType>(); | ||
const [postFeedSort, setPostFeedSort] = useState<SortType>(); | ||
|
||
useEffect(() => { | ||
async function getPosts() { | ||
setPostFeed(process.env.SUBLINKS_API_BASE_URL ? await sublinksClient().getPosts({ | ||
type_: postFeedType, | ||
sort: postFeedSort | ||
}) : testData as unknown as GetPostsResponse); | ||
} | ||
getPosts(); | ||
}, [postFeedSort, postFeedType]); | ||
const posts = process.env.SUBLINKS_API_BASE_URL ? await sublinksClient().getPosts() | ||
: testData as unknown as GetPostsResponse; | ||
|
||
return ( | ||
<div> | ||
<div className="mb-16 ml-4"> | ||
<PostFeedOptions | ||
currentType={postFeedType} | ||
onSortChange={setPostFeedSort} | ||
onTypeChange={setPostFeedType} | ||
currentSort={postFeedSort} | ||
/> | ||
</div> | ||
<PostFeed data={postFeed.posts} /> | ||
<Feed posts={posts} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Feed; | ||
export default page; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use client'; | ||
|
||
import React, { useEffect, useState } from 'react'; | ||
|
||
import PostFeed from '@/components/post-feed'; | ||
import sublinksClient from '@/utils/client'; | ||
|
||
import { | ||
GetPostsResponse, ListingType, SortType | ||
} from 'sublinks-js-client'; | ||
import PostFeedOptions from '@/components/post-feed-sort'; | ||
import * as testData from '../../../test-data.json'; | ||
|
||
interface FeedProps { | ||
posts: GetPostsResponse | ||
} | ||
|
||
const Feed = ({ posts }: FeedProps) => { | ||
// @todo: Allow test data when in non-docker dev env | ||
// as Sublinks Core doesn't yet handle all post features | ||
const [postFeed, setPostFeed] = useState<GetPostsResponse>(posts); | ||
|
||
// @todo: Set this to the users default feed type | ||
const [postFeedType, setPostFeedType] = useState<ListingType>(); | ||
const [postFeedSort, setPostFeedSort] = useState<SortType>(); | ||
|
||
useEffect(() => { | ||
async function getPosts() { | ||
setPostFeed(process.env.SUBLINKS_API_BASE_URL ? await sublinksClient().getPosts({ | ||
type_: postFeedType, | ||
sort: postFeedSort | ||
}) : testData as unknown as GetPostsResponse); | ||
} | ||
getPosts(); | ||
}, [postFeedSort, postFeedType]); | ||
|
||
return ( | ||
<div> | ||
<div className="mb-16 ml-4"> | ||
<PostFeedOptions | ||
currentType={postFeedType} | ||
onSortChange={setPostFeedSort} | ||
onTypeChange={setPostFeedType} | ||
currentSort={postFeedSort} | ||
/> | ||
</div> | ||
<PostFeed data={postFeed?.posts || []} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Feed; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters