コミットを比較
3 コミット
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
| 69d111a133 | |||
| b3405a2d8d | |||
| cbade1cd83 |
@@ -30,7 +30,7 @@ class PostsController < ApplicationController
|
|||||||
viewed = current_user&.viewed?(post) || false
|
viewed = current_user&.viewed?(post) || false
|
||||||
|
|
||||||
render json: (post
|
render json: (post
|
||||||
.as_json(include: { tags: { only: [:id, :name, :category] } })
|
.as_json(include: { tags: { only: [:id, :name, :category, :post_count] } })
|
||||||
.merge(viewed: viewed))
|
.merge(viewed: viewed))
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ class PostsController < ApplicationController
|
|||||||
viewed = current_user&.viewed?(post) || false
|
viewed = current_user&.viewed?(post) || false
|
||||||
|
|
||||||
render json: (post
|
render json: (post
|
||||||
.as_json(include: { tags: { only: [:id, :name, :category] } })
|
.as_json(include: { tags: { only: [:id, :name, :category, :post_count] } })
|
||||||
.merge(viewed: viewed))
|
.merge(viewed: viewed))
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ class PostsController < ApplicationController
|
|||||||
if post.save
|
if post.save
|
||||||
post.resized_thumbnail!
|
post.resized_thumbnail!
|
||||||
post.tags = Tag.normalise_tags(tags_names)
|
post.tags = Tag.normalise_tags(tags_names)
|
||||||
render json: post.as_json(include: { tags: { only: [:id, :name, :category] } }),
|
render json: post.as_json(include: { tags: { only: [:id, :name, :category, :post_count] } }),
|
||||||
status: :created
|
status: :created
|
||||||
else
|
else
|
||||||
render json: { errors: post.errors.full_messages }, status: :unprocessable_entity
|
render json: { errors: post.errors.full_messages }, status: :unprocessable_entity
|
||||||
@@ -96,7 +96,7 @@ class PostsController < ApplicationController
|
|||||||
post = Post.find(params[:id].to_i)
|
post = Post.find(params[:id].to_i)
|
||||||
tags = post.tags.where(category: 'nico').to_a + Tag.normalise_tags(tag_names)
|
tags = post.tags.where(category: 'nico').to_a + Tag.normalise_tags(tag_names)
|
||||||
if post.update(title:, tags:)
|
if post.update(title:, tags:)
|
||||||
render json: post.as_json(include: { tags: { only: [:id, :name, :category] } }),
|
render json: post.as_json(include: { tags: { only: [:id, :name, :category, :post_count] } }),
|
||||||
status: :ok
|
status: :ok
|
||||||
else
|
else
|
||||||
render json: post.errors, status: :unprocessable_entity
|
render json: post.errors, status: :unprocessable_entity
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import toCamel from 'camelcase-keys'
|
import toCamel from 'camelcase-keys'
|
||||||
import { useState, useEffect } from 'react'
|
import { useState, useEffect } from 'react'
|
||||||
import { Link, useLocation, useNavigate } from 'react-router-dom'
|
import { Link, useLocation, /* useNavigate */ } from 'react-router-dom'
|
||||||
|
|
||||||
import { Button } from '@/components/ui/button'
|
|
||||||
import { API_BASE_URL } from '@/config'
|
import { API_BASE_URL } from '@/config'
|
||||||
import { WikiIdBus } from '@/lib/eventBus/WikiIdBus'
|
import { WikiIdBus } from '@/lib/eventBus/WikiIdBus'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
@@ -22,7 +21,7 @@ type Menu = typeof Menu[keyof typeof Menu]
|
|||||||
|
|
||||||
export default ({ user }: Props) => {
|
export default ({ user }: Props) => {
|
||||||
const location = useLocation ()
|
const location = useLocation ()
|
||||||
const navigate = useNavigate ()
|
// const navigate = useNavigate ()
|
||||||
|
|
||||||
const [selectedMenu, setSelectedMenu] = useState<Menu> (Menu.None)
|
const [selectedMenu, setSelectedMenu] = useState<Menu> (Menu.None)
|
||||||
const [wikiId, setWikiId] = useState<number | null> (WikiIdBus.get ())
|
const [wikiId, setWikiId] = useState<number | null> (WikiIdBus.get ())
|
||||||
@@ -116,14 +115,14 @@ export default ({ user }: Props) => {
|
|||||||
if (!(wikiId))
|
if (!(wikiId))
|
||||||
return
|
return
|
||||||
|
|
||||||
void (async () => {
|
const fetchPostCount = async () => {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
const pageRes = await axios.get (`${ API_BASE_URL }/wiki/${ wikiId }`)
|
const pageRes = await axios.get (`${ API_BASE_URL }/wiki/${ wikiId }`)
|
||||||
const wikiPage = toCamel (pageRes.data as any, { deep: true }) as WikiPage
|
const wikiPage = toCamel (pageRes.data as any, { deep: true }) as WikiPage
|
||||||
|
|
||||||
const tagRes = await axios.get (`${ API_BASE_URL }/tags/name/${ wikiPage.title }`)
|
const tagRes = await axios.get (`${ API_BASE_URL }/tags/name/${ wikiPage.title }`)
|
||||||
const tag = toCamel (tagData, { deep: true }) as Tag
|
const tag = toCamel (tagRes.data as any, { deep: true }) as Tag
|
||||||
|
|
||||||
setPostCount (tag.postCount)
|
setPostCount (tag.postCount)
|
||||||
}
|
}
|
||||||
@@ -131,7 +130,8 @@ export default ({ user }: Props) => {
|
|||||||
{
|
{
|
||||||
setPostCount (0)
|
setPostCount (0)
|
||||||
}
|
}
|
||||||
}) ()
|
}
|
||||||
|
fetchPostCount ()
|
||||||
}, [wikiId])
|
}, [wikiId])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ export default ({ user }: Props) => {
|
|||||||
'X-Transfer-Code': localStorage.getItem ('user_code') ?? '' } })
|
'X-Transfer-Code': localStorage.getItem ('user_code') ?? '' } })
|
||||||
const data = toCamel (res.data as any, { deep: true }) as Tag[]
|
const data = toCamel (res.data as any, { deep: true }) as Tag[]
|
||||||
setNicoTags (nicoTags => {
|
setNicoTags (nicoTags => {
|
||||||
nicoTags.find (t => t.id === id).linkedTags = data
|
nicoTags.find (t => t.id === id)!.linkedTags = data
|
||||||
return [...nicoTags]
|
return [...nicoTags]
|
||||||
})
|
})
|
||||||
setRawTags (rawTags => ({ ...rawTags, [id]: data.map (t => t.name).join (' ') }))
|
setRawTags (rawTags => ({ ...rawTags, [id]: data.map (t => t.name).join (' ') }))
|
||||||
|
|||||||
新しい課題から参照
ユーザをブロックする