コミットを比較
2
コミット
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
|
|
4a7296eea0 | ||
|
|
2b18d72f7a |
@@ -5,7 +5,6 @@ class MaterialVersionsController < ApplicationController
|
|||||||
|
|
||||||
page = 1 if page < 1
|
page = 1 if page < 1
|
||||||
limit = 1 if limit < 1
|
limit = 1 if limit < 1
|
||||||
limit = 100 if limit > 100
|
|
||||||
|
|
||||||
offset = (page - 1) * limit
|
offset = (page - 1) * limit
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ class MaterialsController < ApplicationController
|
|||||||
|
|
||||||
page = 1 if page < 1
|
page = 1 if page < 1
|
||||||
limit = 1 if limit < 1
|
limit = 1 if limit < 1
|
||||||
limit = 100 if limit > 100
|
|
||||||
|
|
||||||
offset = (page - 1) * limit
|
offset = (page - 1) * limit
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ class NicoTagsController < ApplicationController
|
|||||||
|
|
||||||
page = 1 if page < 1
|
page = 1 if page < 1
|
||||||
limit = 1 if limit < 1
|
limit = 1 if limit < 1
|
||||||
limit = 100 if limit > 100
|
|
||||||
|
|
||||||
post_tag_max_sql =
|
post_tag_max_sql =
|
||||||
PostExternalTag
|
PostExternalTag
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ class PostVersionsController < ApplicationController
|
|||||||
|
|
||||||
page = 1 if page < 1
|
page = 1 if page < 1
|
||||||
limit = 1 if limit < 1
|
limit = 1 if limit < 1
|
||||||
limit = 100 if limit > 100
|
|
||||||
|
|
||||||
offset = (page - 1) * limit
|
offset = (page - 1) * limit
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ class PostsController < ApplicationController
|
|||||||
|
|
||||||
page = 1 if page < 1
|
page = 1 if page < 1
|
||||||
limit = 1 if limit < 1
|
limit = 1 if limit < 1
|
||||||
limit = 100 if limit > 100
|
|
||||||
|
|
||||||
offset = (page - 1) * limit
|
offset = (page - 1) * limit
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ class TagVersionsController < ApplicationController
|
|||||||
|
|
||||||
page = 1 if page < 1
|
page = 1 if page < 1
|
||||||
limit = 1 if limit < 1
|
limit = 1 if limit < 1
|
||||||
limit = 100 if limit > 100
|
|
||||||
|
|
||||||
offset = (page - 1) * limit
|
offset = (page - 1) * limit
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ class TagsController < ApplicationController
|
|||||||
|
|
||||||
page = 1 if page < 1
|
page = 1 if page < 1
|
||||||
limit = 1 if limit < 1
|
limit = 1 if limit < 1
|
||||||
limit = 100 if limit > 100
|
|
||||||
|
|
||||||
offset = (page - 1) * limit
|
offset = (page - 1) * limit
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ class TheatreCommentsController < ApplicationController
|
|||||||
def index
|
def index
|
||||||
limit = params[:limit].to_i
|
limit = params[:limit].to_i
|
||||||
limit = 20 if limit <= 0
|
limit = 20 if limit <= 0
|
||||||
limit = 100 if limit > 100
|
|
||||||
|
|
||||||
no_gt = params[:no_gt].to_i
|
no_gt = params[:no_gt].to_i
|
||||||
no_gt = 0 if no_gt < 0
|
no_gt = 0 if no_gt < 0
|
||||||
@@ -10,7 +9,6 @@ class TheatreCommentsController < ApplicationController
|
|||||||
comments = TheatreComment
|
comments = TheatreComment
|
||||||
.where(theatre_id: params[:theatre_id])
|
.where(theatre_id: params[:theatre_id])
|
||||||
.where('no > ?', no_gt)
|
.where('no > ?', no_gt)
|
||||||
.includes(:user)
|
|
||||||
.order(no: :desc)
|
.order(no: :desc)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ class TheatreProgrammesController < ApplicationController
|
|||||||
def index
|
def index
|
||||||
limit = params[:limit].to_i
|
limit = params[:limit].to_i
|
||||||
limit = 100 if limit <= 0
|
limit = 100 if limit <= 0
|
||||||
limit = 100 if limit > 100
|
|
||||||
|
|
||||||
position_gt = params[:position_gt].to_i
|
position_gt = params[:position_gt].to_i
|
||||||
position_gt = 0 if position_gt < 0
|
position_gt = 0 if position_gt < 0
|
||||||
@@ -11,7 +10,7 @@ class TheatreProgrammesController < ApplicationController
|
|||||||
.where(theatre_id: params[:theatre_id])
|
.where(theatre_id: params[:theatre_id])
|
||||||
.where('position > ?', position_gt)
|
.where('position > ?', position_gt)
|
||||||
.includes(:post)
|
.includes(:post)
|
||||||
.order(position: :desc)
|
.order(position: :desc).limit(100)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
|
||||||
render json: programmes.map { |programme|
|
render json: programmes.map { |programme|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ class TheatreSkipEventsController < ApplicationController
|
|||||||
def index
|
def index
|
||||||
limit = params[:limit].to_i
|
limit = params[:limit].to_i
|
||||||
limit = 50 if limit <= 0
|
limit = 50 if limit <= 0
|
||||||
limit = 100 if limit > 100
|
|
||||||
|
|
||||||
events =
|
events =
|
||||||
TheatreSkipEvent
|
TheatreSkipEvent
|
||||||
|
|||||||
@@ -6,6 +6,11 @@ class WikiPagesController < ApplicationController
|
|||||||
def index
|
def index
|
||||||
locale = resolve_locale!
|
locale = resolve_locale!
|
||||||
|
|
||||||
|
resource_type = params[:resource_type]
|
||||||
|
unless resource_type.nil? || ['tag_description', 'tag_group'].include?(resource_type)
|
||||||
|
return head :bad_request
|
||||||
|
end
|
||||||
|
|
||||||
title = params[:title].to_s.strip
|
title = params[:title].to_s.strip
|
||||||
descriptions =
|
descriptions =
|
||||||
HistoryAccess.current(TagDescription.all, TagDescriptionVersion)
|
HistoryAccess.current(TagDescription.all, TagDescriptionVersion)
|
||||||
@@ -14,6 +19,8 @@ class WikiPagesController < ApplicationController
|
|||||||
|
|
||||||
descriptions = descriptions.order(updated_at: :desc, id: :asc)
|
descriptions = descriptions.order(updated_at: :desc, id: :asc)
|
||||||
tag_groups = HistoryAccess.current(TagGroup.all, TagGroupVersion).order(updated_at: :desc, id: :asc)
|
tag_groups = HistoryAccess.current(TagGroup.all, TagGroupVersion).order(updated_at: :desc, id: :asc)
|
||||||
|
descriptions = descriptions.none if resource_type == 'tag_group'
|
||||||
|
tag_groups = tag_groups.none if resource_type == 'tag_description'
|
||||||
if title.present?
|
if title.present?
|
||||||
pattern = "%#{ ApplicationRecord.sanitize_sql_like(title) }%"
|
pattern = "%#{ ApplicationRecord.sanitize_sql_like(title) }%"
|
||||||
descriptions =
|
descriptions =
|
||||||
|
|||||||
@@ -1,174 +0,0 @@
|
|||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
RSpec.describe 'List API limits', type: :request do
|
|
||||||
shared_examples 'a capped list' do |default_count, minimum_count, paginated|
|
|
||||||
def response_rows
|
|
||||||
body = json
|
|
||||||
body.is_a?(Array) ? body : body.fetch(collection_key)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'caps oversized limits at 100 and preserves the 100 boundary' do
|
|
||||||
get path, params: { locale: 'ja', limit: 100 }
|
|
||||||
expect(response).to have_http_status(:ok)
|
|
||||||
expect(response_rows.size).to eq(100)
|
|
||||||
boundary_rows = response_rows
|
|
||||||
|
|
||||||
[101, 10_000].each do |limit|
|
|
||||||
get path, params: { locale: 'ja', limit: }
|
|
||||||
expect(response).to have_http_status(:ok)
|
|
||||||
expect(response_rows).to eq(boundary_rows)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'preserves the default, nonpositive and small positive limits' do
|
|
||||||
get path, params: { locale: 'ja' }
|
|
||||||
expect(response).to have_http_status(:ok)
|
|
||||||
expect(response_rows.size).to eq(default_count)
|
|
||||||
|
|
||||||
[0, -1].each do |limit|
|
|
||||||
get path, params: { locale: 'ja', limit: }
|
|
||||||
expect(response).to have_http_status(:ok)
|
|
||||||
expect(response_rows.size).to eq(minimum_count)
|
|
||||||
end
|
|
||||||
|
|
||||||
get path, params: { locale: 'ja', limit: 2 }
|
|
||||||
expect(response).to have_http_status(:ok)
|
|
||||||
expect(response_rows.size).to eq(2)
|
|
||||||
end
|
|
||||||
|
|
||||||
if paginated
|
|
||||||
it 'uses the capped limit for page offsets and preserves total count' do
|
|
||||||
get path, params: { locale: 'ja', limit: 100 }
|
|
||||||
first_page = response_rows
|
|
||||||
expect(response).to have_http_status(:ok)
|
|
||||||
expect(json.fetch('count')).to eq(101)
|
|
||||||
|
|
||||||
get path, params: { locale: 'ja', limit: 100, page: 2 }
|
|
||||||
expect(response).to have_http_status(:ok)
|
|
||||||
expect(response_rows.size).to eq(1)
|
|
||||||
second_page = response_rows
|
|
||||||
expect(first_page & second_page).to be_empty
|
|
||||||
|
|
||||||
get path, params: { locale: 'ja', limit: 101, page: 2 }
|
|
||||||
expect(response).to have_http_status(:ok)
|
|
||||||
expect(response_rows).to eq(second_page)
|
|
||||||
expect(json.fetch('count')).to eq(101)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'posts' do
|
|
||||||
let(:path) { '/posts' }
|
|
||||||
let(:collection_key) { 'posts' }
|
|
||||||
before { create_list(:post, 101) }
|
|
||||||
|
|
||||||
include_examples 'a capped list', 20, 1, true
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'tags' do
|
|
||||||
let(:path) { '/tags' }
|
|
||||||
let(:collection_key) { 'tags' }
|
|
||||||
before { create_list(:tag, 101) }
|
|
||||||
|
|
||||||
include_examples 'a capped list', 20, 1, true
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'nico tags' do
|
|
||||||
let(:path) { '/tags/nico' }
|
|
||||||
let(:collection_key) { 'tags' }
|
|
||||||
before { create_list(:external_tag, 101) }
|
|
||||||
|
|
||||||
include_examples 'a capped list', 20, 1, true
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'materials' do
|
|
||||||
let(:path) { '/materials' }
|
|
||||||
let(:collection_key) { 'materials' }
|
|
||||||
before do
|
|
||||||
101.times { |index| Material.create!(url: "https://example.com/material-#{ index }") }
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples 'a capped list', 20, 1, true
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'post versions' do
|
|
||||||
let(:path) { '/posts/versions' }
|
|
||||||
let(:collection_key) { 'versions' }
|
|
||||||
let(:post) { create(:post) }
|
|
||||||
before do
|
|
||||||
101.times do |index|
|
|
||||||
PostVersion.create!(post:, version_no: index + 1, event_type: 'update',
|
|
||||||
url: post.url, tags: '', tags_json: [], parent_post_ids: '')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples 'a capped list', 20, 1, true
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'tag versions' do
|
|
||||||
let(:path) { '/tags/versions' }
|
|
||||||
let(:collection_key) { 'versions' }
|
|
||||||
let(:tag) { create(:tag) }
|
|
||||||
before do
|
|
||||||
101.times do |index|
|
|
||||||
TagVersion.create!(tag:, version_no: index + 1, event_type: 'update',
|
|
||||||
name: 'limit tag', category: 'general', aliases: '',
|
|
||||||
parent_tag_ids: '', names: {
|
|
||||||
ja: { name: 'limit tag', script_code: 'Jpan',
|
|
||||||
auto_generated: false, aliases: [] } })
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples 'a capped list', 20, 1, true
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'material versions' do
|
|
||||||
let(:path) { '/materials/versions' }
|
|
||||||
let(:collection_key) { 'versions' }
|
|
||||||
let(:material) { Material.create!(url: 'https://example.com/material') }
|
|
||||||
before do
|
|
||||||
101.times do |index|
|
|
||||||
MaterialVersion.create!(material:, version_no: index + 1,
|
|
||||||
event_type: 'update', url: material.url)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples 'a capped list', 20, 1, true
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'theatre lists' do
|
|
||||||
let(:theatre) { create(:theatre) }
|
|
||||||
let(:post) { create(:post) }
|
|
||||||
|
|
||||||
context 'comments' do
|
|
||||||
let(:path) { "/theatres/#{ theatre.id }/comments" }
|
|
||||||
before { create_list(:theatre_comment, 101, theatre:, user: theatre.created_by_user) }
|
|
||||||
|
|
||||||
include_examples 'a capped list', 20, 20, false
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'programmes' do
|
|
||||||
let(:path) { "/theatres/#{ theatre.id }/programmes" }
|
|
||||||
before do
|
|
||||||
101.times do |index|
|
|
||||||
TheatreProgramme.create!(theatre:, post:, position: index + 1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples 'a capped list', 100, 100, false
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'skip events' do
|
|
||||||
let(:path) { "/theatres/#{ theatre.id }/skip_events" }
|
|
||||||
before do
|
|
||||||
101.times do |index|
|
|
||||||
TheatreSkipEvent.create!(theatre:, post:,
|
|
||||||
skipped_by_user: theatre.created_by_user,
|
|
||||||
created_at: Time.utc(2026, 1, 1) + index.seconds)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples 'a capped list', 50, 50, false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
+7
-1
@@ -166,7 +166,13 @@ export const pageRoutes = (
|
|||||||
robots: 'noindex', authentication: 'user' } },
|
robots: 'noindex', authentication: 'user' } },
|
||||||
{ path: ':id', element: <MaterialDetailPage/>,
|
{ path: ':id', element: <MaterialDetailPage/>,
|
||||||
handle: { preload: MaterialDetailPage.preload, sitemap: ['materials'] } }] },
|
handle: { preload: MaterialDetailPage.preload, sitemap: ['materials'] } }] },
|
||||||
{ path: 'wiki', element: <WikiSearchPage/>,
|
{ path: 'wiki', element: <LocaleRedirect to="/tag-descriptions"/>,
|
||||||
|
handle: { redirectTo: '/tag-descriptions' } },
|
||||||
|
{ path: 'tag-descriptions',
|
||||||
|
element: <WikiSearchPage key="tag_description" resourceType="tag_description"/>,
|
||||||
|
handle: { preload: WikiSearchPage.preload, sitemap: ['static'] } },
|
||||||
|
{ path: 'tag-groups',
|
||||||
|
element: <WikiSearchPage key="tag_group" resourceType="tag_group"/>,
|
||||||
handle: { preload: WikiSearchPage.preload, sitemap: ['static'] } },
|
handle: { preload: WikiSearchPage.preload, sitemap: ['static'] } },
|
||||||
{ path: 'wiki/:title', element: <WikiDetailPage/>,
|
{ path: 'wiki/:title', element: <WikiDetailPage/>,
|
||||||
handle: { preload: WikiDetailPage.preload, switchLocale: switchWikiLocale,
|
handle: { preload: WikiDetailPage.preload, switchLocale: switchWikiLocale,
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import { fetchWikiPage } from '@/lib/wiki'
|
|||||||
import type { FC, MouseEvent } from 'react'
|
import type { FC, MouseEvent } from 'react'
|
||||||
|
|
||||||
import type { AvailableLocale, LocaleCode } from '@/lib/locales'
|
import type { AvailableLocale, LocaleCode } from '@/lib/locales'
|
||||||
import type { Material, Menu, MenuVisibleItem, Tag, User } from '@/types'
|
import type { Material, Menu, MenuVisibleItem, Tag, User, WikiPage } from '@/types'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
user: User | null
|
user: User | null
|
||||||
@@ -39,10 +39,11 @@ type NavDensity = 'auto' | 'comfortable' | 'compact'
|
|||||||
|
|
||||||
|
|
||||||
export const menuOutline = (
|
export const menuOutline = (
|
||||||
{ tag, material, wikiId, user, pathName: fullPathname }: {
|
{ tag, material, wikiId, wikiResourceType, user, pathName: fullPathname }: {
|
||||||
tag?: Tag | null
|
tag?: Tag | null
|
||||||
material?: Material | null
|
material?: Material | null
|
||||||
wikiId: number | null
|
wikiId: number | null
|
||||||
|
wikiResourceType?: WikiPage['resourceType']
|
||||||
user: User | null
|
user: User | null
|
||||||
pathName: string },
|
pathName: string },
|
||||||
): Menu => {
|
): Menu => {
|
||||||
@@ -99,17 +100,30 @@ export const menuOutline = (
|
|||||||
visible: materialFlg && Boolean (material?.tag) },
|
visible: materialFlg && Boolean (material?.tag) },
|
||||||
{ ...message ('history'), to: `/materials/changes?material_id=${ material?.id }`,
|
{ ...message ('history'), to: `/materials/changes?material_id=${ material?.id }`,
|
||||||
visible: materialFlg }] },
|
visible: materialFlg }] },
|
||||||
{ ...message ('wiki'), to: '/wiki', subMenu: [
|
...([
|
||||||
{ ...message ('search'), to: '/wiki' },
|
{ key: 'tagDescriptions', path: '/tag-descriptions', type: 'tag_description' },
|
||||||
{ ...message ('create'), to: '/wiki/new', visible: editable },
|
{ key: 'tagGroups', path: '/tag-groups', type: 'tag_group' }] as const)
|
||||||
{ ...message ('allHistory'), to: '/wiki/changes' },
|
.map (({ key, path, type }): MenuVisibleItem => {
|
||||||
{ ...message ('help'), to: '/wiki/ヘルプ:Wiki' },
|
const current = (wikiResourceType ?? 'tag_description') === type
|
||||||
{ component: <Separator/>, visible: wikiPageFlg },
|
const detailFlg = wikiPageFlg && current
|
||||||
{ ...message ('postsWithCount', { count: postCount }), to: `/posts?tags=${ wikiTitle }`,
|
const creationPath =
|
||||||
visible: wikiPageFlg },
|
type === 'tag_group'
|
||||||
{ ...message ('history'), to: `/wiki/changes?id=${ wikiId }`, visible: wikiPageFlg },
|
? `/wiki/new?title=${ encodeURIComponent ('タググループ:') }` : '/wiki/new'
|
||||||
{ ...message ('edit'), to: `/wiki/${ wikiId || wikiTitle }/edit`,
|
return { ...message (key), to: path,
|
||||||
visible: wikiPageFlg && editable }] },
|
base: (pathName.startsWith ('/wiki') && current) ? '/wiki' : path,
|
||||||
|
subMenu: [
|
||||||
|
{ ...message ('search'), to: path },
|
||||||
|
{ ...message ('create'), to: creationPath, visible: editable },
|
||||||
|
{ ...message ('allHistory'), to: '/wiki/changes' },
|
||||||
|
{ ...message ('help'), to: '/wiki/ヘルプ:Wiki' },
|
||||||
|
{ component: <Separator/>, visible: detailFlg },
|
||||||
|
{ ...message ('postsWithCount', { count: postCount }),
|
||||||
|
to: `/posts?tags=${ wikiTitle }`, visible: detailFlg },
|
||||||
|
{ ...message ('history'), to: `/wiki/changes?id=${ wikiId }`,
|
||||||
|
visible: detailFlg },
|
||||||
|
{ ...message ('edit'), to: `/wiki/${ wikiId || wikiTitle }/edit`,
|
||||||
|
visible: detailFlg && editable }] }
|
||||||
|
}),
|
||||||
{ ...message ('help'), to: '/help/home', base: '/help', subMenu: [
|
{ ...message ('help'), to: '/help/home', base: '/help', subMenu: [
|
||||||
{ ...message ('search'), to: '/help' },
|
{ ...message ('search'), to: '/help' },
|
||||||
{ ...message ('allHistory'), to: '/help/changes' },
|
{ ...message ('allHistory'), to: '/help/changes' },
|
||||||
@@ -229,7 +243,8 @@ const TopNav: FC<Props> = ({ user, locales, resolveLocaleSwitch }) => {
|
|||||||
queryKey: materialsKeys.show (effectiveTitle, locale),
|
queryKey: materialsKeys.show (effectiveTitle, locale),
|
||||||
queryFn: () => fetchMaterial (effectiveTitle, locale) })
|
queryFn: () => fetchMaterial (effectiveTitle, locale) })
|
||||||
|
|
||||||
const menu = menuOutline ({ tag, material, wikiId, user, pathName: location.pathname })
|
const menu = menuOutline ({ tag, material, wikiId,
|
||||||
|
wikiResourceType: wikiPage?.resourceType, user, pathName: location.pathname })
|
||||||
const visibleMenu = menu.filter ((item): item is MenuVisibleItem => item.visible ?? true)
|
const visibleMenu = menu.filter ((item): item is MenuVisibleItem => item.visible ?? true)
|
||||||
const menuLabels = visibleMenu.map (item => item.name).join ('\u0000')
|
const menuLabels = visibleMenu.map (item => item.name).join ('\u0000')
|
||||||
const moreMenu = menu.filter (item =>
|
const moreMenu = menu.filter (item =>
|
||||||
|
|||||||
@@ -100,10 +100,11 @@ const prefetchHelpDiff: Prefetcher = async (qc, url, locale) => {
|
|||||||
|
|
||||||
const prefetchWikiPagesIndex: Prefetcher = async (qc, url, locale) => {
|
const prefetchWikiPagesIndex: Prefetcher = async (qc, url, locale) => {
|
||||||
const title = url.searchParams.get ('title') ?? ''
|
const title = url.searchParams.get ('title') ?? ''
|
||||||
|
const resourceType = url.pathname === '/tag-groups' ? 'tag_group' : 'tag_description'
|
||||||
|
|
||||||
await qc.prefetchQuery ({
|
await qc.prefetchQuery ({
|
||||||
queryKey: wikiKeys.index ({ title }, locale),
|
queryKey: wikiKeys.index ({ title, resourceType }, locale),
|
||||||
queryFn: () => fetchWikiPages ({ title }, locale) })
|
queryFn: () => fetchWikiPages ({ title, resourceType }, locale) })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -310,7 +311,8 @@ export const routePrefetchers: { test: (u: URL) => boolean; run: Prefetcher }[]
|
|||||||
&& Boolean (mPost (u.pathname))),
|
&& Boolean (mPost (u.pathname))),
|
||||||
run: prefetchPostShow },
|
run: prefetchPostShow },
|
||||||
{ test: u => u.pathname === '/posts/changes', run: prefetchPostChanges },
|
{ test: u => u.pathname === '/posts/changes', run: prefetchPostChanges },
|
||||||
{ test: u => u.pathname === '/wiki', run: prefetchWikiPagesIndex },
|
{ test: u => ['/wiki', '/tag-descriptions', '/tag-groups'].includes (u.pathname),
|
||||||
|
run: prefetchWikiPagesIndex },
|
||||||
{ test: u => (!(['/wiki/new', '/wiki/changes'].includes (u.pathname))
|
{ test: u => (!(['/wiki/new', '/wiki/changes'].includes (u.pathname))
|
||||||
&& Boolean (mWiki (u.pathname))),
|
&& Boolean (mWiki (u.pathname))),
|
||||||
run: prefetchWikiPageShow },
|
run: prefetchWikiPageShow },
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import type {
|
|||||||
FetchPostsParams,
|
FetchPostsParams,
|
||||||
FetchTagsParams,
|
FetchTagsParams,
|
||||||
MaterialFilter,
|
MaterialFilter,
|
||||||
|
WikiPage,
|
||||||
WikiTagReference } from '@/types'
|
WikiTagReference } from '@/types'
|
||||||
|
|
||||||
export const localesKeys = {
|
export const localesKeys = {
|
||||||
@@ -130,7 +131,7 @@ export const wikiKeys = {
|
|||||||
autolinkCandidates: (language: string, locale: LocaleCode) =>
|
autolinkCandidates: (language: string, locale: LocaleCode) =>
|
||||||
['wiki', 'autolink', locale, language] as const,
|
['wiki', 'autolink', locale, language] as const,
|
||||||
index: (
|
index: (
|
||||||
p: { title?: string },
|
p: { title?: string, resourceType?: WikiPage['resourceType'] },
|
||||||
locale: LocaleCode = 'ja',
|
locale: LocaleCode = 'ja',
|
||||||
) => ['wiki', locale, 'index', p] as const,
|
) => ['wiki', locale, 'index', p] as const,
|
||||||
show: (
|
show: (
|
||||||
|
|||||||
@@ -24,10 +24,10 @@ export const fetchWikiChanges = (
|
|||||||
|
|
||||||
|
|
||||||
export const fetchWikiPages = async (
|
export const fetchWikiPages = async (
|
||||||
{ title }: { title?: string },
|
{ title, resourceType }: { title?: string, resourceType?: WikiPage['resourceType'] },
|
||||||
locale: LocaleCode = 'ja',
|
locale: LocaleCode = 'ja',
|
||||||
): Promise<WikiPage[]> =>
|
): Promise<WikiPage[]> =>
|
||||||
await apiGet ('/wiki', { locale, params: { title } })
|
await apiGet ('/wiki', { locale, params: { title, resource_type: resourceType } })
|
||||||
|
|
||||||
|
|
||||||
export const fetchWikiPage = async (
|
export const fetchWikiPage = async (
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
"materials": "チカㇻペ",
|
"materials": "チカㇻペ",
|
||||||
"suppressions": "アエアイカㇷ゚テㇷ゚",
|
"suppressions": "アエアイカㇷ゚テㇷ゚",
|
||||||
"wiki": "Wiki",
|
"wiki": "Wiki",
|
||||||
|
"tagDescriptions": "$t(counts:resources.tag_descriptions)",
|
||||||
|
"tagGroups": "$t(counts:resources.tag_groups)",
|
||||||
"create": "アシㇼ",
|
"create": "アシㇼ",
|
||||||
"edit": "イヌイェㇷ゚",
|
"edit": "イヌイェㇷ゚",
|
||||||
"entertainment": "シノッ",
|
"entertainment": "シノッ",
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
"materials": "素材",
|
"materials": "素材",
|
||||||
"suppressions": "抑止",
|
"suppressions": "抑止",
|
||||||
"wiki": "Wiki",
|
"wiki": "Wiki",
|
||||||
|
"tagDescriptions": "$t(counts:resources.tag_descriptions)",
|
||||||
|
"tagGroups": "$t(counts:resources.tag_groups)",
|
||||||
"create": "新規",
|
"create": "新規",
|
||||||
"edit": "編輯",
|
"edit": "編輯",
|
||||||
"entertainment": "おたのしみ",
|
"entertainment": "おたのしみ",
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ const MaterialDetailPage: FC = () => {
|
|||||||
|
|
||||||
<TabGroup>
|
<TabGroup>
|
||||||
{material.tag && (
|
{material.tag && (
|
||||||
<Tab name={label ('navigation:wiki')}>
|
<Tab name={label ('navigation:tagDescriptions')}>
|
||||||
<WikiBody
|
<WikiBody
|
||||||
title={material.tag.name}
|
title={material.tag.name}
|
||||||
language={localeLanguage (locale)}
|
language={localeLanguage (locale)}
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ const PostListPage: FC = () => {
|
|||||||
{loading && label ('common:loading')}
|
{loading && label ('common:loading')}
|
||||||
</Tab>
|
</Tab>
|
||||||
{tags.length === 1 && (
|
{tags.length === 1 && (
|
||||||
<Tab name={label ('navigation:wiki')}>
|
<Tab name={label ('navigation:tagDescriptions')}>
|
||||||
<WikiBody title={tags[0]} body={wikiPage?.body}
|
<WikiBody title={tags[0]} body={wikiPage?.body}
|
||||||
language={wikiPage?.languageCode ?? (wikiPage?.resourceType === 'tag_description'
|
language={wikiPage?.languageCode ?? (wikiPage?.resourceType === 'tag_description'
|
||||||
? localeLanguage (locale) : 'und')}/>
|
? localeLanguage (locale) : 'und')}/>
|
||||||
|
|||||||
@@ -51,7 +51,8 @@ const WikiDetailPage: FC = () => {
|
|||||||
queryKey: helpKeys.titles ('ja'),
|
queryKey: helpKeys.titles ('ja'),
|
||||||
queryFn: () => getHelpTitleIndex ('ja'),
|
queryFn: () => getHelpTitleIndex ('ja'),
|
||||||
staleTime: Infinity })
|
staleTime: Infinity })
|
||||||
const lookupTitle = title.trim ().normalize ('NFKC').toLowerCase ().replace (/^ヘルプ:/, '')
|
const lookupTitle = title.trim ().normalize ('NFKC').toLowerCase ()
|
||||||
|
.replace (/^(?:ヘルプ|手引):/, '')
|
||||||
const identifiers = useMemo (() => (
|
const identifiers = useMemo (() => (
|
||||||
(titleIndex != null && Object.hasOwn (titleIndex, lookupTitle))
|
(titleIndex != null && Object.hasOwn (titleIndex, lookupTitle))
|
||||||
? titleIndex[lookupTitle] : []), [titleIndex, lookupTitle])
|
? titleIndex[lookupTitle] : []), [titleIndex, lookupTitle])
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import FormField from '@/components/common/FormField'
|
|||||||
import PageTitle from '@/components/common/PageTitle'
|
import PageTitle from '@/components/common/PageTitle'
|
||||||
import MainArea from '@/components/layout/MainArea'
|
import MainArea from '@/components/layout/MainArea'
|
||||||
import PageHead from '@/components/common/PageHead'
|
import PageHead from '@/components/common/PageHead'
|
||||||
import { apiGet } from '@/lib/api'
|
import { fetchWikiPages } from '@/lib/wiki'
|
||||||
import { wikiKeys } from '@/lib/queryKeys'
|
import { wikiKeys } from '@/lib/queryKeys'
|
||||||
import { dateString, inputClass } from '@/lib/utils'
|
import { dateString, inputClass } from '@/lib/utils'
|
||||||
|
|
||||||
@@ -17,16 +17,20 @@ import type { FormEvent , FC } from 'react'
|
|||||||
import type { WikiPage } from '@/types'
|
import type { WikiPage } from '@/types'
|
||||||
|
|
||||||
|
|
||||||
const WikiSearchPage: FC = () => {
|
const WikiSearchPage: FC<{ resourceType?: WikiPage['resourceType'] }> = (
|
||||||
|
{ resourceType = 'tag_description' },
|
||||||
|
) => {
|
||||||
const { message, label } = useUITranslation ('shared')
|
const { message, label } = useUITranslation ('shared')
|
||||||
const locale = useLocale ()
|
const locale = useLocale ()
|
||||||
|
const heading =
|
||||||
|
resourceType === 'tag_group'
|
||||||
|
? 'navigation:tagGroups' : 'navigation:tagDescriptions'
|
||||||
const [title, setTitle] = useState ('')
|
const [title, setTitle] = useState ('')
|
||||||
const [text, setText] = useState ('')
|
const [text, setText] = useState ('')
|
||||||
const [submittedTitle, setSubmittedTitle] = useState ('')
|
const [submittedTitle, setSubmittedTitle] = useState ('')
|
||||||
const { data: results = [], refetch } = useQuery ({
|
const { data: results = [], refetch } = useQuery ({
|
||||||
queryKey: wikiKeys.index ({ title: submittedTitle }, locale),
|
queryKey: wikiKeys.index ({ title: submittedTitle, resourceType }, locale),
|
||||||
queryFn: () => apiGet<WikiPage[]> ('/wiki', {
|
queryFn: () => fetchWikiPages ({ title: submittedTitle, resourceType }, locale) })
|
||||||
locale, params: { title: submittedTitle } }) })
|
|
||||||
|
|
||||||
const handleSearch = (ev: FormEvent) => {
|
const handleSearch = (ev: FormEvent) => {
|
||||||
ev.preventDefault ()
|
ev.preventDefault ()
|
||||||
@@ -42,10 +46,10 @@ const WikiSearchPage: FC = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<MainArea>
|
<MainArea>
|
||||||
<PageHead title={message ('navigation:wiki')}/>
|
<PageHead title={message (heading)}/>
|
||||||
|
|
||||||
<div className="max-w-xl">
|
<div className="max-w-xl">
|
||||||
<PageTitle>{label ('navigation:wiki')}</PageTitle>
|
<PageTitle>{label (heading)}</PageTitle>
|
||||||
<form onSubmit={handleSearch} className="space-y-2">
|
<form onSubmit={handleSearch} className="space-y-2">
|
||||||
{/* タイトル */}
|
{/* タイトル */}
|
||||||
<FormField label={label ('labels.title')}>
|
<FormField label={label ('labels.title')}>
|
||||||
|
|||||||
新しいイシューから参照
ユーザーをブロックする