diff --git a/backend/app/controllers/posts_controller.rb b/backend/app/controllers/posts_controller.rb index bcfc0c4..39d2ee1 100644 --- a/backend/app/controllers/posts_controller.rb +++ b/backend/app/controllers/posts_controller.rb @@ -18,13 +18,13 @@ class PostsController < ApplicationController else @posts = Post.all end - render json: @posts + render json: @posts.as_json(include: { tags: { only: [:id, :name, :category] } }) end # GET /posts/1 def show @post = Post.includes(:tags).find(params[:id]) - render json: @post.as_json(include: { tags: { only: [:id, :name] } }) + render json: @post.as_json(include: { tags: { only: [:id, :name, :category] } }) end # POST /posts diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 8b8803c..c27eb2b 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useEffect, useState } from 'react' import { BrowserRouter as Router, Route, Routes } from 'react-router-dom' import HomePage from './pages/HomePage' import TagPage from './pages/TagPage' @@ -7,28 +7,41 @@ import TagSidebar from './components/TagSidebar' import PostPage from './pages/PostPage' import PostDetailPage from './pages/PostDetailPage' +type Tag = { id: number + name: string + category: string } + +type Post = { id: number + url: string + title: string + thumbnail: string + tags: Tag[] } + + const App = () => { + const [posts, setPosts] = useState ([]) + + useEffect (() => { + alert ('このサイトはまだ作りかけです!!!!\n出てけ!!!!!!!!!!!!!!!!!!!!') + }, []) + return ( - -
- -
- - } /> - } /> - -
- - } /> - } /> - } /> - } /> - -
+ +
+ +
+ +
+ + } /> + } /> + } /> + +
+
-
- - ) + ) } + export default App diff --git a/frontend/src/components/NicoViewer.tsx b/frontend/src/components/NicoViewer.tsx index 8f1aee1..8636c53 100644 --- a/frontend/src/components/NicoViewer.tsx +++ b/frontend/src/components/NicoViewer.tsx @@ -15,23 +15,23 @@ const NicoViewer: React.FC = (props: Props) => { const iframeRef = useRef (null) const [screenWidth, setScreenWidth] = useState () const [screenHeight, setScreenHeight] = useState () - const [isLandscape, setIsLandScape] = useState (false) - const [isFullScreen, setIsFullScreen] = useState (false) + const [landscape, setLandscape] = useState (false) + const [fullScreen, setFullScreen] = useState (false) const src = `https://embed.nicovideo.jp/watch/${id}?persistence=1&oldScript=1&referer=&from=0&allowProgrammaticFullScreen=1`; - const styleFullScreen: CSSProperties = isFullScreen ? { + const styleFullScreen: CSSProperties = fullScreen ? { top: 0, - left: isLandscape ? 0 : '100%', + left: landscape ? 0 : '100%', position: 'fixed', width: screenWidth, height: screenHeight, zIndex: 2147483647, maxWidth: 'none', transformOrigin: '0% 0%', - transform: isLandscape ? 'none' : 'rotate(90deg)', + transform: landscape ? 'none' : 'rotate(90deg)', WebkitTransformOrigin: '0% 0%', - WebkitTransform: isLandscape ? 'none' : 'rotate(90deg)', + WebkitTransform: landscape ? 'none' : 'rotate(90deg)', } : {}; const margedStyle = { @@ -45,38 +45,40 @@ const NicoViewer: React.FC = (props: Props) => { const onMessage = (event: MessageEvent) => { if (!iframeRef.current || event.source !== iframeRef.current.contentWindow) return; if (event.data.eventName === 'enterProgrammaticFullScreen') { - setIsFullScreen(true); + setFullScreen(true); } else if (event.data.eventName === 'exitProgrammaticFullScreen') { - setIsFullScreen(false); + setFullScreen(false); } }; - window.addEventListener('message', onMessage); + addEventListener('message', onMessage); return () => { - window.removeEventListener('message', onMessage); + removeEventListener('message', onMessage); }; }, []); useLayoutEffect(() => { - if (!isFullScreen) return; + if (!(fullScreen)) + return - const initialScrollX = window.scrollX; - const initialScrollY = window.scrollY; - let timer: NodeJS.Timeout; - let ended = false; + const initialScrollX = window.scrollX + const initialScrollY = window.scrollY + let timer: NodeJS.Timeout + let ended = false const pollingResize = () => { - if (ended) return; + if (ended) + return - const isLandscape = window.innerWidth >= window.innerHeight; - const windowWidth = `${isLandscape ? window.innerWidth : window.innerHeight}px`; - const windowHeight = `${isLandscape ? window.innerHeight : window.innerWidth}px`; + const landscape = window.innerWidth >= window.innerHeight + const windowWidth = `${landscape ? window.innerWidth : window.innerHeight}px` + const windowHeight = `${landscape ? window.innerHeight : window.innerWidth}px` - setIsLandScape(isLandscape); - setScreenWidth(windowWidth); - setScreenHeight(windowHeight); - timer = setTimeout(startPollingResize, 200); + setLandScape (Landscape) + setScreenWidth (windowWidth) + setScreenHeight (windowHeight) + timer = setTimeout (startPollingResize, 200) } const startPollingResize = () => { @@ -94,12 +96,13 @@ const NicoViewer: React.FC = (props: Props) => { ended = true; window.scrollTo(initialScrollX, initialScrollY); }; - }, [isFullScreen]); + }, [fullScreen]); useEffect(() => { - if (!isFullScreen) return; - window.scrollTo(0, 0); - }, [screenWidth, screenHeight, isFullScreen]); + if (!(fullScreen)) + return + scrollTo (0, 0) + }, [screenWidth, screenHeight, fullScreen]) return