@stone-js/starters 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +101 -0
- package/basic-react-declarative/LICENSE +21 -0
- package/basic-react-declarative/README.md +39 -0
- package/basic-react-declarative/app/Application.tsx +89 -0
- package/basic-react-declarative/assets/css/index.css +26 -0
- package/basic-react-declarative/package.json +39 -0
- package/basic-react-declarative/public/logo.png +0 -0
- package/basic-react-declarative/tests/Application.spec.ts +96 -0
- package/basic-react-declarative/tests/__snapshots__/Application.spec.ts.snap +3 -0
- package/basic-react-declarative/tsconfig.json +33 -0
- package/basic-react-declarative/vitest.config.ts +24 -0
- package/basic-react-imperative/LICENSE +21 -0
- package/basic-react-imperative/README.md +39 -0
- package/basic-react-imperative/app/Application.tsx +89 -0
- package/basic-react-imperative/assets/css/index.css +26 -0
- package/basic-react-imperative/package.json +39 -0
- package/basic-react-imperative/public/logo.png +0 -0
- package/basic-react-imperative/tests/Application.spec.ts +80 -0
- package/basic-react-imperative/tests/__snapshots__/Application.spec.ts.snap +3 -0
- package/basic-react-imperative/tsconfig.json +33 -0
- package/basic-react-imperative/vitest.config.ts +24 -0
- package/basic-service-declarative/LICENSE +21 -0
- package/basic-service-declarative/README.md +39 -0
- package/basic-service-declarative/app/Application.ts +56 -0
- package/basic-service-declarative/package.json +34 -0
- package/basic-service-declarative/tests/Application.spec.ts +60 -0
- package/basic-service-declarative/tsconfig.json +25 -0
- package/basic-service-declarative/vitest.config.ts +24 -0
- package/basic-service-imperative/LICENSE +21 -0
- package/basic-service-imperative/README.md +39 -0
- package/basic-service-imperative/app/Application.ts +60 -0
- package/basic-service-imperative/package.json +34 -0
- package/basic-service-imperative/tests/Application.spec.ts +52 -0
- package/basic-service-imperative/tsconfig.json +25 -0
- package/basic-service-imperative/vitest.config.ts +24 -0
- package/continuum-showcase/README.md +44 -0
- package/continuum-showcase/app/env.d.ts +34 -0
- package/continuum-showcase/app/layouts/MainLayout.tsx +20 -0
- package/continuum-showcase/app/pages/BlogPostPage.tsx +62 -0
- package/continuum-showcase/app/pages/HomePage.tsx +58 -0
- package/continuum-showcase/package.json +25 -0
- package/continuum-showcase/stone.config.mjs +20 -0
- package/full-react-declarative/.env.example +1 -0
- package/full-react-declarative/.env.public.example +1 -0
- package/full-react-declarative/LICENSE +21 -0
- package/full-react-declarative/README.md +39 -0
- package/full-react-declarative/app/Application.ts +85 -0
- package/full-react-declarative/app/clients/AxiosClient.ts +136 -0
- package/full-react-declarative/app/clients/CommentClient.ts +61 -0
- package/full-react-declarative/app/clients/PostClient.ts +90 -0
- package/full-react-declarative/app/clients/SecurityClient.ts +66 -0
- package/full-react-declarative/app/clients/UserClient.ts +97 -0
- package/full-react-declarative/app/components/ChangePasswordForm/ChangePasswordForm.tsx +50 -0
- package/full-react-declarative/app/components/CommentForm/CommentForm.tsx +37 -0
- package/full-react-declarative/app/components/CommentItem/CommentItem.tsx +42 -0
- package/full-react-declarative/app/components/CommentWidget/CommentWidget.tsx +95 -0
- package/full-react-declarative/app/components/LoginForm/LoginForm.css +0 -0
- package/full-react-declarative/app/components/LoginForm/LoginForm.tsx +71 -0
- package/full-react-declarative/app/components/PostDetails/PostDetails.tsx +44 -0
- package/full-react-declarative/app/components/PostForm/PostForm.css +0 -0
- package/full-react-declarative/app/components/PostForm/PostForm.tsx +47 -0
- package/full-react-declarative/app/components/PostItem/PostItem.css +0 -0
- package/full-react-declarative/app/components/PostItem/PostItem.tsx +34 -0
- package/full-react-declarative/app/components/RegisterForm/RegisterForm.tsx +110 -0
- package/full-react-declarative/app/components/UserForm/UserForm.tsx +47 -0
- package/full-react-declarative/app/configurations/AppConfiguration.ts +17 -0
- package/full-react-declarative/app/error-pages/DefaultErrorPage/DefaultErrorPage.css +0 -0
- package/full-react-declarative/app/error-pages/DefaultErrorPage/DefaultErrorPage.tsx +52 -0
- package/full-react-declarative/app/error-pages/ForbiddenErrorPage/ForbiddenErrorPage.css +0 -0
- package/full-react-declarative/app/error-pages/ForbiddenErrorPage/ForbiddenErrorPage.tsx +53 -0
- package/full-react-declarative/app/error-pages/NotFoundErrorPage/NotFoundErrorPage.css +0 -0
- package/full-react-declarative/app/error-pages/NotFoundErrorPage/NotFoundErrorPage.tsx +54 -0
- package/full-react-declarative/app/error-pages/UnauthorizedErrorPage/UnauthorizedErrorPage.css +0 -0
- package/full-react-declarative/app/error-pages/UnauthorizedErrorPage/UnauthorizedErrorPage.tsx +53 -0
- package/full-react-declarative/app/errors/ForbiddenError.ts +11 -0
- package/full-react-declarative/app/errors/PostNotFoundError.ts +11 -0
- package/full-react-declarative/app/errors/UnauthorizedError.ts +11 -0
- package/full-react-declarative/app/errors/UserNotFoundError.ts +11 -0
- package/full-react-declarative/app/events/UserEvent.ts +18 -0
- package/full-react-declarative/app/layout/AppLayout/AppLayout.css +20 -0
- package/full-react-declarative/app/layout/AppLayout/AppLayout.tsx +101 -0
- package/full-react-declarative/app/layout/ErrorLayout/ErrorLayout.css +0 -0
- package/full-react-declarative/app/layout/ErrorLayout/ErrorLayout.tsx +41 -0
- package/full-react-declarative/app/layout/SecurityLayout/SecurityLayout.css +0 -0
- package/full-react-declarative/app/layout/SecurityLayout/SecurityLayout.tsx +39 -0
- package/full-react-declarative/app/middleware/AuthMiddleware.ts +85 -0
- package/full-react-declarative/app/models/Comment.ts +31 -0
- package/full-react-declarative/app/models/Post.ts +22 -0
- package/full-react-declarative/app/models/User.ts +62 -0
- package/full-react-declarative/app/pages/home/HomePage.tsx +44 -0
- package/full-react-declarative/app/pages/login/LoginPage.css +0 -0
- package/full-react-declarative/app/pages/login/LoginPage.tsx +73 -0
- package/full-react-declarative/app/pages/posts/CreatePostPage/CreatePostPage.css +0 -0
- package/full-react-declarative/app/pages/posts/CreatePostPage/CreatePostPage.tsx +67 -0
- package/full-react-declarative/app/pages/posts/PostPage/PostPage.tsx +60 -0
- package/full-react-declarative/app/pages/posts/ShowPostPage/ShowPostPage.tsx +83 -0
- package/full-react-declarative/app/pages/posts/UpdatePostPage/UpdatePostPage.tsx +77 -0
- package/full-react-declarative/app/pages/register/RegisterPage.tsx +68 -0
- package/full-react-declarative/app/pages/users/CreateUserPage.tsx +48 -0
- package/full-react-declarative/app/pages/users/ShowUserPage.tsx +62 -0
- package/full-react-declarative/app/pages/users/UpdateUserPage.tsx +57 -0
- package/full-react-declarative/app/pages/users/UserPage.tsx +57 -0
- package/full-react-declarative/app/providers/AppServiceProvider.ts +43 -0
- package/full-react-declarative/app/services/CommentService.ts +59 -0
- package/full-react-declarative/app/services/PostService.ts +108 -0
- package/full-react-declarative/app/services/SecurityService.ts +80 -0
- package/full-react-declarative/app/services/TokenService.ts +116 -0
- package/full-react-declarative/app/services/UserService.ts +126 -0
- package/full-react-declarative/app/utils.ts +17 -0
- package/full-react-declarative/assets/css/index.css +301 -0
- package/full-react-declarative/assets/img/logo.png +0 -0
- package/full-react-declarative/package.json +46 -0
- package/full-react-declarative/public/logo.png +0 -0
- package/full-react-declarative/public/vite.svg +1 -0
- package/full-react-declarative/stone.config.mjs +12 -0
- package/full-react-declarative/tsconfig.json +29 -0
- package/full-react-declarative/vitest.config.ts +24 -0
- package/full-react-imperative/.env.example +1 -0
- package/full-react-imperative/.env.public.example +1 -0
- package/full-react-imperative/LICENSE +21 -0
- package/full-react-imperative/README.md +39 -0
- package/full-react-imperative/app/Application.ts +79 -0
- package/full-react-imperative/app/clients/AxiosClient.ts +124 -0
- package/full-react-imperative/app/clients/CommentClient.ts +57 -0
- package/full-react-imperative/app/clients/PostClient.ts +86 -0
- package/full-react-imperative/app/clients/SecurityClient.ts +60 -0
- package/full-react-imperative/app/clients/UserClient.ts +93 -0
- package/full-react-imperative/app/clients/contracts/IAxiosClient.ts +97 -0
- package/full-react-imperative/app/clients/contracts/ICommentClient.ts +31 -0
- package/full-react-imperative/app/clients/contracts/IPostClient.ts +55 -0
- package/full-react-imperative/app/clients/contracts/ISecurityClient.ts +33 -0
- package/full-react-imperative/app/clients/contracts/IUserClient.ts +61 -0
- package/full-react-imperative/app/components/ChangePasswordForm/ChangePasswordForm.tsx +50 -0
- package/full-react-imperative/app/components/CommentForm/CommentForm.css +35 -0
- package/full-react-imperative/app/components/CommentForm/CommentForm.tsx +45 -0
- package/full-react-imperative/app/components/CommentItem/CommentItem.css +74 -0
- package/full-react-imperative/app/components/CommentItem/CommentItem.tsx +62 -0
- package/full-react-imperative/app/components/CommentWidget/CommentWidget.css +25 -0
- package/full-react-imperative/app/components/CommentWidget/CommentWidget.tsx +119 -0
- package/full-react-imperative/app/components/Dropdown/Dropdown.css +52 -0
- package/full-react-imperative/app/components/Dropdown/Dropdown.tsx +40 -0
- package/full-react-imperative/app/components/LayoutHeader/LayoutHeader.css +62 -0
- package/full-react-imperative/app/components/LayoutHeader/LayoutHeader.tsx +61 -0
- package/full-react-imperative/app/components/LayoutLeftMenu/LayoutLeftMenu.css +25 -0
- package/full-react-imperative/app/components/LayoutLeftMenu/LayoutLeftMenu.tsx +32 -0
- package/full-react-imperative/app/components/LoginForm/LoginForm.css +0 -0
- package/full-react-imperative/app/components/LoginForm/LoginForm.tsx +71 -0
- package/full-react-imperative/app/components/NotificationBadge/NotificationBadge.css +41 -0
- package/full-react-imperative/app/components/NotificationBadge/NotificationBadge.tsx +63 -0
- package/full-react-imperative/app/components/PostCard/PostCard.css +129 -0
- package/full-react-imperative/app/components/PostCard/PostCard.tsx +65 -0
- package/full-react-imperative/app/components/PostForm/PostForm.css +92 -0
- package/full-react-imperative/app/components/PostForm/PostForm.tsx +76 -0
- package/full-react-imperative/app/components/PostSkeleton/PostSkeleton.css +65 -0
- package/full-react-imperative/app/components/PostSkeleton/PostSkeleton.tsx +25 -0
- package/full-react-imperative/app/components/PostWidget/PostWidget.tsx +95 -0
- package/full-react-imperative/app/components/ProfileForm/ProfileForm.css +84 -0
- package/full-react-imperative/app/components/ProfileForm/ProfileForm.tsx +79 -0
- package/full-react-imperative/app/components/RegisterForm/RegisterForm.tsx +110 -0
- package/full-react-imperative/app/components/RightAsidePanel/RightAsidePanel.css +32 -0
- package/full-react-imperative/app/components/RightAsidePanel/RightAsidePanel.tsx +62 -0
- package/full-react-imperative/app/components/SettingsForm/SettingsForm.css +126 -0
- package/full-react-imperative/app/components/SettingsForm/SettingsForm.tsx +86 -0
- package/full-react-imperative/app/components/UserAvatar/UserAvatar.css +18 -0
- package/full-react-imperative/app/components/UserAvatar/UserAvatar.tsx +60 -0
- package/full-react-imperative/app/components/UserBadge/UserBadge.css +33 -0
- package/full-react-imperative/app/components/UserBadge/UserBadge.tsx +49 -0
- package/full-react-imperative/app/components/UserCard/UserCard.css +70 -0
- package/full-react-imperative/app/components/UserCard/UserCard.tsx +43 -0
- package/full-react-imperative/app/configurations/AppConfiguration.ts +19 -0
- package/full-react-imperative/app/error-pages/DefaultErrorPage/DefaultErrorPage.css +0 -0
- package/full-react-imperative/app/error-pages/DefaultErrorPage/DefaultErrorPage.tsx +41 -0
- package/full-react-imperative/app/error-pages/ForbiddenErrorPage/ForbiddenErrorPage.css +0 -0
- package/full-react-imperative/app/error-pages/ForbiddenErrorPage/ForbiddenErrorPage.tsx +42 -0
- package/full-react-imperative/app/error-pages/NotFoundErrorPage/NotFoundErrorPage.css +0 -0
- package/full-react-imperative/app/error-pages/NotFoundErrorPage/NotFoundErrorPage.tsx +49 -0
- package/full-react-imperative/app/error-pages/UnauthorizedErrorPage/UnauthorizedErrorPage.css +0 -0
- package/full-react-imperative/app/error-pages/UnauthorizedErrorPage/UnauthorizedErrorPage.tsx +42 -0
- package/full-react-imperative/app/errors/ForbiddenError.ts +11 -0
- package/full-react-imperative/app/errors/PostNotFoundError.ts +11 -0
- package/full-react-imperative/app/errors/UnauthorizedError.ts +11 -0
- package/full-react-imperative/app/errors/UserNotFoundError.ts +11 -0
- package/full-react-imperative/app/events/UserEvent.ts +18 -0
- package/full-react-imperative/app/layout/AppLayout/AppLayout.css +106 -0
- package/full-react-imperative/app/layout/AppLayout/AppLayout.tsx +48 -0
- package/full-react-imperative/app/layout/ErrorLayout/ErrorLayout.css +0 -0
- package/full-react-imperative/app/layout/ErrorLayout/ErrorLayout.tsx +45 -0
- package/full-react-imperative/app/layout/SecurityLayout/SecurityLayout.css +0 -0
- package/full-react-imperative/app/layout/SecurityLayout/SecurityLayout.tsx +43 -0
- package/full-react-imperative/app/layout/SettingsLayout/SettingsLayout.css +99 -0
- package/full-react-imperative/app/layout/SettingsLayout/SettingsLayout.tsx +44 -0
- package/full-react-imperative/app/middleware/AuthMiddleware.ts +56 -0
- package/full-react-imperative/app/models/Comment.ts +35 -0
- package/full-react-imperative/app/models/Post.ts +27 -0
- package/full-react-imperative/app/models/User.ts +68 -0
- package/full-react-imperative/app/pages/Settings/SettingsPage.tsx +23 -0
- package/full-react-imperative/app/pages/home/HomePage.tsx +58 -0
- package/full-react-imperative/app/pages/login/LoginPage.css +0 -0
- package/full-react-imperative/app/pages/login/LoginPage.tsx +65 -0
- package/full-react-imperative/app/pages/posts/ShowPostPage/ShowPostPage.tsx +64 -0
- package/full-react-imperative/app/pages/posts/UpdatePostPage/UpdatePostPage.tsx +56 -0
- package/full-react-imperative/app/pages/register/RegisterPage.tsx +71 -0
- package/full-react-imperative/app/pages/users/ShowUserPage/ShowUserPage.css +64 -0
- package/full-react-imperative/app/pages/users/ShowUserPage/ShowUserPage.tsx +104 -0
- package/full-react-imperative/app/pages/users/UpdateUserPage/UpdateUserPage.css +0 -0
- package/full-react-imperative/app/pages/users/UpdateUserPage/UpdateUserPage.tsx +43 -0
- package/full-react-imperative/app/pages/users/UserPage/UserPage.css +31 -0
- package/full-react-imperative/app/pages/users/UserPage/UserPage.tsx +59 -0
- package/full-react-imperative/app/pages/utils.ts +67 -0
- package/full-react-imperative/app/providers/AppServiceProvider.ts +40 -0
- package/full-react-imperative/app/services/CommentService.ts +53 -0
- package/full-react-imperative/app/services/PostService.ts +102 -0
- package/full-react-imperative/app/services/SecurityService.ts +72 -0
- package/full-react-imperative/app/services/TokenService.ts +108 -0
- package/full-react-imperative/app/services/UserService.ts +115 -0
- package/full-react-imperative/app/services/contracts/ICommentService.ts +30 -0
- package/full-react-imperative/app/services/contracts/IPostService.ts +65 -0
- package/full-react-imperative/app/services/contracts/ISecurityService.ts +39 -0
- package/full-react-imperative/app/services/contracts/ITokenService.ts +44 -0
- package/full-react-imperative/app/services/contracts/IUserService.ts +70 -0
- package/full-react-imperative/app/utils.ts +31 -0
- package/full-react-imperative/assets/css/index.css +301 -0
- package/full-react-imperative/assets/img/logo.png +0 -0
- package/full-react-imperative/package.json +48 -0
- package/full-react-imperative/public/logo.png +0 -0
- package/full-react-imperative/public/vite.svg +1 -0
- package/full-react-imperative/stone.config.mjs +12 -0
- package/full-react-imperative/tsconfig.json +29 -0
- package/full-react-imperative/vitest.config.ts +24 -0
- package/full-service-declarative/.env.example +2 -0
- package/full-service-declarative/LICENSE +21 -0
- package/full-service-declarative/README.md +65 -0
- package/full-service-declarative/app/Application.ts +327 -0
- package/full-service-declarative/app/commands/ListSessionsCommand.ts +70 -0
- package/full-service-declarative/app/commands/ListUsersCommand.ts +56 -0
- package/full-service-declarative/app/configurations/AppConfiguration.ts +52 -0
- package/full-service-declarative/app/configurations/UserLiveConfiguration.ts +28 -0
- package/full-service-declarative/app/database/DatabaseClient.ts +43 -0
- package/full-service-declarative/app/database/schema.ts +43 -0
- package/full-service-declarative/app/error-handlers/SecurityErrorHandler.ts +61 -0
- package/full-service-declarative/app/errors/CredentialsError.ts +12 -0
- package/full-service-declarative/app/events/UserEvent.ts +17 -0
- package/full-service-declarative/app/handlers/CommentEventHandler.ts +103 -0
- package/full-service-declarative/app/handlers/PostEventHandler.ts +104 -0
- package/full-service-declarative/app/handlers/SecurityEventHandler.ts +108 -0
- package/full-service-declarative/app/handlers/UserEventHandler.ts +159 -0
- package/full-service-declarative/app/listeners/UserEventListener.ts +35 -0
- package/full-service-declarative/app/middleware/AuthMiddleware.ts +54 -0
- package/full-service-declarative/app/models/Comment.ts +38 -0
- package/full-service-declarative/app/models/Post.ts +50 -0
- package/full-service-declarative/app/models/Session.ts +14 -0
- package/full-service-declarative/app/models/User.ts +77 -0
- package/full-service-declarative/app/providers/DrizzleServiceProvider.ts +59 -0
- package/full-service-declarative/app/repositories/CommentRepository.ts +155 -0
- package/full-service-declarative/app/repositories/PostRepository.ts +138 -0
- package/full-service-declarative/app/repositories/SessionRepository.ts +123 -0
- package/full-service-declarative/app/repositories/UserRepository.ts +99 -0
- package/full-service-declarative/app/services/CommentService.ts +112 -0
- package/full-service-declarative/app/services/PostService.ts +100 -0
- package/full-service-declarative/app/services/SecurityService.ts +232 -0
- package/full-service-declarative/app/services/SessionService.ts +130 -0
- package/full-service-declarative/app/services/UserService.ts +110 -0
- package/full-service-declarative/app/subscribers/UserEventSubscriber.ts +38 -0
- package/full-service-declarative/drizzle.config.ts +13 -0
- package/full-service-declarative/package.json +48 -0
- package/full-service-declarative/stone.config.mjs +12 -0
- package/full-service-declarative/tsconfig.json +25 -0
- package/full-service-declarative/vitest.config.ts +24 -0
- package/full-service-imperative/.env.example +2 -0
- package/full-service-imperative/LICENSE +21 -0
- package/full-service-imperative/README.md +65 -0
- package/full-service-imperative/app/Application.ts +317 -0
- package/full-service-imperative/app/commands/ListSessionsCommand.ts +54 -0
- package/full-service-imperative/app/commands/ListUsersCommand.ts +42 -0
- package/full-service-imperative/app/configurations/AppConfiguration.ts +44 -0
- package/full-service-imperative/app/configurations/UserLiveConfiguration.ts +26 -0
- package/full-service-imperative/app/database/DatabaseClient.ts +39 -0
- package/full-service-imperative/app/database/schema.ts +43 -0
- package/full-service-imperative/app/error-handlers/SecurityErrorHandler.ts +58 -0
- package/full-service-imperative/app/errors/CredentialsError.ts +12 -0
- package/full-service-imperative/app/events/UserEvent.ts +17 -0
- package/full-service-imperative/app/handlers/CommentEventHandler.ts +99 -0
- package/full-service-imperative/app/handlers/PostEventHandler.ts +99 -0
- package/full-service-imperative/app/handlers/SecurityEventHandler.ts +83 -0
- package/full-service-imperative/app/handlers/UserEventHandler.ts +132 -0
- package/full-service-imperative/app/listeners/UserEventListener.ts +23 -0
- package/full-service-imperative/app/middleware/AuthMiddleware.ts +44 -0
- package/full-service-imperative/app/models/Comment.ts +38 -0
- package/full-service-imperative/app/models/Post.ts +50 -0
- package/full-service-imperative/app/models/Session.ts +14 -0
- package/full-service-imperative/app/models/User.ts +77 -0
- package/full-service-imperative/app/providers/DrizzleServiceProvider.ts +56 -0
- package/full-service-imperative/app/repositories/CommentRepository.ts +148 -0
- package/full-service-imperative/app/repositories/PostRepository.ts +130 -0
- package/full-service-imperative/app/repositories/SessionRepository.ts +115 -0
- package/full-service-imperative/app/repositories/UserRepository.ts +91 -0
- package/full-service-imperative/app/repositories/contracts/ICommentRepository.ts +72 -0
- package/full-service-imperative/app/repositories/contracts/IPostRepository.ts +63 -0
- package/full-service-imperative/app/repositories/contracts/ISessionRepository.ts +65 -0
- package/full-service-imperative/app/repositories/contracts/IUserRepository.ts +55 -0
- package/full-service-imperative/app/services/CommentService.ts +109 -0
- package/full-service-imperative/app/services/PostService.ts +97 -0
- package/full-service-imperative/app/services/SecurityService.ts +224 -0
- package/full-service-imperative/app/services/SessionService.ts +124 -0
- package/full-service-imperative/app/services/UserService.ts +105 -0
- package/full-service-imperative/app/services/contracts/ICommentService.ts +62 -0
- package/full-service-imperative/app/services/contracts/IPostService.ts +53 -0
- package/full-service-imperative/app/services/contracts/ISecurityService.ts +97 -0
- package/full-service-imperative/app/services/contracts/ISessionService.ts +73 -0
- package/full-service-imperative/app/services/contracts/IUserService.ts +57 -0
- package/full-service-imperative/app/subscribers/UserEventSubscriber.ts +28 -0
- package/full-service-imperative/drizzle.config.ts +13 -0
- package/full-service-imperative/package.json +48 -0
- package/full-service-imperative/stone.config.mjs +12 -0
- package/full-service-imperative/tsconfig.json +25 -0
- package/full-service-imperative/vitest.config.ts +24 -0
- package/package.json +225 -0
- package/standard-react-declarative/LICENSE +21 -0
- package/standard-react-declarative/README.md +39 -0
- package/standard-react-declarative/app/Application.ts +45 -0
- package/standard-react-declarative/app/pages/welcome/WelcomePage.tsx +57 -0
- package/standard-react-declarative/app/services/WelcomeService.ts +38 -0
- package/standard-react-declarative/assets/css/index.css +26 -0
- package/standard-react-declarative/package.json +42 -0
- package/standard-react-declarative/tsconfig.json +33 -0
- package/standard-react-declarative/vitest.config.ts +24 -0
- package/standard-react-imperative/LICENSE +21 -0
- package/standard-react-imperative/README.md +39 -0
- package/standard-react-imperative/app/Application.ts +41 -0
- package/standard-react-imperative/app/pages/welcome/WelcomePage.tsx +50 -0
- package/standard-react-imperative/app/services/WelcomeService.ts +38 -0
- package/standard-react-imperative/assets/css/index.css +26 -0
- package/standard-react-imperative/package.json +42 -0
- package/standard-react-imperative/tsconfig.json +33 -0
- package/standard-react-imperative/vitest.config.ts +24 -0
- package/standard-service-declarative/LICENSE +21 -0
- package/standard-service-declarative/README.md +39 -0
- package/standard-service-declarative/app/Application.ts +39 -0
- package/standard-service-declarative/app/handlers/WelcomeEventHandler.ts +45 -0
- package/standard-service-declarative/app/services/WelcomeService.ts +38 -0
- package/standard-service-declarative/package.json +36 -0
- package/standard-service-declarative/tsconfig.json +25 -0
- package/standard-service-declarative/vitest.config.ts +24 -0
- package/standard-service-imperative/LICENSE +21 -0
- package/standard-service-imperative/README.md +39 -0
- package/standard-service-imperative/app/Application.ts +11 -0
- package/standard-service-imperative/app/handlers/welcomeEventHandler.ts +31 -0
- package/standard-service-imperative/app/services/welcomeService.ts +38 -0
- package/standard-service-imperative/package.json +35 -0
- package/standard-service-imperative/tsconfig.json +25 -0
- package/standard-service-imperative/vitest.config.ts +24 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import './LayoutHeader.css'
|
|
2
|
+
import { FC, useState } from 'react'
|
|
3
|
+
import { User } from '../../models/User'
|
|
4
|
+
import { Dropdown } from '../Dropdown/Dropdown'
|
|
5
|
+
import { UserBadge } from '../UserBadge/UserBadge'
|
|
6
|
+
import { IContainer, isNotEmpty } from '@stone-js/core'
|
|
7
|
+
import { ISecurityService } from '../../services/contracts/ISecurityService'
|
|
8
|
+
import { IRouter, ReactIncomingEvent, StoneLink } from '@stone-js/use-react'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* LayoutHeader options.
|
|
12
|
+
*/
|
|
13
|
+
export interface LayoutHeaderOptions {
|
|
14
|
+
container: IContainer
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* LayoutHeader component.
|
|
19
|
+
*/
|
|
20
|
+
export const LayoutHeader: FC<LayoutHeaderOptions> = ({ container }) => {
|
|
21
|
+
const router = container.make<IRouter>('router')
|
|
22
|
+
const [showDropdown, setShowDropdown] = useState(false)
|
|
23
|
+
const securityService = container.make<ISecurityService>('securityService')
|
|
24
|
+
const user = container.make<ReactIncomingEvent>('event').getUser<User>() ?? {} as unknown as User
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<nav className='app-navbar'>
|
|
28
|
+
<div className='header-left'>
|
|
29
|
+
<StoneLink to='/' className='logo'>
|
|
30
|
+
<img src='/logo.png' alt='Stone.js Logo' />
|
|
31
|
+
<span>Stone.js</span>
|
|
32
|
+
</StoneLink>
|
|
33
|
+
</div>
|
|
34
|
+
{isNotEmpty<User>(user) && (
|
|
35
|
+
<div className='header-right'>
|
|
36
|
+
<div className='dropdown-wrapper'>
|
|
37
|
+
<UserBadge withLink={false} user={user} onClick={() => setShowDropdown(!showDropdown)} />
|
|
38
|
+
<Dropdown show={showDropdown} onClose={() => setShowDropdown(false)}>
|
|
39
|
+
<ul className='dropdown-menu'>
|
|
40
|
+
<li><StoneLink to={`/users/${user.id}`}>Show Profile</StoneLink></li>
|
|
41
|
+
<li><StoneLink to={`/users/${user.id}/edit`}>Manage Profile</StoneLink></li>
|
|
42
|
+
<li><button onClick={logout.bind(this, router, securityService)}>Logout</button></li>
|
|
43
|
+
</ul>
|
|
44
|
+
</Dropdown>
|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
47
|
+
)}
|
|
48
|
+
</nav>
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Logout the user.
|
|
54
|
+
*/
|
|
55
|
+
export function logout (router: IRouter, securityService: ISecurityService): void {
|
|
56
|
+
if (window.confirm('Are you sure you want to logout?')) {
|
|
57
|
+
securityService.logout().then(() => {
|
|
58
|
+
router.navigate('/', true)
|
|
59
|
+
}).catch(() => {})
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
.main-nav {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
gap: 1rem;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.nav-btn {
|
|
8
|
+
font-size: 1.1rem;
|
|
9
|
+
padding: 0.75rem 1rem;
|
|
10
|
+
text-align: left;
|
|
11
|
+
font-weight: 600;
|
|
12
|
+
border-radius: 9999px;
|
|
13
|
+
color: #1f2937;
|
|
14
|
+
text-decoration: none;
|
|
15
|
+
transition: background-color 0.2s ease;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.nav-btn.selected {
|
|
19
|
+
font-weight: bolder;
|
|
20
|
+
background-color: #fff;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.nav-btn:hover {
|
|
24
|
+
background-color: #fdfeff;
|
|
25
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import './LayoutLeftMenu.css'
|
|
2
|
+
import { FC } from 'react'
|
|
3
|
+
import { User } from '../../models/User'
|
|
4
|
+
import { IContainer, isNotEmpty } from '@stone-js/core'
|
|
5
|
+
import { ReactIncomingEvent, StoneLink } from '@stone-js/use-react'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* LayoutLeftMenu options.
|
|
9
|
+
*/
|
|
10
|
+
export interface LayoutLeftMenuOptions {
|
|
11
|
+
container: IContainer
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* LayoutLeftMenu component.
|
|
16
|
+
*/
|
|
17
|
+
export const LayoutLeftMenu: FC<LayoutLeftMenuOptions> = ({ container }) => {
|
|
18
|
+
const user = container.make<ReactIncomingEvent>('event').getUser<User>() ?? {} as unknown as User
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<nav className='main-nav'>
|
|
22
|
+
<StoneLink to='/' className='nav-btn'>Home</StoneLink>
|
|
23
|
+
<StoneLink to='/users' className='nav-btn'>Users</StoneLink>
|
|
24
|
+
{isNotEmpty<User>(user) && (
|
|
25
|
+
<>
|
|
26
|
+
<StoneLink to={`/users/${user.id}`} className='nav-btn'>Profile</StoneLink>
|
|
27
|
+
<StoneLink to='/settings' className='nav-btn'>Settings</StoneLink>
|
|
28
|
+
</>
|
|
29
|
+
)}
|
|
30
|
+
</nav>
|
|
31
|
+
)
|
|
32
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import './LoginForm.css'
|
|
2
|
+
import { FC, useRef } from 'react'
|
|
3
|
+
import { UserLogin } from '../../models/User'
|
|
4
|
+
import { StoneLink } from '@stone-js/use-react'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Login Form Options
|
|
8
|
+
*/
|
|
9
|
+
export interface LoginFormOptions {
|
|
10
|
+
error: boolean
|
|
11
|
+
onSubmit: (user: UserLogin) => Promise<void>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Login Form component.
|
|
16
|
+
*
|
|
17
|
+
* @param options - The options to create the Login Form component.
|
|
18
|
+
*/
|
|
19
|
+
export const LoginForm: FC<LoginFormOptions> = ({ error, onSubmit }) => {
|
|
20
|
+
// Create a reference to the login
|
|
21
|
+
const loginRef = useRef<UserLogin>({
|
|
22
|
+
email: '',
|
|
23
|
+
password: ''
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
// Handle the form submit
|
|
27
|
+
const handleSubmit = (event: React.FormEvent<HTMLFormElement>): void => {
|
|
28
|
+
event.preventDefault()
|
|
29
|
+
void onSubmit(loginRef.current).catch(() => {})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Handle the field change
|
|
33
|
+
const onChange = (field: keyof UserLogin) => (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
34
|
+
loginRef.current[field] = event.target.value
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Render the component
|
|
38
|
+
return (
|
|
39
|
+
<>
|
|
40
|
+
<form onSubmit={handleSubmit} className='panel'>
|
|
41
|
+
{error && <p className='alert alert-danger alert-small'>Invalid email or password</p>}
|
|
42
|
+
|
|
43
|
+
<div>
|
|
44
|
+
<label htmlFor='email' className='label'>Email:</label>
|
|
45
|
+
<input
|
|
46
|
+
id='email'
|
|
47
|
+
type='email'
|
|
48
|
+
className='input'
|
|
49
|
+
placeholder='Enter your email'
|
|
50
|
+
onChange={onChange('email')} defaultValue={loginRef.current.email}
|
|
51
|
+
/>
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
<div className='mt-8'>
|
|
55
|
+
<label htmlFor='password' className='label'>Password:</label>
|
|
56
|
+
<input
|
|
57
|
+
id='password'
|
|
58
|
+
type='password'
|
|
59
|
+
className='input'
|
|
60
|
+
placeholder='Enter your password'
|
|
61
|
+
onChange={onChange('password')} defaultValue={loginRef.current.password}
|
|
62
|
+
/>
|
|
63
|
+
</div>
|
|
64
|
+
<button type='submit' className='button button-secondary button-full mt-24'>Login</button>
|
|
65
|
+
</form>
|
|
66
|
+
<p className='mt-24 text-center'>
|
|
67
|
+
<StoneLink to='/register' className='button button-primary'>Register</StoneLink>
|
|
68
|
+
</p>
|
|
69
|
+
</>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
.dropdown-menu li {
|
|
2
|
+
display: flex;
|
|
3
|
+
justify-content: space-between;
|
|
4
|
+
align-items: center;
|
|
5
|
+
gap: 0.5rem;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.dropdown-menu li.unread {
|
|
9
|
+
font-weight: 600;
|
|
10
|
+
background: #eef2ff;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.dropdown-menu li.read {
|
|
14
|
+
font-weight: 400;
|
|
15
|
+
background: white;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.notification-time {
|
|
19
|
+
font-size: 0.7rem;
|
|
20
|
+
color: #888;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.notification-button {
|
|
24
|
+
background: none;
|
|
25
|
+
border: none;
|
|
26
|
+
font-size: 1.2rem;
|
|
27
|
+
position: relative;
|
|
28
|
+
cursor: pointer;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.notification-count {
|
|
32
|
+
position: absolute;
|
|
33
|
+
top: -4px;
|
|
34
|
+
right: -6px;
|
|
35
|
+
background-color: #ef4444;
|
|
36
|
+
color: white;
|
|
37
|
+
font-size: 0.65rem;
|
|
38
|
+
padding: 2px 5px;
|
|
39
|
+
border-radius: 9999px;
|
|
40
|
+
font-weight: bold;
|
|
41
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import './NotificationBadge.css'
|
|
2
|
+
import { FC, useState } from 'react'
|
|
3
|
+
import { dateTimeFromNow } from '../../utils'
|
|
4
|
+
import { Dropdown } from '../Dropdown/Dropdown'
|
|
5
|
+
import { StoneLink } from '@stone-js/use-react'
|
|
6
|
+
|
|
7
|
+
interface Notification {
|
|
8
|
+
id: number
|
|
9
|
+
message: string
|
|
10
|
+
link?: string
|
|
11
|
+
createdAt: number
|
|
12
|
+
read?: boolean
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface NotificationBadgeOptions {
|
|
16
|
+
notifications: Notification[]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const NotificationBadge: FC<NotificationBadgeOptions> = ({ notifications: initial }) => {
|
|
20
|
+
const [open, setOpen] = useState(false)
|
|
21
|
+
const [notifications, setNotifications] = useState(initial)
|
|
22
|
+
|
|
23
|
+
const handleClick = (id: number): void => {
|
|
24
|
+
setNotifications(prev =>
|
|
25
|
+
prev.map(n => (n.id === id ? { ...n, read: true } : n))
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const unreadCount = notifications.filter(n => n.read !== undefined).length
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<div className='dropdown-wrapper'>
|
|
33
|
+
<button className='notification-button' onClick={() => setOpen(!open)}>
|
|
34
|
+
🔔
|
|
35
|
+
{unreadCount > 0 && (
|
|
36
|
+
<span className='notification-count'>{unreadCount}</span>
|
|
37
|
+
)}
|
|
38
|
+
</button>
|
|
39
|
+
<Dropdown show={open} onClose={() => setOpen(false)} align='right'>
|
|
40
|
+
<ul className='dropdown-menu'>
|
|
41
|
+
{notifications.length === 0
|
|
42
|
+
? (
|
|
43
|
+
<li>No new notifications</li>
|
|
44
|
+
)
|
|
45
|
+
: (
|
|
46
|
+
notifications.map(n => (
|
|
47
|
+
<li
|
|
48
|
+
key={n.id}
|
|
49
|
+
className={n.read !== undefined ? 'read' : 'unread'}
|
|
50
|
+
onClick={() => handleClick(n.id)}
|
|
51
|
+
>
|
|
52
|
+
{n.link !== undefined ? <StoneLink to={n.link}>{n.message}</StoneLink> : n.message}
|
|
53
|
+
<span className='notification-time'>
|
|
54
|
+
{dateTimeFromNow(n.createdAt)}
|
|
55
|
+
</span>
|
|
56
|
+
</li>
|
|
57
|
+
))
|
|
58
|
+
)}
|
|
59
|
+
</ul>
|
|
60
|
+
</Dropdown>
|
|
61
|
+
</div>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
.post-card {
|
|
2
|
+
background: #ffffff;
|
|
3
|
+
border: 1px solid #e5e7eb;
|
|
4
|
+
border-radius: 12px;
|
|
5
|
+
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
|
|
6
|
+
padding: 1rem;
|
|
7
|
+
margin-top: 1.5rem;
|
|
8
|
+
transition: box-shadow 0.2s ease;
|
|
9
|
+
max-width: 100%;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.post-card:hover {
|
|
13
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.post-header {
|
|
17
|
+
display: flex;
|
|
18
|
+
align-items: center;
|
|
19
|
+
gap: 0.75rem;
|
|
20
|
+
margin-bottom: 0.75rem;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.post-content p {
|
|
24
|
+
margin: 0.5rem 0;
|
|
25
|
+
line-height: 1.5;
|
|
26
|
+
color: #1c1e21;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.post-image {
|
|
30
|
+
margin-top: 0.75rem;
|
|
31
|
+
border-radius: 8px;
|
|
32
|
+
overflow: hidden;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.post-image img {
|
|
36
|
+
width: 100%;
|
|
37
|
+
height: auto;
|
|
38
|
+
display: block;
|
|
39
|
+
border-radius: 8px;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/* Responsive */
|
|
43
|
+
@media (max-width: 600px) {
|
|
44
|
+
.post-card {
|
|
45
|
+
padding: 0.75rem;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.post-avatar {
|
|
49
|
+
width: 36px;
|
|
50
|
+
height: 36px;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.post-author strong {
|
|
54
|
+
font-size: 0.875rem;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.post-author span {
|
|
58
|
+
font-size: 0.7rem;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.post-actions {
|
|
63
|
+
margin-left: auto;
|
|
64
|
+
position: relative;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.menu-toggle {
|
|
68
|
+
background: none;
|
|
69
|
+
border: none;
|
|
70
|
+
font-size: 1.25rem;
|
|
71
|
+
cursor: pointer;
|
|
72
|
+
color: #666;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.post-dropdown {
|
|
76
|
+
position: absolute;
|
|
77
|
+
top: 1.5rem;
|
|
78
|
+
right: 0;
|
|
79
|
+
background: #fff;
|
|
80
|
+
border: 1px solid #ddd;
|
|
81
|
+
border-radius: 8px;
|
|
82
|
+
box-shadow: 0 2px 8px rgba(0,0,0,0.06);
|
|
83
|
+
list-style: none;
|
|
84
|
+
padding: 0.25rem 0;
|
|
85
|
+
width: 140px;
|
|
86
|
+
z-index: 20;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.post-dropdown li {
|
|
90
|
+
padding: 0.5rem 1rem;
|
|
91
|
+
cursor: pointer;
|
|
92
|
+
font-size: 0.875rem;
|
|
93
|
+
color: #333;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.post-dropdown li:hover {
|
|
97
|
+
background: #f0f2f5;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/* Post Footer Buttons */
|
|
101
|
+
.post-footer {
|
|
102
|
+
display: flex;
|
|
103
|
+
justify-content: space-around;
|
|
104
|
+
margin-top: 1rem;
|
|
105
|
+
padding-top: 0.5rem;
|
|
106
|
+
border-top: 1px solid #e5e7eb;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.post-comments {
|
|
110
|
+
margin-top: 0.5rem;
|
|
111
|
+
padding-top: 1rem;
|
|
112
|
+
border-top: 1px solid #e5e7eb;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.post-action {
|
|
116
|
+
background: none;
|
|
117
|
+
border: none;
|
|
118
|
+
color: #555;
|
|
119
|
+
font-size: 0.9rem;
|
|
120
|
+
cursor: pointer;
|
|
121
|
+
padding: 0.5rem 1rem;
|
|
122
|
+
border-radius: 8px;
|
|
123
|
+
transition: background-color 0.2s ease;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.post-action:hover {
|
|
127
|
+
background-color: #f0f2f5;
|
|
128
|
+
color: #111;
|
|
129
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Post } from '../../models/Post'
|
|
2
|
+
import { User } from '../../models/User'
|
|
3
|
+
import { FC, ReactNode, useState } from 'react'
|
|
4
|
+
import { UserBadge } from '../UserBadge/UserBadge'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* PostCard options.
|
|
8
|
+
*/
|
|
9
|
+
interface PostCardOptions {
|
|
10
|
+
post: Post
|
|
11
|
+
currentUser?: User
|
|
12
|
+
children: ReactNode
|
|
13
|
+
onEdit?: (post: Post) => void
|
|
14
|
+
onDelete: (post: Post) => Promise<void>
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* PostCard component.
|
|
19
|
+
*/
|
|
20
|
+
export const PostCard: FC<PostCardOptions> = ({ children, post, currentUser, onEdit, onDelete }) => {
|
|
21
|
+
const [showMenu, setShowMenu] = useState(false)
|
|
22
|
+
const [showComment, setShowComment] = useState(post.commentsCount > 0)
|
|
23
|
+
|
|
24
|
+
const isOwner = post.authorId === currentUser?.id
|
|
25
|
+
|
|
26
|
+
const deletePost = (): void => {
|
|
27
|
+
void onDelete?.(post).catch(() => {})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<article className='post-card'>
|
|
32
|
+
<header className='post-header'>
|
|
33
|
+
<UserBadge user={post.author} createdAt={post.createdAt} />
|
|
34
|
+
{isOwner && (
|
|
35
|
+
<div className='post-actions'>
|
|
36
|
+
<button className='menu-toggle' onClick={() => setShowMenu(!showMenu)}>⋮</button>
|
|
37
|
+
{showMenu && (
|
|
38
|
+
<ul className='post-dropdown'>
|
|
39
|
+
<li onClick={() => onEdit?.(post)}>✏️ Edit</li>
|
|
40
|
+
<li onClick={deletePost}>🗑️ Delete</li>
|
|
41
|
+
</ul>
|
|
42
|
+
)}
|
|
43
|
+
</div>
|
|
44
|
+
)}
|
|
45
|
+
</header>
|
|
46
|
+
|
|
47
|
+
<div className='post-content'>
|
|
48
|
+
{post.content !== undefined && <p>{post.content}</p>}
|
|
49
|
+
{post.imagePath !== undefined && (
|
|
50
|
+
<div className='post-image'>
|
|
51
|
+
<img src={post.imagePath} alt='Post' />
|
|
52
|
+
</div>
|
|
53
|
+
)}
|
|
54
|
+
</div>
|
|
55
|
+
|
|
56
|
+
<footer className='post-footer'>
|
|
57
|
+
<button className='post-action'>👍 Like</button>
|
|
58
|
+
<button className='post-action' onClick={() => setShowComment(!showComment)}>💬 Comment</button>
|
|
59
|
+
<button className='post-action'>🔁 Share</button>
|
|
60
|
+
</footer>
|
|
61
|
+
|
|
62
|
+
{showComment && <div className='post-comments'>{children}</div>}
|
|
63
|
+
</article>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
.post-form {
|
|
2
|
+
background: #ffffff;
|
|
3
|
+
border-radius: 12px;
|
|
4
|
+
padding: 1rem 1.25rem;
|
|
5
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
|
|
6
|
+
border: 1px solid #e5e7eb;
|
|
7
|
+
display: flex;
|
|
8
|
+
flex-direction: column;
|
|
9
|
+
gap: 0.75rem;
|
|
10
|
+
max-width: 100%;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.post-textarea {
|
|
14
|
+
resize: none;
|
|
15
|
+
padding: 0.75rem 1rem;
|
|
16
|
+
border: 1px solid #d1d5db;
|
|
17
|
+
border-radius: 8px;
|
|
18
|
+
font-size: 1rem;
|
|
19
|
+
width: 100%;
|
|
20
|
+
min-height: 60px;
|
|
21
|
+
background: #f9fafb;
|
|
22
|
+
outline: none;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.post-textarea:focus {
|
|
26
|
+
border-color: #2563eb;
|
|
27
|
+
background-color: #ffffff;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.image-preview {
|
|
31
|
+
position: relative;
|
|
32
|
+
width: fit-content;
|
|
33
|
+
max-width: 100%;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.image-preview img {
|
|
37
|
+
max-width: 100%;
|
|
38
|
+
border-radius: 8px;
|
|
39
|
+
margin-top: 0.5rem;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.remove-image-btn {
|
|
43
|
+
position: absolute;
|
|
44
|
+
top: 8px;
|
|
45
|
+
right: 8px;
|
|
46
|
+
background: rgba(255, 255, 255, 0.85);
|
|
47
|
+
border: none;
|
|
48
|
+
border-radius: 50%;
|
|
49
|
+
cursor: pointer;
|
|
50
|
+
font-weight: bold;
|
|
51
|
+
padding: 0.2rem 0.5rem;
|
|
52
|
+
color: #111;
|
|
53
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.post-form-footer {
|
|
57
|
+
display: flex;
|
|
58
|
+
justify-content: space-between;
|
|
59
|
+
align-items: center;
|
|
60
|
+
padding-top: 0.5rem;
|
|
61
|
+
border-top: 1px solid #e5e7eb;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.upload-btn {
|
|
65
|
+
cursor: pointer;
|
|
66
|
+
color: #2563eb;
|
|
67
|
+
font-weight: 500;
|
|
68
|
+
font-size: 0.95rem;
|
|
69
|
+
display: inline-flex;
|
|
70
|
+
align-items: center;
|
|
71
|
+
gap: 0.25rem;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.submit-btn {
|
|
75
|
+
background: #2563eb;
|
|
76
|
+
color: white;
|
|
77
|
+
border: none;
|
|
78
|
+
border-radius: 6px;
|
|
79
|
+
padding: 0.5rem 1rem;
|
|
80
|
+
font-weight: 500;
|
|
81
|
+
cursor: pointer;
|
|
82
|
+
transition: background 0.2s ease;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.submit-btn:hover:not(:disabled) {
|
|
86
|
+
background: #1e40af;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.submit-btn:disabled {
|
|
90
|
+
background: #cbd5e1;
|
|
91
|
+
cursor: not-allowed;
|
|
92
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import './PostForm.css'
|
|
2
|
+
import { PostInput } from '../../models/Post'
|
|
3
|
+
import { ChangeEvent, FC, FormEvent, useRef, useState } from 'react'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Post Form Options
|
|
7
|
+
*/
|
|
8
|
+
export interface PostFormOptions {
|
|
9
|
+
post?: PostInput
|
|
10
|
+
onSubmit: (post: PostInput) => Promise<void>
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const PostForm: FC<PostFormOptions> = ({ post, onSubmit }) => {
|
|
14
|
+
const [text, setText] = useState(post?.content ?? '')
|
|
15
|
+
const fileInputRef = useRef<HTMLInputElement>(null)
|
|
16
|
+
const [imagePreview, setImagePreview] = useState<string | undefined>(undefined)
|
|
17
|
+
|
|
18
|
+
const handleImageChange = (e: ChangeEvent<HTMLInputElement>): void => {
|
|
19
|
+
const file = e.target.files?.[0]
|
|
20
|
+
if (file != null) {
|
|
21
|
+
const reader = new FileReader()
|
|
22
|
+
reader.onloadend = () => setImagePreview(reader.result as string)
|
|
23
|
+
reader.readAsDataURL(file)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const handleRemoveImage = (): void => {
|
|
28
|
+
setImagePreview(undefined)
|
|
29
|
+
if (fileInputRef.current != null) fileInputRef.current.value = ''
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const handleSubmit = (e: FormEvent): void => {
|
|
33
|
+
e.preventDefault()
|
|
34
|
+
// Handle form submission logic here
|
|
35
|
+
onSubmit({
|
|
36
|
+
content: text,
|
|
37
|
+
title: text.substring(0, 32) // Assuming title is the first 32 characters of content
|
|
38
|
+
// image: imagePreview ? { url: imagePreview } : undefined
|
|
39
|
+
}).catch(() => {})
|
|
40
|
+
setText('')
|
|
41
|
+
handleRemoveImage()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<form className='post-form' onSubmit={handleSubmit}>
|
|
46
|
+
<textarea
|
|
47
|
+
className='post-textarea'
|
|
48
|
+
placeholder="What's on your mind?"
|
|
49
|
+
value={text}
|
|
50
|
+
onChange={(e) => setText(e.target.value)}
|
|
51
|
+
rows={3}
|
|
52
|
+
/>
|
|
53
|
+
{imagePreview !== undefined && (
|
|
54
|
+
<div className='image-preview'>
|
|
55
|
+
<img src={imagePreview} alt='Preview' />
|
|
56
|
+
<button type='button' onClick={handleRemoveImage} className='remove-image-btn'>✕</button>
|
|
57
|
+
</div>
|
|
58
|
+
)}
|
|
59
|
+
<div className='post-form-footer'>
|
|
60
|
+
<label className='upload-btn'>
|
|
61
|
+
📷 Photo
|
|
62
|
+
<input
|
|
63
|
+
type='file'
|
|
64
|
+
accept='image/*'
|
|
65
|
+
onChange={handleImageChange}
|
|
66
|
+
ref={fileInputRef}
|
|
67
|
+
hidden
|
|
68
|
+
/>
|
|
69
|
+
</label>
|
|
70
|
+
<button className='submit-btn' type='submit' disabled={text.trim().length === 0 && imagePreview === undefined}>
|
|
71
|
+
Publish
|
|
72
|
+
</button>
|
|
73
|
+
</div>
|
|
74
|
+
</form>
|
|
75
|
+
)
|
|
76
|
+
}
|