Skip to content

Commit

Permalink
Merge pull request #37 from ecency/bugfix/rss
Browse files Browse the repository at this point in the history
RSS, dynamic pages
  • Loading branch information
feruzm authored Sep 27, 2024
2 parents bc02805 + 0ed31af commit d23c033
Show file tree
Hide file tree
Showing 341 changed files with 1,617 additions and 1,026 deletions.
50 changes: 48 additions & 2 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,57 @@ const config = {
}
]
},
// Warn: Rewrites applies in order
async rewrites() {
return [
{
source: "/:author/rss",
destination: "/api/:author/posts/rss"
source: "/:author(@.+)/feed",
destination: "/feed/feed/:author"
},
{
source:
"/:author(@.+)/:section(posts|blog|comments|replies|communities|trail|wallet|engine|points|spk|settings|referrals|permissions|rss|rss.xml)",
destination: "/profile/:author/:section"
},
{
source: "/:tag/:community(hive-.+)/:sub",
destination: "/community/:community/:tag/:sub"
},
{
source: "/:tag/:community(hive-.+)",
destination: "/community/:community/:tag"
},
{
source: "/:category/:author(@.+)/:permlink/:sub",
destination: "/entry/:category/:author/:permlink/:sub"
},
{
source: "/:author(@.+)/:permlink/edit",
destination: "/entry/created/:author/:permlink/edit"
},
{
source: "/:category/:author(@.+)/:permlink",
destination: "/entry/:category/:author/:permlink"
},
{
source: "/:author(@.+)/:permlink",
destination: "/entry/created/:author/:permlink"
},
{
source: "/:author(@.+)",
destination: "/profile/:author"
},
{
source: "/:filter/:tag/:sub",
destination: "/feed/:filter/:tag/:sub"
},
{
source: "/:filter/:tag",
destination: "/feed/:filter/:tag"
},
{
source: "/:filter",
destination: "/feed/:filter"
}
];
}
Expand Down
2 changes: 1 addition & 1 deletion public/sw.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/sw.js.map

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions src/api/mutations/update-reply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import { CommentOptions, Entry, MetaData } from "@/entities";
import { comment, formatError } from "@/api/operations";
import { error } from "@/features/shared";
import { EcencyEntriesCacheManagement } from "@/core/caches";
import useUpdateEntry = EcencyEntriesCacheManagement.useUpdateEntry;

