[nextjs]SNS Server-34(myapp44)Β 

πŸ‘‰πŸ» myapp44μ—μ„œλŠ” myapp43νŒ”λ‘œμž‰,νŒ”λ‘œμ›Œ 리슀트처럼 μ•Œλ¦Όμ„ pinafore ν…Œλ§ˆμ— ν¬ν•¨μ‹œν‚΅λ‹ˆλ‹€.
In myapp44, notificationsβ€”similar to the following and follower lists in myapp43β€”are included in the Pinafore theme.

πŸ‘‰πŸ» μ•Œλ¦Ό APIλŠ” 기쑴의 것을 μž¬ν™œμš©ν•©λ‹ˆλ‹€.(app/api/v1/notifications/route.ts)
The notification API reuses the existing one (app/api/v1/notifications/route.ts)

πŸ‘‰πŸ» 전체 μ½”λ“œλŠ” κΉƒν—ˆλΈŒμ—μ„œ 확인 ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
You can find the full code on GitHub.

https://github.com/gideonslife01/flm-nextjs

πŸ“ 전체 ν”„λ‘œμ νŠΈ ꡬ쑰 / Overall Project Structure

myapp project/  
β”œβ”€β”€ app/  (Next.js App Router)
β”‚   β”œβ”€β”€ .well-known/webfinger/route.ts  -> webfinger
β”‚   β”œβ”€β”€ api/follow/route.ts    -> Follow API(temporary)
β”‚   β”œβ”€β”€ api/announce/route.ts  -> Boost(Announcement)
β”‚   β”œβ”€β”€ api/like/route.ts.     -> Like API
β”‚   β”œβ”€β”€ api/posts/route.ts     -> Writing API
β”‚   β”œβ”€β”€ api/timeline/route.ts  -> Timeline API
β”‚   β”œβ”€β”€ api/followinglist/route.ts  -> followinglist API
β”‚   β”œβ”€β”€ api/followerslist/route.ts  -> followerslist API
β”‚   β”œβ”€β”€ api/v1/instance/route.ts -> auth
β”‚   β”œβ”€β”€ api/v1/apps/route.ts.    -> auth
β”‚   β”œβ”€β”€ api/v1/accounts/verify_credentials/route.ts -> auth
β”‚   β”œβ”€β”€ api/v1/statuses/route.ts -> Write Post
β”‚   β”œβ”€β”€ api/v1/timelines/home/route.ts -> timeline
β”‚   β”œβ”€β”€ oauth/authorize/route.ts -> auth
β”‚   β”œβ”€β”€ oauth/token/route.ts -> auth
β”‚   β”œβ”€β”€ api/v1/search/home/route.ts -> search
β”‚   β”œβ”€β”€ api/v2/search/home/route.ts -> search
β”‚   β”œβ”€β”€ api/v1/accounts/[id]/followers/route.ts -> followers
β”‚   β”œβ”€β”€ api/v1/accounts/[id]/following/route.ts -> following
β”‚   β”œβ”€β”€ api/auth/signup/route.ts        -> Signup
β”‚   β”œβ”€β”€ api/auth/login/route.ts         -> Login
β”‚   β”œβ”€β”€ api/auth/logout/route.ts        -> Logout
β”‚   β”œβ”€β”€ api/auth/refresh/route.ts       -> Refresh Token
β”‚   β”œβ”€β”€ api/auth/me/route.tsx           -> Login Check
β”‚   β”œβ”€β”€ auth/signup/page.tsx            -> Signup UI
β”‚   β”œβ”€β”€ auth/signup/page.tsx            -> Login UI
β”‚   β”œβ”€β”€ users/[username]/
β”‚   β”‚   β”œβ”€β”€ statuses/[id]/route.ts -> Indivisual Post
β”‚   β”‚   β”œβ”€β”€ route.ts               -> Acotr Information
β”‚   β”‚   β”œβ”€β”€ followers/route.ts     -> Followers List
β”‚   β”‚   β”œβ”€β”€ following/route.ts     -> Following List
β”‚   β”‚   β”œβ”€β”€ inbox/route.ts         -> Inbox
β”‚   β”‚   └── outbox/route.ts        -> outbox
β”‚   β”œβ”€β”€ usersui/[username]/
β”‚   β”‚   β”œβ”€β”€ page.tsx               -> Timeline UI(Server, 404)
β”‚   β”‚   β”œβ”€β”€ ClientPage.tsx.        -> Timeline UI(Client,Call Active Themes)
β”‚   β”‚   └── _components/themes/
β”‚   β”‚       β”œβ”€β”€ themeex/ThemeexTheme.tsx   -> Example Theme
β”‚   β”‚       β”œβ”€β”€ pinafore/PinaforeTheme.tsx -> Theme 1
β”‚   β”‚       β”œβ”€β”€ pinafore/FollowersList.tsx -> Theme 1, FollowersList
β”‚   β”‚       β”œβ”€β”€ pinafore/FollowingList.tsx -> Theme 1, FollowingList
β”‚   β”‚       β”œβ”€β”€ pinafore/NotificationsList.tsx -> Theme 1, NotificationsList
β”‚   β”‚       β”œβ”€β”€ mastodon/MastodonTheme.tsx -> Theme 2
β”‚   β”‚       └── minimal/MinimaltTheme.tsx  -> Theme 3
β”‚   β”œβ”€β”€ layout.tsx, page.tsx, globals.css
β”‚   └── favicon.ico
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ theme.tsx              -> Theme Provider
β”‚   β”œβ”€β”€ watchThemes.ts         -> Check real-time theme changes
β”‚   β”œβ”€β”€ auth.ts                -> Authentication, User Management
β”‚   β”œβ”€β”€ ap.ts                  -> Follow,Undo,Create,Likes,Announce
β”‚   └── db.ts                  -> DB connection
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ keys/userIDs/          -> private.pem, public.pem(New)
β”‚   └── keys/                  -> private.pem, public.pem(legacy)
β”œβ”€β”€ data.sqlite                -> Database(1/3)
β”œβ”€β”€ data.sqlite-wal            -> Database(2/3)
β”œβ”€β”€ data.sqlite-shm            -> Database(3/3)
β”œβ”€β”€ Caddyfile                  -> https 
β”œβ”€β”€ instrumentation.ts         -> Background Server
└── package.json

