| 
				
				
					
				
				
				 | 
			
			 | 
			@@ -8,10 +8,11 @@ import SectionTitle from '@/components/common/SectionTitle' | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			import SidebarComponent from '@/components/layout/SidebarComponent' | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			import { API_BASE_URL } from '@/config' | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			import { CATEGORIES } from '@/consts' | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			import { cn } from '@/lib/utils' | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
  | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			import type { Post, Tag } from '@/types' | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
  | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			type TagByCategory = { [key: string]: Tag[] } | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			type TagByCategory = Record<string, Tag[]> | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
  | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			type Props = { posts: Post[] } | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
  | 
		
		
	
	
		
			
				| 
				
				
				
					
				
				 | 
			
			 | 
			@@ -19,6 +20,7 @@ type Props = { posts: Post[] } | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			export default ({ posts }: Props) => { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			  const navigate = useNavigate () | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
  | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			  const [tagsVsbl, setTagsVsbl] = useState (false) | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			  const [tags, setTags] = useState<TagByCategory> ({ }) | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
  | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			  const location = useLocation () | 
		
		
	
	
		
			
				| 
				
					
				
				
					
				
				
				 | 
			
			 | 
			@@ -57,34 +59,44 @@ export default ({ posts }: Props) => { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			  return ( | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			      <SidebarComponent> | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				<TagSearch /> | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				<SectionTitle>タグ</SectionTitle> | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				<ul> | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				  {CATEGORIES.flatMap (cat => cat in tags ? ( | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				      tags[cat].map (tag => ( | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					  <li key={tag.id} className="mb-1"> | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					    <TagLink tag={tag} /> | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					  </li>))) : [])} | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				</ul> | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				<SectionTitle>関聯</SectionTitle> | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				{posts.length > 0 && ( | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				    <a href="#" | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				       onClick={ev => { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					 ev.preventDefault () | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					 void ((async () => { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					   try | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					   { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					     const { data } = await axios.get (`${ API_BASE_URL }/posts/random`, | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
						 { params: { tags:  tagsQuery.split (' ').filter (e => e !== '').join (','), | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
							     match: (anyFlg ? 'any' : 'all') } }) | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					     navigate (`/posts/${ (data as Post).id }`) | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					   } | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					   catch | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					   { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					     ; | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					   } | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					 }) ()) | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				       }}> | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				      ランダム | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				    </a>)} | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				<div className={cn (!(tagsVsbl) && 'hidden', 'md:block mt-4')}> | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				  <SectionTitle>タグ</SectionTitle> | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				  <ul> | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				    {CATEGORIES.flatMap (cat => cat in tags ? ( | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					tags[cat].map (tag => ( | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					    <li key={tag.id} className="mb-1"> | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					      <TagLink tag={tag} /> | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					    </li>))) : [])} | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				  </ul> | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				  <SectionTitle>関聯</SectionTitle> | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				  {posts.length > 0 && ( | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				      <a href="#" | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					 onClick={ev => { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					   ev.preventDefault () | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					   void ((async () => { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					     try | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					     { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					       const { data } = await axios.get (`${ API_BASE_URL }/posts/random`, | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
						   { params: { tags:  tagsQuery.split (' ').filter (e => e !== '').join (','), | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
							       match: (anyFlg ? 'any' : 'all') } }) | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					       navigate (`/posts/${ (data as Post).id }`) | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					     } | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					     catch | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					     { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					       ; | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					     } | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					   }) ()) | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					 }}> | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					ランダム | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				      </a>)} | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				</div> | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				<a href="#" | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				   className="md:hidden block my-2 text-center text-sm text-gray-500" | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				   onClick={ev => { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				     ev.preventDefault () | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				     setTagsVsbl (!(tagsVsbl)) | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				   }}> | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				  {tagsVsbl ? '▲▲▲ タグ一覧を閉じる ▲▲▲' : '▼▼▼ タグ一覧を表示 ▼▼▼'} | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				</a> | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			      </SidebarComponent>) | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			} |