export function useUpdateReply(entry?: Entry | null, onSuccess?: () => void) {
const activeUser = useGlobalStore((state) => state.activeUser);

const { updateEntryQueryData } = useUpdateEntry();
const { updateEntryQueryData } = EcencyEntriesCacheManagement.useUpdateEntry();

return useMutation({
mutationKey: ["reply-update", activeUser?.username, entry?.author, entry?.permlink],
Expand Down
30 changes: 24 additions & 6 deletions src/api/queries/get-account-posts-feed-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function prefetchGetPostsFeedQuery(
observer?: string
): Promise<InfiniteData<Entry[] | SearchResponse> | undefined> {
const isControversial = ["rising", "controversial"].includes(what);
const isUser = tag.startsWith("@");
const isUser = tag.startsWith("@") || tag.startsWith("%40");

const isAccountPosts = isUser && !isControversial;
const isControversialPosts = !isUser && isControversial;
Expand All @@ -23,7 +23,13 @@ export async function prefetchGetPostsFeedQuery(
}

if (isAccountPosts) {
return getAccountPostsQuery(tag.replace("@", ""), what, limit, observer ?? "", true).prefetch();
return getAccountPostsQuery(
tag.replace("@", "").replace("%40", ""),
what,
limit,
observer ?? "",
true
).prefetch();
}

if (isControversialPosts) {
Expand All @@ -35,7 +41,7 @@ export async function prefetchGetPostsFeedQuery(

export function getPostsFeedQueryData(what: string, tag: string, limit = 20, observer?: string) {
const isControversial = ["rising", "controversial"].includes(what);
const isUser = tag.startsWith("@");
const isUser = tag.startsWith("@") || tag.startsWith("%40");

const isAccountPosts = isUser && !isControversial;
const isControversialPosts = !isUser && isControversial;
Expand All @@ -46,7 +52,13 @@ export function getPostsFeedQueryData(what: string, tag: string, limit = 20, obs
}

if (isAccountPosts) {
return getAccountPostsQuery(tag.replace("@", ""), what, limit, observer ?? "", true).getData();
return getAccountPostsQuery(
tag.replace("@", "").replace("%40", ""),
what,
limit,
observer ?? "",
true
).getData();
}

if (isControversialPosts) {
Expand All @@ -58,7 +70,7 @@ export function getPostsFeedQueryData(what: string, tag: string, limit = 20, obs

export function usePostsFeedQuery(what: string, tag: string, limit = 20) {
const isControversial = ["rising", "controversial"].includes(what);
const isUser = tag.startsWith("@");
const isUser = tag.startsWith("@") || tag.startsWith("%40");

const isAccountPosts = isUser && !isControversial;
const isControversialPosts = !isUser && isControversial;
Expand All @@ -69,7 +81,13 @@ export function usePostsFeedQuery(what: string, tag: string, limit = 20) {
}

if (isAccountPosts) {
return getAccountPostsQuery(tag.replace("@", ""), what, limit, "", true).useClientQuery();
return getAccountPostsQuery(
tag.replace("@", "").replace("%40", ""),
what,
limit,
"",
true
).useClientQuery();
}

if (isControversialPosts) {
Expand Down
2 changes: 1 addition & 1 deletion src/api/queries/get-promoted-entries-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const getPromotedEntriesQuery = () =>

/**
* Use this query for fetching promotion entries as single list in SSR
* Because SSR index page requires paginated response
* Because SSR feed page requires paginated response
*/
export const getPromotedEntriesInfiniteQuery = () =>
EcencyQueriesManager.generateConfiguredClientServerInfiniteQuery(
Expand Down
13 changes: 13 additions & 0 deletions src/app/(dynamicPages)/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Dynamic pages

---
Dynamic pages represents all pages which matching the same URL but with different section.

Examples:
1. Profile: `/@ecency/<some_subpage>?`
2. Community: `/<some_tag>/hive-125125/<some_section>?`
3. Entry: `/<some_tag>/<author>/<permlink>`
4. Index: `/<some_tag>?`

NextJs cannot declare dynamic routes by regex so the routing stage is on the middleware or rewrites responsibility. Check out: `/features/next-middleware`, `./next.config.js`.
There is special handler for it.
58 changes: 58 additions & 0 deletions src/app/(dynamicPages)/community/[community]/[tag]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { getCommunityCache } from "@/core/caches";
import { notFound, redirect } from "next/navigation";
import { prefetchGetPostsFeedQuery } from "@/api/queries";
import { EntryListContent, LinearProgress } from "@/features/shared";
import { CommunityContentSearch } from "@/app/(dynamicPages)/community/[community]/_components/community-content-search";
import { ProfileEntriesLayout } from "@/app/(dynamicPages)/profile/[username]/_components/profile-entries-layout";
import { Entry } from "@/entities";
import { CommunityContentInfiniteList } from "@/app/(dynamicPages)/community/[community]/_components/community-content-infinite-list";
import { dehydrate, HydrationBoundary } from "@tanstack/react-query";
import { getQueryClient } from "@/core/react-query";
import { Metadata, ResolvingMetadata } from "next";
import { generateCommunityMetadata } from "@/app/(dynamicPages)/community/[community]/_helpers";

interface Props {
params: { tag: string; community: string };
}

export async function generateMetadata(props: Props, parent: ResolvingMetadata): Promise<Metadata> {
return generateCommunityMetadata(props.params.community, props.params.tag);
}

export default async function CommunityPostsPage({ params: { community, tag } }: Props) {
const communityData = await getCommunityCache(community).prefetch();
if (!communityData) {
return notFound();
}

const data = await prefetchGetPostsFeedQuery(tag, community);
if (!data || !data.pages || data.pages.length === 0) {
return <></>;
}

return (
<HydrationBoundary state={dehydrate(getQueryClient())}>
{data.pages.length === 0 ? <LinearProgress /> : ""}

{["hot", "created", "trending"].includes(tag) && data.pages.length > 0 && (
<div className="searchProfile">
<CommunityContentSearch community={communityData} filter={tag} />
</div>
)}
{/*<CommunityContentSearchData query={query} community={community} />*/}

{/*{(!query || query?.length === 0) && (*/}
<ProfileEntriesLayout section={tag} username={community}>
<EntryListContent
username={community}
isPromoted={false}
entries={data.pages.reduce<Entry[]>((acc, page) => [...acc, ...(page as Entry[])], [])}
loading={false}
sectionParam={tag}
/>
<CommunityContentInfiniteList community={communityData} section={tag} />
</ProfileEntriesLayout>
{/*)}*/}
</HydrationBoundary>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NextRequest } from "next/server";
import { AccountRssHandler } from "@/features/rss";

interface Props {
params: { community: string; tag: string };
}

export async function GET(request: NextRequest, { params: { community, tag } }: Props) {
return new Response(
(await new AccountRssHandler(request.nextUrl.pathname, community, tag).getFeed()).xml(),
{ headers: { "Content-Type": "text/xml" } }
);
}
13 changes: 13 additions & 0 deletions src/app/(dynamicPages)/community/[community]/[tag]/rss/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NextRequest } from "next/server";
import { CommunityRssHandler } from "@/features/rss";

interface Props {
params: { community: string; tag: string };
}

export async function GET(request: NextRequest, { params: { community, tag } }: Props) {
return new Response(
(await new CommunityRssHandler(request.nextUrl.pathname, community, tag).getFeed()).xml(),
{ headers: { "Content-Type": "text/xml" } }
);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "src/styles/vars_mixins";
@import "../../../../../../styles/vars_mixins";

.community-activities {
.activity-list {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "src/styles/vars_mixins";
@import "../../../../../../styles/vars_mixins";

.community-card {
position: relative;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { informationOutlineSvg } from "@ui/svg";
import i18next from "i18next";
import { Community } from "@/entities";
import { renderPostBody } from "@ecency/render-helper";
import { DialogInfo } from "@/app/[...slugs]/types";
import { DialogInfo } from "../../_types";

interface Props {
community: Community;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Community } from "@/entities";
import { nl2list } from "@/utils";
import { scriptTextOutlineSvg } from "@ui/svg";
import i18next from "i18next";
import { DialogInfo } from "@/app/[...slugs]/types";
import { DialogInfo } from "../../_types";

interface Props {
community: Community;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import i18next from "i18next";
import { accountGroupSvg } from "@ui/svg";
import React, { useMemo } from "react";
import { Community } from "@/entities";
import { DialogInfo } from "@/app/[...slugs]/types";
import { DialogInfo } from "../../_types";
import { ProfileLink } from "@/features/shared";

interface Props {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import { Account, Community, FullAccount, roleMap, ROLES } from "@/entities";
import i18next from "i18next";
import { JoinCommunityChatBtn } from "@/app/chats/_components/join-community-chat-btn";
import { UserAvatar } from "@/features/shared";
import { DialogInfo } from "@/app/[...slugs]/types";
import { DialogInfo } from "../../_types";
import { CommunityCardEditPic } from "./community-card-edit-pic";
import { CommunityCardDescription } from "./community-card-description";
import { CommunityCardRules } from "./community-card-rules";
import { CommunityCardTeam } from "./community-card-team";
import { CommunitySettingsDialog } from "@/app/[...slugs]/_components/community-settings";
import { CommunitySettingsDialog } from "@/app/(dynamicPages)/community/[community]/_components/community-settings";
import { CommunityRewardsRegistrationDialog } from "../community-rewards-registration";
import { EcencyConfigManager } from "@/config";
import Link from "next/link";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { CommunitySubscribers } from "@/app/[...slugs]/_components/community-subscribers";
import { CommunityActivities } from "@/app/[...slugs]/_components/community-activities";
import { CommunityRoles } from "@/app/[...slugs]/_components/community-roles";
import { CommunitySubscribers } from "@/app/(dynamicPages)/community/[community]/_components/community-subscribers";
import { CommunityActivities } from "@/app/(dynamicPages)/community/[community]/_components/community-activities";
import { CommunityRoles } from "@/app/(dynamicPages)/community/[community]/_components/community-roles";
import { EntryListContent, LinearProgress } from "@/features/shared";
import { Fragment } from "react";
import { Community, Entry } from "@/entities";
import { getPostsFeedQueryData } from "@/api/queries/get-account-posts-feed-query";
import { CommunityContentSearch } from "@/app/[...slugs]/_components/community-content-search";
import { ProfileEntriesLayout } from "@/app/[...slugs]/_profile-components/profile-entries-layout";
import { CommunityContentSearchData } from "@/app/[...slugs]/_components/community-content-search-data";
import { CommunityContentInfiniteList } from "@/app/[...slugs]/_components/community-content-infinite-list";
import { CommunityContentSearch } from "@/app/(dynamicPages)/community/[community]/_components/community-content-search";
import { ProfileEntriesLayout } from "@/app/(dynamicPages)/profile/[username]/_components/profile-entries-layout";
import { CommunityContentSearchData } from "@/app/(dynamicPages)/community/[community]/_components/community-content-search-data";
import { CommunityContentInfiniteList } from "@/app/(dynamicPages)/community/[community]/_components/community-content-infinite-list";

interface Props {
filter: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useCallback, useState } from "react";
import { Tooltip } from "@ui/tooltip";
import i18next from "i18next";
import { pencilOutlineSvg } from "@ui/svg";
import { ImageUploadDialog } from "@/app/[...slugs]/_components/community-card/community-image-upload-dialog";
import { ImageUploadDialog } from "@/app/(dynamicPages)/community/[community]/_components/community-card/community-image-upload-dialog";
import { useUpdateProfile } from "@/api/mutations";
import { FullAccount } from "@/entities";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "src/styles/vars_mixins";
@import "../../../../../../styles/vars_mixins";

.community-cover {
.btn-edit-cover-image {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import renderer from "react-test-renderer";

import CommunityCover from "./index";

import { Theme } from "../../store/global/types";
import { Account } from "../../store/accounts/types";
import { Theme } from "../../store/global/_types";
import { Account } from "../../store/accounts/_types";

import {
globalInstance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import { setProxyBase } from "@ecency/render-helper";
import "./_index.scss";
import defaults from "@/defaults.json";
import i18next from "i18next";
import { CommunityCoverEditImage } from "@/app/[...slugs]/_components/community-cover-edit-image";
import { CommunityCoverEditImage } from "@/app/(dynamicPages)/community/[community]/_components/community-cover-edit-image";
import { SubscriptionBtn } from "@/app/communities/_components";
import { Account, Community, FullAccount } from "@/entities";
import { useGlobalStore } from "@/core/global-store";
import { formattedNumber } from "@/utils";
import { Button } from "@ui/button";
import Link from "next/link";
import { CommunityStatItem } from "@/app/[...slugs]/_components/community-cover/community-stat-item";
import { CommunityStatItem } from "@/app/(dynamicPages)/community/[community]/_components/community-cover/community-stat-item";
import { JoinCommunityModal } from "@/app/(dynamicPages)/community/[community]/_components";
import { useSearchParams } from "next/navigation";

setProxyBase(defaults.imageServer);

Expand Down Expand Up @@ -53,6 +55,8 @@ export function CommunityCover({ community, account }: Props) {
[activeUser, users, community.name]
);

const searchParams = useSearchParams();

return (
<div className="relative overflow-hidden rounded-2xl lg:max-h-[210px]">
<div
Expand All @@ -79,6 +83,10 @@ export function CommunityCover({ community, account }: Props) {
</Link>
</div>
{canUpdateCoverImage && <CommunityCoverEditImage account={account as FullAccount} />}
<JoinCommunityModal
community={community}
communityId={searchParams.get("communityid") ?? ""}
/>
</div>
);
}
Loading

0 comments on commit d23c033

Please sign in to comment.