Compare commits

..

9 Commits

Author SHA1 Message Date
みてるぞ ea93556952 #95 2026-04-13 21:04:21 +09:00
みてるぞ 584415edff #95 2026-04-13 18:33:50 +09:00
みてるぞ 27989f3bb2 #95 2026-04-12 21:05:42 +09:00
みてるぞ 0c805671a0 #95 2026-04-12 20:08:06 +09:00
みてるぞ 2a4def667c #95 2026-04-12 04:43:53 +09:00
みてるぞ 9963050546 Merge remote-tracking branch 'origin/main' into feature/095 2026-04-11 23:13:40 +09:00
みてるぞ 09ff99309f #95 2026-03-29 03:34:32 +09:00
みてるぞ e09964818f #95 2026-03-28 19:58:47 +09:00
みてるぞ 39036d1189 #95 2026-03-28 16:07:36 +09:00
16 changed files with 100 additions and 568 deletions
@@ -33,8 +33,7 @@ class NicoTagsController < ApplicationController
return head :bad_request if tag.category != 'nico' return head :bad_request if tag.category != 'nico'
linked_tag_names = params[:tags].to_s.split(' ') linked_tag_names = params[:tags].to_s.split(' ')
linked_tags = Tag.normalise_tags(linked_tag_names, with_tagme: false, linked_tags = Tag.normalise_tags(linked_tag_names, with_tagme: false)
with_no_deerjikist: false)
return head :bad_request if linked_tags.any? { |t| t.category == 'nico' } return head :bad_request if linked_tags.any? { |t| t.category == 'nico' }
tag.linked_tags = linked_tags tag.linked_tags = linked_tags
@@ -1,119 +0,0 @@
class PostVersionsController < ApplicationController
def index
post_id = params[:post].presence
tag_id = params[:tag].presence
page = (params[:page].presence || 1).to_i
limit = (params[:limit].presence || 20).to_i
page = 1 if page < 1
limit = 1 if limit < 1
offset = (page - 1) * limit
tag_name =
if tag_id
TagName.joins(:tag).find_by(tag: { id: tag_id })
end
return render json: { versions: [], count: 0 } if tag_id && tag_name.blank?
q = PostVersion.joins(<<~SQL.squish)
LEFT JOIN
post_versions prev
ON
prev.post_id = post_versions.post_id
AND prev.version_no = post_versions.version_no - 1
SQL
.select('post_versions.*', 'prev.title AS prev_title', 'prev.url AS prev_url',
'prev.thumbnail_base AS prev_thumbnail_base', 'prev.tags AS prev_tags',
'prev.original_created_from AS prev_original_created_from',
'prev.original_created_before AS prev_original_created_before')
q = q.where('post_versions.post_id = ?', post_id) if post_id
if tag_name
escaped = ActiveRecord::Base.sanitize_sql_like(tag_name.name)
q = q.where(("CONCAT(' ', post_versions.tags, ' ') LIKE :kw " +
"OR CONCAT(' ', prev.tags, ' ') LIKE :kw"),
kw: "% #{ escaped } %")
end
count = q.except(:select, :order, :limit, :offset).count
versions = q.order(Arel.sql('post_versions.created_at DESC, post_versions.id DESC'))
.limit(limit)
.offset(offset)
render json: { versions: serialise_versions(versions), count: }
end
private
def serialise_versions rows
user_ids = rows.map(&:created_by_user_id).compact.uniq
users_by_id = User.where(id: user_ids).pluck(:id, :name).to_h
rows.map do |row|
cur_tags = split_tags(row.tags)
prev_tags = split_tags(row.attributes['prev_tags'])
{
post_id: row.post_id,
version_no: row.version_no,
event_type: row.event_type,
title: {
current: row.title,
prev: row.attributes['prev_title']
},
url: {
current: row.url,
prev: row.attributes['prev_url']
},
thumbnail: {
current: nil,
prev: nil
},
thumbnail_base: {
current: row.thumbnail_base,
prev: row.attributes['prev_thumbnail_base']
},
tags: build_version_tags(cur_tags, prev_tags),
original_created_from: {
current: row.original_created_from&.iso8601,
prev: row.attributes['prev_original_created_from']&.iso8601
},
original_created_before: {
current: row.original_created_before&.iso8601,
prev: row.attributes['prev_original_created_before']&.iso8601
},
created_at: row.created_at.iso8601,
created_by_user:
if row.created_by_user_id
{
id: row.created_by_user_id,
name: users_by_id[row.created_by_user_id]
}
end
}
end
end
def build_version_tags(cur_tags, prev_tags)
(cur_tags | prev_tags).map do |name|
type =
if cur_tags.include?(name) && prev_tags.include?(name)
'context'
elsif cur_tags.include?(name)
'added'
else
'removed'
end
{
name:,
type:
}
end
end
def split_tags(tags)
tags.to_s.split(/\s+/).reject(&:blank?)
end
end
+4 -4
View File
@@ -44,7 +44,7 @@ class PostsController < ApplicationController
filtered_posts filtered_posts
.joins("LEFT JOIN (#{ pt_max_sql }) pt_max ON pt_max.post_id = posts.id") .joins("LEFT JOIN (#{ pt_max_sql }) pt_max ON pt_max.post_id = posts.id")
.reselect('posts.*', Arel.sql("#{ updated_at_all_sql } AS updated_at_all")) .reselect('posts.*', Arel.sql("#{ updated_at_all_sql } AS updated_at_all"))
.preload(tags: [:materials, { tag_name: :wiki_page }]) .preload(tags: { tag_name: :wiki_page })
.with_attached_thumbnail .with_attached_thumbnail
q = q.where('posts.url LIKE ?', "%#{ url }%") if url q = q.where('posts.url LIKE ?', "%#{ url }%") if url
@@ -95,7 +95,7 @@ class PostsController < ApplicationController
end end
def random def random
post = filtered_posts.preload(tags: [:materials, { tag_name: :wiki_page }]) post = filtered_posts.preload(tags: { tag_name: :wiki_page })
.order('RAND()') .order('RAND()')
.first .first
return head :not_found unless post return head :not_found unless post
@@ -104,7 +104,7 @@ class PostsController < ApplicationController
end end
def show def show
post = Post.includes(tags: [:materials, { tag_name: :wiki_page }]).find_by(id: params[:id]) post = Post.includes(tags: { tag_name: :wiki_page }).find_by(id: params[:id])
return head :not_found unless post return head :not_found unless post
render json: PostRepr.base(post, current_user) render json: PostRepr.base(post, current_user)
@@ -204,7 +204,7 @@ class PostsController < ApplicationController
pts = pts.where(post_id: id) if id.present? pts = pts.where(post_id: id) if id.present?
pts = pts.where(tag_id:) if tag_id.present? pts = pts.where(tag_id:) if tag_id.present?
pts = pts.includes(:post, :created_user, :deleted_user, pts = pts.includes(:post, :created_user, :deleted_user,
tag: [:materials, { tag_name: :wiki_page }]) tag: { tag_name: :wiki_page })
events = [] events = []
pts.each do |pt| pts.each do |pt|
+2 -4
View File
@@ -98,9 +98,7 @@ class Tag < ApplicationRecord
@niconico ||= find_or_create_by_tag_name!('ニコニコ', category: :meta) @niconico ||= find_or_create_by_tag_name!('ニコニコ', category: :meta)
end end
def self.normalise_tags tag_names, with_tagme: true, def self.normalise_tags tag_names, with_tagme: true, deny_nico: true
with_no_deerjikist: true,
deny_nico: true
if deny_nico && tag_names.any? { |n| n.downcase.start_with?('nico:') } if deny_nico && tag_names.any? { |n| n.downcase.start_with?('nico:') }
raise NicoTagNormalisationError raise NicoTagNormalisationError
end end
@@ -114,7 +112,7 @@ class Tag < ApplicationRecord
end end
tags << Tag.tagme if with_tagme && tags.size < 10 && tags.none?(Tag.tagme) tags << Tag.tagme if with_tagme && tags.size < 10 && tags.none?(Tag.tagme)
tags << Tag.no_deerjikist if with_no_deerjikist && tags.all? { |t| !(t.deerjikist?) } tags << Tag.no_deerjikist if tags.all? { |t| !(t.deerjikist?) }
tags.uniq(&:id) tags.uniq(&:id)
end end
-1
View File
@@ -49,7 +49,6 @@ Rails.application.routes.draw do
collection do collection do
get :random get :random
get :changes get :changes
get :versions, to: 'post_versions#index'
end end
member do member do
-1
View File
@@ -13,4 +13,3 @@ r2:
secret_access_key: <%= ENV['R2_SECRET_ACCESS_KEY'] %> secret_access_key: <%= ENV['R2_SECRET_ACCESS_KEY'] %>
bucket: <%= ENV['R2_BUCKET'] %> bucket: <%= ENV['R2_BUCKET'] %>
region: auto region: auto
request_checksum_calculation: when_required
-212
View File
@@ -756,218 +756,6 @@ RSpec.describe 'Posts API', type: :request do
end end
end end
describe 'GET /posts/versions' do
let(:member) { create(:user, :member, name: 'version member') }
let(:t_v1) { Time.zone.local(2020, 1, 1, 12, 0, 0) }
let(:t_v2) { Time.zone.local(2020, 1, 2, 12, 0, 0) }
let(:t_other) { Time.zone.local(2020, 1, 3, 12, 0, 0) }
let(:oc_from) { Time.zone.local(2019, 12, 31, 0, 0, 0) }
let(:oc_before) { Time.zone.local(2020, 1, 1, 0, 0, 0) }
let!(:tag_name2) { TagName.create!(name: 'spec_tag_2') }
let!(:tag2) { Tag.create!(tag_name: tag_name2, category: :general) }
def snapshot_tags(post)
post.snapshot_tag_names.join(' ')
end
def create_post_version!(post, version_no:, event_type:, created_by_user:, created_at:)
PostVersion.create!(
post: post,
version_no: version_no,
event_type: event_type,
title: post.title,
url: post.url,
thumbnail_base: post.thumbnail_base,
tags: snapshot_tags(post),
parent: post.parent,
original_created_from: post.original_created_from,
original_created_before: post.original_created_before,
created_at: created_at,
created_by_user: created_by_user
)
end
let!(:v1) do
travel_to(t_v1) do
create_post_version!(
post_record,
version_no: 1,
event_type: 'create',
created_by_user: member,
created_at: t_v1
)
end
end
let!(:v2) do
post_record.post_tags.kept.find_by!(tag: tag).discard_by!(member)
PostTag.create!(post: post_record, tag: tag2, created_user: member)
post_record.update!(
title: 'updated spec post',
original_created_from: oc_from,
original_created_before: oc_before
)
travel_to(t_v2) do
create_post_version!(
post_record.reload,
version_no: 2,
event_type: 'update',
created_by_user: member,
created_at: t_v2
)
end
end
let!(:other_post_version) do
other_post = Post.create!(
title: 'other versioned post',
url: 'https://example.com/other-versioned'
)
PostTag.create!(post: other_post, tag: tag)
travel_to(t_other) do
create_post_version!(
other_post,
version_no: 1,
event_type: 'create',
created_by_user: member,
created_at: t_other
)
end
end
it 'returns versions for the specified post in reverse chronological order' do
get '/posts/versions', params: { post: post_record.id }
expect(response).to have_http_status(:ok)
expect(json).to include('versions', 'count')
expect(json.fetch('count')).to eq(2)
versions = json.fetch('versions')
expect(versions.map { |v| v['post_id'] }.uniq).to eq([post_record.id])
expect(versions.map { |v| v['version_no'] }).to eq([2, 1])
latest = versions.first
expect(latest).to include(
'post_id' => post_record.id,
'version_no' => 2,
'event_type' => 'update',
'created_by_user' => {
'id' => member.id,
'name' => member.name
}
)
expect(latest.fetch('title')).to eq(
'current' => 'updated spec post',
'prev' => 'spec post'
)
expect(latest.fetch('url')).to eq(
'current' => 'https://example.com/spec',
'prev' => 'https://example.com/spec'
)
expect(latest.fetch('thumbnail')).to eq(
'current' => nil,
'prev' => nil
)
expect(latest.fetch('thumbnail_base')).to eq(
'current' => nil,
'prev' => nil
)
expect(latest.fetch('tags')).to include(
{ 'name' => 'spec_tag_2', 'type' => 'added' },
{ 'name' => 'spec_tag', 'type' => 'removed' }
)
expect(latest.fetch('original_created_from')).to eq(
'current' => oc_from.iso8601,
'prev' => nil
)
expect(latest.fetch('original_created_before')).to eq(
'current' => oc_before.iso8601,
'prev' => nil
)
expect(latest.fetch('created_at')).to eq(t_v2.iso8601)
first = versions.second
expect(first).to include(
'post_id' => post_record.id,
'version_no' => 1,
'event_type' => 'create',
'created_by_user' => {
'id' => member.id,
'name' => member.name
}
)
expect(first.fetch('title')).to eq(
'current' => 'spec post',
'prev' => nil
)
expect(first.fetch('tags')).to include(
{ 'name' => 'spec_tag', 'type' => 'added' }
)
expect(first.fetch('created_at')).to eq(t_v1.iso8601)
end
it 'filters versions by tag when the current snapshot includes the tag' do
get '/posts/versions', params: { post: post_record.id, tag: tag2.id }
expect(response).to have_http_status(:ok)
expect(json.fetch('count')).to eq(1)
versions = json.fetch('versions')
expect(versions.size).to eq(1)
expect(versions[0]['post_id']).to eq(post_record.id)
expect(versions[0]['version_no']).to eq(2)
expect(versions[0]['tags']).to include(
{ 'name' => 'spec_tag_2', 'type' => 'added' }
)
end
it 'filters versions by tag when the tag exists in either current or previous snapshot' do
get '/posts/versions', params: { post: post_record.id, tag: tag.id }
expect(response).to have_http_status(:ok)
expect(json.fetch('count')).to eq(2)
versions = json.fetch('versions')
expect(versions.map { |v| v['post_id'] }).to all(eq(post_record.id))
expect(versions.map { |v| v['version_no'] }).to eq([2, 1])
latest = versions[0]
first = versions[1]
expect(latest['tags']).to include(
{ 'name' => 'spec_tag', 'type' => 'removed' }
)
expect(first['tags']).to include(
{ 'name' => 'spec_tag', 'type' => 'added' }
)
end
it 'returns empty when tag does not exist' do
get '/posts/versions', params: { tag: 999_999_999 }
expect(response).to have_http_status(:ok)
expect(json.fetch('versions')).to eq([])
expect(json.fetch('count')).to eq(0)
end
it 'clamps page and limit to at least 1' do
get '/posts/versions', params: { post: post_record.id, page: 0, limit: 0 }
expect(response).to have_http_status(:ok)
expect(json.fetch('count')).to eq(2)
versions = json.fetch('versions')
expect(versions.size).to eq(1)
expect(versions[0]['version_no']).to eq(2)
end
end
describe 'POST /posts/:id/viewed' do describe 'POST /posts/:id/viewed' do
let(:user) { create(:user) } let(:user) { create(:user) }
@@ -90,9 +90,7 @@ export default (({ tag, nestLevel, pathKey, parentTagId, suppressClickRef, sp }:
className={cn ('rounded select-none', over && 'ring-2 ring-offset-2')} className={cn ('rounded select-none', over && 'ring-2 ring-offset-2')}
{...attributes} {...attributes}
{...listeners}> {...listeners}>
<motion.div <motion.div layoutId={`tag-${ sp ? 'sp-' : '' }${ tag.id }`}>
transition={{ layout: { duration: .2, ease: 'easeOut' } }}
layoutId={`tag-${ sp ? 'sp-' : '' }${ tag.id }`}>
<TagLink tag={tag} nestLevel={nestLevel}/> <TagLink tag={tag} nestLevel={nestLevel}/>
</motion.div> </motion.div>
</div>) </div>)
+1 -1
View File
@@ -62,7 +62,7 @@ export default (({ post, onSave }: Props) => {
<Label></Label> <Label></Label>
<input type="text" <input type="text"
className="w-full border rounded p-2" className="w-full border rounded p-2"
value={title ?? ''} value={title}
onChange={ev => setTitle (ev.target.value)}/> onChange={ev => setTitle (ev.target.value)}/>
</div> </div>
+2 -6
View File
@@ -313,9 +313,7 @@ export default (({ post, sp }: Props) => {
{CATEGORIES.map ((cat: Category) => ((tags[cat] ?? []).length > 0 || dragging) && ( {CATEGORIES.map ((cat: Category) => ((tags[cat] ?? []).length > 0 || dragging) && (
<div className="my-3" key={cat}> <div className="my-3" key={cat}>
<SubsectionTitle> <SubsectionTitle>
<motion.div <motion.div layoutId={`tag-${ sp ? 'sp-' : '' }${ cat }`}>
layoutId={`tag-${ sp ? 'sp-' : '' }${ cat }`}
transition={{ layout: { duration: .2, ease: 'easeOut' } }}>
{CATEGORY_NAMES[cat]} {CATEGORY_NAMES[cat]}
</motion.div> </motion.div>
</SubsectionTitle> </SubsectionTitle>
@@ -327,9 +325,7 @@ export default (({ post, sp }: Props) => {
</ul> </ul>
</div>))} </div>))}
{post && ( {post && (
<motion.div <motion.div layoutId={`post-info-${ sp }`}>
layoutId={`post-info-${ sp }`}
transition={{ layout: { duration: .2, ease: 'easeOut' } }}>
<SectionTitle></SectionTitle> <SectionTitle></SectionTitle>
<ul> <ul>
<li>Id.: {post.id}</li> <li>Id.: {post.id}</li>
+7 -7
View File
@@ -1,6 +1,6 @@
import { apiDelete, apiGet, apiPost } from '@/lib/api' import { apiDelete, apiGet, apiPost } from '@/lib/api'
import type { FetchPostsParams, Post, PostVersion } from '@/types' import type { FetchPostsParams, Post, PostTagChange } from '@/types'
export const fetchPosts = async ( export const fetchPosts = async (
@@ -29,17 +29,17 @@ export const fetchPost = async (id: string): Promise<Post> => await apiGet (`/po
export const fetchPostChanges = async ( export const fetchPostChanges = async (
{ post, tag, page, limit }: { { id, tag, page, limit }: {
post?: string id?: string
tag?: string tag?: string
page: number page: number
limit: number }, limit: number },
): Promise<{ ): Promise<{
versions: PostVersion[] changes: PostTagChange[]
count: number }> => count: number }> =>
await apiGet ('/posts/versions', { params: { ...(post && { post }), await apiGet ('/posts/changes', { params: { ...(id && { id }),
...(tag && { tag }), ...(tag && { tag }),
page, limit } }) page, limit } })
export const toggleViewedFlg = async (id: string, viewed: boolean): Promise<void> => { export const toggleViewedFlg = async (id: string, viewed: boolean): Promise<void> => {
+1 -1
View File
@@ -5,7 +5,7 @@ export const postsKeys = {
index: (p: FetchPostsParams) => ['posts', 'index', p] as const, index: (p: FetchPostsParams) => ['posts', 'index', p] as const,
show: (id: string) => ['posts', id] as const, show: (id: string) => ['posts', id] as const,
related: (id: string) => ['related', id] as const, related: (id: string) => ['related', id] as const,
changes: (p: { post?: string; tag?: string; page: number; limit: number }) => changes: (p: { id?: string; tag?: string; page: number; limit: number }) =>
['posts', 'changes', p] as const } ['posts', 'changes', p] as const }
export const tagsKeys = { export const tagsKeys = {
+2 -2
View File
@@ -96,7 +96,7 @@ export default (({ user }: Props) => {
<div className="md:flex md:flex-1 overflow-y-auto md:overflow-y-hidden"> <div className="md:flex md:flex-1 overflow-y-auto md:overflow-y-hidden">
<Helmet> <Helmet>
{(post?.thumbnail || post?.thumbnailBase) && ( {(post?.thumbnail || post?.thumbnailBase) && (
<meta name="thumbnail" content={post.thumbnail! || post.thumbnailBase!}/>)} <meta name="thumbnail" content={post.thumbnail || post.thumbnailBase}/>)}
{post && <title>{`${ post.title || post.url } | ${ SITE_TITLE }`}</title>} {post && <title>{`${ post.title || post.url } | ${ SITE_TITLE }`}</title>}
</Helmet> </Helmet>
@@ -116,7 +116,7 @@ export default (({ user }: Props) => {
initial={{ opacity: 1 }} initial={{ opacity: 1 }}
animate={{ opacity: 0 }} animate={{ opacity: 0 }}
transition={{ duration: .2, ease: 'easeOut' }}> transition={{ duration: .2, ease: 'easeOut' }}>
<img src={post.thumbnail || post.thumbnailBase || undefined} <img src={post.thumbnail || post.thumbnailBase}
alt={post.title || post.url} alt={post.title || post.url}
title={post.title || post.url || undefined} title={post.title || post.url || undefined}
className="object-cover w-full h-full"/> className="object-cover w-full h-full"/>
+73 -185
View File
@@ -1,4 +1,4 @@
import { useQuery, useQueryClient } from '@tanstack/react-query' import { useQuery } from '@tanstack/react-query'
import { motion } from 'framer-motion' import { motion } from 'framer-motion'
import { useEffect } from 'react' import { useEffect } from 'react'
import { Helmet } from 'react-helmet-async' import { Helmet } from 'react-helmet-async'
@@ -9,30 +9,15 @@ import PrefetchLink from '@/components/PrefetchLink'
import PageTitle from '@/components/common/PageTitle' import PageTitle from '@/components/common/PageTitle'
import Pagination from '@/components/common/Pagination' import Pagination from '@/components/common/Pagination'
import MainArea from '@/components/layout/MainArea' import MainArea from '@/components/layout/MainArea'
import { toast } from '@/components/ui/use-toast'
import { SITE_TITLE } from '@/config' import { SITE_TITLE } from '@/config'
import { apiPut } from '@/lib/api'
import { fetchPostChanges } from '@/lib/posts' import { fetchPostChanges } from '@/lib/posts'
import { postsKeys, tagsKeys } from '@/lib/queryKeys' import { postsKeys, tagsKeys } from '@/lib/queryKeys'
import { fetchTag } from '@/lib/tags' import { fetchTag } from '@/lib/tags'
import { cn, dateString, originalCreatedAtString } from '@/lib/utils' import { cn, dateString } from '@/lib/utils'
import type { FC } from 'react' import type { FC } from 'react'
const renderDiff = (diff: { current: string | null; prev: string | null }) => (
<>
{(diff.prev && diff.prev !== diff.current) && (
<>
<del className="text-red-600 dark:text-red-400">
{diff.prev}
</del>
{diff.current && <br/>}
</>)}
{diff.current}
</>)
export default (() => { export default (() => {
const location = useLocation () const location = useLocation ()
const query = new URLSearchParams (location.search) const query = new URLSearchParams (location.search)
@@ -51,17 +36,15 @@ export default (() => {
: { data: null } : { data: null }
const { data, isLoading: loading } = useQuery ({ const { data, isLoading: loading } = useQuery ({
queryKey: postsKeys.changes ({ ...(id && { post: id }), queryKey: postsKeys.changes ({ ...(id && { id }),
...(tagId && { tag: tagId }), ...(tagId && { tag: tagId }),
page, limit }), page, limit }),
queryFn: () => fetchPostChanges ({ ...(id && { post: id }), queryFn: () => fetchPostChanges ({ ...(id && { id }),
...(tagId && { tag: tagId }), ...(tagId && { tag: tagId }),
page, limit }) }) page, limit }) })
const changes = data?.versions ?? [] const changes = data?.changes ?? []
const totalPages = data ? Math.ceil (data.count / limit) : 0 const totalPages = data ? Math.ceil (data.count / limit) : 0
const qc = useQueryClient ()
useEffect (() => { useEffect (() => {
document.querySelector ('table')?.scrollIntoView ({ behavior: 'smooth' }) document.querySelector ('table')?.scrollIntoView ({ behavior: 'smooth' })
}, [location.search]) }, [location.search])
@@ -82,171 +65,76 @@ export default (() => {
{loading ? 'Loading...' : ( {loading ? 'Loading...' : (
<> <>
<div className="overflow-x-auto"> <table className="table-auto w-full border-collapse">
<table className="w-full min-w-[1200px] table-fixed border-collapse"> <thead className="border-b-2 border-black dark:border-white">
<colgroup> <tr>
{/* 投稿 */} <th className="p-2 text-left">稿</th>
<col className="w-64"/> <th className="p-2 text-left"></th>
{/* 版 */} <th className="p-2 text-left"></th>
<col className="w-40"/> </tr>
{/* タイトル */} </thead>
<col className="w-96"/> <tbody>
{/* URL */} {changes.map ((change, i) => {
<col className="w-96"/> const withPost = i === 0 || change.post.id !== changes[i - 1].post.id
{/* タグ */} if (withPost)
<col className="w-[48rem]"/> {
{/* オリジナルの投稿日時 */} rowsCnt = 1
<col className="w-96"/> for (let j = i + 1;
{/* 更新日時 */} (j < changes.length
<col className="w-64"/> && change.post.id === changes[j].post.id);
{/* (差戻ボタン) */} ++j)
<col className="w-20"/> ++rowsCnt
</colgroup> }
<thead className="border-b-2 border-black dark:border-white"> let layoutId: string | undefined = `page-${ change.post.id }`
<tr> if (layoutIds.includes (layoutId))
<th className="p-2 text-left">稿</th> layoutId = undefined
<th className="p-2 text-left"></th> else
<th className="p-2 text-left"></th> layoutIds.push (layoutId)
<th className="p-2 text-left">URL</th>
<th className="p-2 text-left"></th>
<th className="p-2 text-left">稿</th>
<th className="p-2 text-left"></th>
<th className="p-2"/>
</tr>
</thead>
<tbody> return (
{changes.map ((change, i) => { <tr key={`${ change.timestamp }-${ change.post.id }-${ change.tag?.id }`}
const withPost = i === 0 || change.postId !== changes[i - 1].postId className={cn ('even:bg-gray-100 dark:even:bg-gray-700',
if (withPost) withPost && 'border-t')}>
{ {withPost && (
rowsCnt = 1 <td className="align-top p-2 bg-white dark:bg-[#242424] border-r"
for (let j = i + 1; rowSpan={rowsCnt}>
(j < changes.length <PrefetchLink to={`/posts/${ change.post.id }`}>
&& change.postId === changes[j].postId); <motion.div
++j) layoutId={layoutId}
++rowsCnt transition={{ type: 'spring',
} stiffness: 500,
damping: 40,
let layoutId: string | undefined = `page-${ change.postId }` mass: .5 }}>
if (layoutIds.includes (layoutId)) <img src={change.post.thumbnail
layoutId = undefined || change.post.thumbnailBase
else || undefined}
layoutIds.push (layoutId) alt={change.post.title || change.post.url}
title={change.post.title || change.post.url || undefined}
return ( className="w-40"/>
<tr key={`${ change.postId }.${ change.versionNo }`} </motion.div>
className={cn ('even:bg-gray-100 dark:even:bg-gray-700', </PrefetchLink>
withPost && 'border-t')}> </td>)}
{withPost && ( <td className="p-2">
<td className="align-top p-2 bg-white dark:bg-[#242424] border-r" {change.tag
rowSpan={rowsCnt}> ? <TagLink tag={change.tag} withWiki={false} withCount={false}/>
<PrefetchLink to={`/posts/${ change.postId }`}> : '(マスタ削除済のタグ) '}
<motion.div {`${ change.changeType === 'add' ? '記載' : '消除' }`}
layoutId={layoutId} </td>
transition={{ layout: { duration: .2, ease: 'easeOut' } }}> <td className="p-2">
<img src={change.thumbnail.current {change.user
|| change.thumbnailBase.current ? (
|| undefined} <PrefetchLink to={`/users/${ change.user.id }`}>
alt={change.title.current || change.url.current} {change.user.name}
title={change.title.current || change.url.current || undefined} </PrefetchLink>)
className="w-40"/> : 'bot 操作'}
</motion.div> <br/>
</PrefetchLink> {dateString (change.timestamp)}
</td>)} </td>
<td className="p-2">{change.postId}.{change.versionNo}</td> </tr>)
<td className="p-2 break-all">{renderDiff (change.title)}</td> })}
<td className="p-2 break-all">{renderDiff (change.url)}</td> </tbody>
<td className="p-2"> </table>
{change.tags.map ((tag, i) => (
tag.type === 'added'
? (
<ins
key={i}
className="mr-2 text-green-600 dark:text-green-400">
{tag.name}
</ins>)
: (
tag.type === 'removed'
? (
<del
key={i}
className="mr-2 text-red-600 dark:text-red-400">
{tag.name}
</del>)
: (
<span key={i} className="mr-2">
{tag.name}
</span>))))}
</td>
<td className="p-2">
{change.versionNo === 1
? originalCreatedAtString (change.originalCreatedFrom.current,
change.originalCreatedBefore.current)
: renderDiff ({
current: originalCreatedAtString (
change.originalCreatedFrom.current,
change.originalCreatedBefore.current),
prev: originalCreatedAtString (
change.originalCreatedFrom.prev,
change.originalCreatedBefore.prev) })}
</td>
<td className="p-2">
{change.createdByUser
? (
<PrefetchLink to={`/users/${ change.createdByUser.id }`}>
{change.createdByUser.name
|| `名もなきニジラー(#${ change.createdByUser.id }`}
</PrefetchLink>)
: 'bot 操作'}
<br/>
{dateString (change.createdAt)}
</td>
<td className="p-2">
<a
href="#"
onClick={async e => {
e.preventDefault ()
if (!(confirm (
`${ change.title.current
|| change.url.current }』を版 ${
change.versionNo } に差戻します.\nよろしいですか?`)))
return
try
{
await apiPut (
`/posts/${ change.postId }`,
{ title: change.title.current,
tags: change.tags
.filter (t => t.type !== 'removed')
.map (t => t.name)
.filter (t => t.slice (0, 5) !== 'nico:')
.join (' '),
original_created_from:
change.originalCreatedFrom.current,
original_created_before:
change.originalCreatedBefore.current })
qc.invalidateQueries ({ queryKey: postsKeys.root })
qc.invalidateQueries ({ queryKey: tagsKeys.root })
toast ({ description: '差戻しました.' })
}
catch
{
toast ({ description: '差戻に失敗……' })
}
}}>
</a>
</td>
</tr>)
})}
</tbody>
</table>
</div>
<Pagination page={page} totalPages={totalPages}/> <Pagination page={page} totalPages={totalPages}/>
</>)} </>)}
+2 -2
View File
@@ -289,7 +289,7 @@ export default (() => {
{results.map (row => ( {results.map (row => (
<tr key={row.id} className="even:bg-gray-100 dark:even:bg-gray-700"> <tr key={row.id} className="even:bg-gray-100 dark:even:bg-gray-700">
<td className="p-2"> <td className="p-2">
<PrefetchLink to={`/posts/${ row.id }`} title={row.title || undefined}> <PrefetchLink to={`/posts/${ row.id }`} title={row.title}>
<motion.div <motion.div
layoutId={`page-${ row.id }`} layoutId={`page-${ row.id }`}
transition={{ type: 'spring', transition={{ type: 'spring',
@@ -304,7 +304,7 @@ export default (() => {
</PrefetchLink> </PrefetchLink>
</td> </td>
<td className="p-2 truncate"> <td className="p-2 truncate">
<PrefetchLink to={`/posts/${ row.id }`} title={row.title || undefined}> <PrefetchLink to={`/posts/${ row.id }`} title={row.title}>
{row.title} {row.title}
</PrefetchLink> </PrefetchLink>
</td> </td>
+4 -18
View File
@@ -117,9 +117,9 @@ export type NiconicoViewerHandle = {
export type Post = { export type Post = {
id: number id: number
url: string url: string
title: string | null title: string
thumbnail: string | null thumbnail: string
thumbnailBase: string | null thumbnailBase: string
tags: Tag[] tags: Tag[]
viewed: boolean viewed: boolean
related: Post[] related: Post[]
@@ -127,7 +127,7 @@ export type Post = {
originalCreatedBefore: string | null originalCreatedBefore: string | null
createdAt: string createdAt: string
updatedAt: string updatedAt: string
uploadedUser: { id: number; name: string | null } | null } uploadedUser: { id: number; name: string } | null }
export type PostTagChange = { export type PostTagChange = {
post: Post post: Post
@@ -136,20 +136,6 @@ export type PostTagChange = {
changeType: 'add' | 'remove' changeType: 'add' | 'remove'
timestamp: string } timestamp: string }
export type PostVersion = {
postId: number
versionNo: number
eventType: 'create' | 'update' | 'discard' | 'restore'
title: { current: string | null; prev: string | null }
url: { current: string; prev: string | null }
thumbnail: { current: string | null; prev: string | null }
thumbnailBase: { current: string | null; prev: string | null }
tags: { name: string; type: 'context' | 'added' | 'removed' }[]
originalCreatedFrom: { current: string | null; prev: string | null }
originalCreatedBefore: { current: string | null; prev: string | null }
createdAt: string
createdByUser: { id: number; name: string | null } | null }
export type SubMenuComponentItem = { export type SubMenuComponentItem = {
component: ReactNode component: ReactNode
visible: boolean } visible: boolean }