πŸ“ ν”„λ‘œμ νŠΈ μ‹œμž‘ / Project Start


πŸ“ μ½”λ“œ μˆ˜μ • / Code modification

βœ”οΈ next.config.ts

— ν…Œλ§ˆνŒŒμΌμ—μ„œ notifications 뢀뢄을 보여주기 μœ„ν•΄μ„œ initialview 전솑 μ½”λ“œλ₯Ό μΆ”κ°€ν•©λ‹ˆλ‹€.
Add the code to pass the initialView in order to display the notifications section in the theme file.

import type { NextConfig } from "next";

const nextConfig: NextConfig = {

  /* allow domain*/
  allowedDevOrigins: ['aloy-horizon.duckdns.org', '*.duckdns.org'],

  /* host.domain.org/@userid */
  async rewrites() {
    return [
      {
        source: '/@:username',
        destination: '/usersui/:username',
      },
      {
        source: '/@:username/following',
        destination: '/usersui/:username?view=following', // βœ… myapp43 - initialView
      },
      {
        source: '/@:username/followers',
        destination: '/usersui/:username?view=followers',
      },
      { source: '/@:username/notifications', // βœ… myapp44 - initialView for notifications
        destination: '/usersui/:username?view=notifications' 
      },
    ]
  },
  
};

export default nextConfig;

βœ”οΈ notificationλΌμš°νŠΈλŠ” λ”°λ‘œ λ§Œλ“€μ§€ μ•Šκ³  κΈ°μ‘΄ 라우트λ₯Ό μž¬ν™œμš©ν•©λ‹ˆλ‹€.
Instead of creating a separate notification route, the existing route is reused.

— app/api/v1/notifications/route.ts

βœ”οΈ μ—‘ν‹°λΈŒ ν…Œλ§ˆ κΈ°λŠ₯으둜 ν…Œλ§ˆλ””λ ‰ν† λ¦¬ λ‚΄μ˜ νŒŒμΌμ΄λ¦„μ— “List”κ°€ 있으면 ν…Œλ§ˆνŒŒμΌλ‘œ μΈμ‹ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.(이전 ν”„λ‘œμ νŠΈμ—μ„œ 처리 함.)
Due to the active theme feature, files in the theme directory with “List” in their names are not recognized as theme files (this was handled in a previous project).

— lib/watchThemes

βœ”οΈ app/usersui/[username]/_components/theme/pinafore/PinaforeTheme.tsx

— λ³€μˆ˜μ „λ‹¬ / Variable passing : paget.tsx -> ClientPage.tsx -> pinafore/PinaforeTheme.tsx

— initialview(=view)λ³€μˆ˜μ˜ 전달은 myap43μ—μ„œ μ²˜λ¦¬ν–ˆκΈ° λ•Œλ¬Έμ— ν…Œλ§ˆνŒŒμΌμ—μ„œλ§Œ μˆ˜μ •ν•©λ‹ˆλ‹€.
Since the passing of the initialview (or view) variable is handled in myap43, you only need to make modifications in the theme file.

— Home λ²„νŠΌν΄λ¦­μ‹œλŠ” νƒ€μž„λΌμΈμ΄ 보이도둝 μˆ˜μ •ν•©λ‹ˆλ‹€.
The Home button is being modified so that the timeline appears when clicked.

... ...
import NotificationsList from './NotificationsList'; // βœ… myapp44
... ...
export function PinaforeTheme({ timeline, username, initialView, onBoost, onLike }: any) {
... ...
  // βœ… myapp43 + myapp44
  const [view, setView] = useState<'timeline' | 'followers' | 'following' | 'notifications'>(initialView || 'timeline');
... ...
          {/** βœ… myapp44 */}
          <button 
            onClick={(e) => switchView(e, 'timeline')}
            style={{ fontWeight: view === 'timeline' ? 800 : 400 }}
          >
            🏠 Home
          </button>
          <button 
            onClick={(e) => switchView(e, 'notifications')}
            style={{ fontWeight: view === 'notifications' ? 800 : 400 }}
          >
            πŸ”” Notifications
          </button>
... ...
          {view === 'notifications' && (
            <NotificationsList username={username} style={{ padding: '0' }} />
          )}

}

πŸ“ ν…ŒμŠ€νŠΈ / Test

Notifications

μš”ν•œλ³΅μŒ 8μž₯ 32절 / John 8:32

“그리고 λ„ˆν¬λŠ” 진리λ₯Ό μ•Œκ²Œ 될 것이며, 진리가 λ„ˆν¬λ₯Ό 자유둭게 ν•  것이닀.”

“Then you will know the truth ,and the truth will set you free”

Leave a Reply