このコミットが含まれているのは:
@@ -238,8 +238,7 @@ const createGameSeed = (): string => {
|
||||
|
||||
const normalizeStoredQuestionId = (
|
||||
questionId: string,
|
||||
condition?: GekanatorQuestionCondition,
|
||||
): string => {
|
||||
condition?: GekanatorQuestionCondition): string => {
|
||||
if (condition?.type === 'title-length-greater-than')
|
||||
return `title:length-at-least:${ condition.length + 1 }`
|
||||
|
||||
@@ -312,8 +311,7 @@ const sourcePriorityForMerge = (question: GekanatorQuestion): number => {
|
||||
|
||||
const shouldReplaceMergedQuestion = (
|
||||
current: GekanatorQuestion | undefined,
|
||||
candidate: GekanatorQuestion,
|
||||
): boolean => {
|
||||
candidate: GekanatorQuestion): boolean => {
|
||||
if (!(current))
|
||||
return true
|
||||
|
||||
@@ -408,8 +406,7 @@ const loadRecentGames = (): RecentGameSummary[] => {
|
||||
|
||||
|
||||
const storeRecentGameSummary = (
|
||||
summary: RecentGameSummary,
|
||||
): RecentGameSummary[] => {
|
||||
summary: RecentGameSummary): RecentGameSummary[] => {
|
||||
const next =
|
||||
[summary,
|
||||
...loadRecentGames ().filter (item => (item.savedAt !== summary.savedAt
|
||||
@@ -459,8 +456,7 @@ const resettableExtraQuestionState = (): {
|
||||
|
||||
const recoveredCandidateMapFromStored = (
|
||||
items: RecoveredCandidatePost[],
|
||||
scores: [number, number][],
|
||||
): Map<number, RecoveredCandidateState> => {
|
||||
scores: [number, number][]): Map<number, RecoveredCandidateState> => {
|
||||
const storedScores = new Map (scores)
|
||||
|
||||
return new Map (items.map (item => [item.postId, {
|
||||
@@ -470,8 +466,7 @@ const recoveredCandidateMapFromStored = (
|
||||
|
||||
|
||||
const storedRecoveredCandidatesFromMap = (
|
||||
recoveredCandidatePosts: Map<number, RecoveredCandidateState>,
|
||||
): RecoveredCandidatePost[] =>
|
||||
recoveredCandidatePosts: Map<number, RecoveredCandidateState>): RecoveredCandidatePost[] =>
|
||||
[...recoveredCandidatePosts.entries ()]
|
||||
.map (([postId, recoveredCandidate]) => ({
|
||||
postId,
|
||||
@@ -513,8 +508,7 @@ const distributionEntropy = (weights: number[]): number =>
|
||||
const questionCategoryPenalty = (
|
||||
question: GekanatorQuestion,
|
||||
answerCount: number,
|
||||
repeatPenalty: number,
|
||||
): number => {
|
||||
repeatPenalty: number): number => {
|
||||
const earlyFactor = Math.max (0, (3 - answerCount) / 3)
|
||||
const titleLengthPenalty = (() => {
|
||||
if (titleLengthMinimumForCondition (question.condition) == null)
|
||||
@@ -553,8 +547,7 @@ const relatedPostIdsOf = (post: Post): number[] => {
|
||||
|
||||
const userPriorWeightsFor = (
|
||||
posts: Post[],
|
||||
recentGames: RecentGameSummary[],
|
||||
): Map<number, number> => {
|
||||
recentGames: RecentGameSummary[]): Map<number, number> => {
|
||||
const postById = new Map (posts.map (post => [post.id, post]))
|
||||
const weights = new Map<number, number> ()
|
||||
const addWeight = (postId: number, weight: number) => {
|
||||
@@ -581,14 +574,12 @@ const userPriorWeightsFor = (
|
||||
|
||||
const answerWeightFor = (
|
||||
questionId: string,
|
||||
softenedQuestionIds: Set<string>,
|
||||
): number => softenedQuestionIds.has (questionId) ? softenedAnswerWeight : 1
|
||||
softenedQuestionIds: Set<string>): number => softenedQuestionIds.has (questionId) ? softenedAnswerWeight : 1
|
||||
|
||||
|
||||
const scoreWeightForAnswer = (
|
||||
answer: GekanatorAnswerLog,
|
||||
softenedQuestionIds: Set<string>,
|
||||
): number =>
|
||||
softenedQuestionIds: Set<string>): number =>
|
||||
answerWeightFor (answer.questionId, softenedQuestionIds)
|
||||
* (
|
||||
answer.questionPurpose === 'learning_user_suggested'
|
||||
@@ -638,8 +629,7 @@ const titleTermPattern =
|
||||
const addPostIdToIndex = <K extends string | number> (
|
||||
index: Map<K, Set<number>>,
|
||||
key: K,
|
||||
postId: number,
|
||||
) => {
|
||||
postId: number) => {
|
||||
const current = index.get (key)
|
||||
if (current)
|
||||
{
|
||||
@@ -652,8 +642,7 @@ const addPostIdToIndex = <K extends string | number> (
|
||||
|
||||
|
||||
const buildMaterialIndex = (
|
||||
posts: Post[],
|
||||
): GekanatorQuestionMaterialIndex => {
|
||||
posts: Post[]): GekanatorQuestionMaterialIndex => {
|
||||
const postById = new Map<number, Post> ()
|
||||
const tagKeysByPostId = new Map<number, string[]> ()
|
||||
const postIdsByTagKey = new Map<string, Set<number>> ()
|
||||
@@ -784,8 +773,7 @@ const originalDateQuestionTextFor = (
|
||||
condition: Extract<
|
||||
GekanatorQuestionCondition,
|
||||
{ type: 'original-year' | 'original-month' | 'original-month-day' }
|
||||
>,
|
||||
): string => {
|
||||
>): string => {
|
||||
switch (condition.type)
|
||||
{
|
||||
case 'original-year':
|
||||
@@ -852,8 +840,7 @@ const isLearnableTagKey = (key: string): boolean => !(key.startsWith ('nico:'))
|
||||
|
||||
|
||||
const isUserSuggestedLearnedSemanticQuestion = (
|
||||
question: GekanatorQuestion,
|
||||
): boolean => isLearnedSemanticQuestion (question)
|
||||
question: GekanatorQuestion): boolean => isLearnedSemanticQuestion (question)
|
||||
|
||||
|
||||
type LearnedSemanticCandidateStats = {
|
||||
@@ -872,8 +859,7 @@ const learnedSemanticStatsForCandidateIds = (
|
||||
question }: {
|
||||
candidateIds: number[]
|
||||
posts: Post[]
|
||||
question: GekanatorQuestion },
|
||||
): LearnedSemanticCandidateStats => {
|
||||
question: GekanatorQuestion }): LearnedSemanticCandidateStats => {
|
||||
const candidateIdSet = new Set (candidateIds)
|
||||
const positiveIds = new Set<number> ()
|
||||
const negativeIds = new Set<number> ()
|
||||
@@ -915,8 +901,7 @@ const learnedSemanticQuestionIsEffectiveForCandidateIds = (
|
||||
question }: {
|
||||
candidateIds: number[]
|
||||
posts: Post[]
|
||||
question: GekanatorQuestion },
|
||||
): boolean => {
|
||||
question: GekanatorQuestion }): boolean => {
|
||||
if (!(isUserSuggestedLearnedSemanticQuestion (question)))
|
||||
return false
|
||||
|
||||
@@ -936,8 +921,7 @@ const learnedSemanticQuestionIsEffectiveForCandidateIds = (
|
||||
|
||||
const directSemanticAnswerForPost = (
|
||||
question: GekanatorQuestion,
|
||||
post: Post,
|
||||
): GekanatorAnswerValue | null => {
|
||||
post: Post): GekanatorAnswerValue | null => {
|
||||
const direct = question.exampleAnswers?.[String (post.id) as `${ number }`]
|
||||
if (direct)
|
||||
return direct
|
||||
@@ -956,8 +940,7 @@ const learnedSemanticLearningValueForTopPosts = (
|
||||
question: GekanatorQuestion
|
||||
learningTargetPosts: Post[]
|
||||
candidateIds: number[]
|
||||
posts: Post[] },
|
||||
): { missingTopCount: number
|
||||
posts: Post[] }): { missingTopCount: number
|
||||
knownCount: number
|
||||
hasLearningValue: boolean } => {
|
||||
const missingTopCount =
|
||||
@@ -1000,8 +983,7 @@ const learningTargetPostsForCandidates = ({
|
||||
|
||||
|
||||
const questionPurposeCountsFor = (
|
||||
answers: GekanatorAnswerLog[],
|
||||
): {
|
||||
answers: GekanatorAnswerLog[]): {
|
||||
effectiveUserSuggestedCount: number
|
||||
learningUserSuggestedCount: number
|
||||
normalQuestionCount: number
|
||||
@@ -1041,8 +1023,7 @@ const questionPurposeCountsFor = (
|
||||
|
||||
const learnedSemanticNarrowPenaltyForStats = (
|
||||
candidateCount: number,
|
||||
stats: LearnedSemanticCandidateStats,
|
||||
): number => {
|
||||
stats: LearnedSemanticCandidateStats): number => {
|
||||
const minSide = candidateCount < 10 ? 1 : Math.max (3, candidateCount * .08)
|
||||
return stats.positiveCount < minSide || stats.negativeCount < minSide ? .15 : 0
|
||||
}
|
||||
@@ -1050,8 +1031,7 @@ const learnedSemanticNarrowPenaltyForStats = (
|
||||
|
||||
const learnedSemanticScoreDeltaForExpectedAnswer = (
|
||||
userAnswer: GekanatorAnswerValue,
|
||||
expectedAnswer: GekanatorAnswerValue | null,
|
||||
): number => {
|
||||
expectedAnswer: GekanatorAnswerValue | null): number => {
|
||||
switch (userAnswer)
|
||||
{
|
||||
case 'yes':
|
||||
@@ -1089,8 +1069,7 @@ const learnedSemanticScoreDeltaForExpectedAnswer = (
|
||||
const scoreDropDeltaForRecoveredPost = (
|
||||
postId: number,
|
||||
totalScore: number,
|
||||
recoveredCandidatePosts: Map<number, RecoveredCandidateState>,
|
||||
): number => {
|
||||
recoveredCandidatePosts: Map<number, RecoveredCandidateState>): number => {
|
||||
const recoveredCandidate = recoveredCandidatePosts.get (postId)
|
||||
if (recoveredCandidate == null)
|
||||
return totalScore
|
||||
@@ -1114,8 +1093,7 @@ const postPassesScoreDrop = (
|
||||
recoveredCandidatePosts }: {
|
||||
postId: number
|
||||
scores: Map<number, number>
|
||||
recoveredCandidatePosts: Map<number, RecoveredCandidateState> },
|
||||
): boolean => {
|
||||
recoveredCandidatePosts: Map<number, RecoveredCandidateState> }): boolean => {
|
||||
if (!(activeCandidateScoreDropEnabled (scores)))
|
||||
return true
|
||||
|
||||
@@ -1129,8 +1107,7 @@ const postPassesScoreDrop = (
|
||||
|
||||
// `post_similarities` is the score-propagation graph, not the question kind.
|
||||
const questionUsesPostSimilarityPropagationGraphForScoring = (
|
||||
question: GekanatorQuestion,
|
||||
): boolean =>
|
||||
question: GekanatorQuestion): boolean =>
|
||||
(question.kind === 'post_similarity'
|
||||
&& !(isUserSuggestedLearnedSemanticQuestion (question)))
|
||||
|| (question.kind === 'tag'
|
||||
@@ -1139,8 +1116,7 @@ const questionUsesPostSimilarityPropagationGraphForScoring = (
|
||||
|
||||
|
||||
const questionSupportsAnswerBasedHardFiltering = (
|
||||
question: GekanatorQuestion,
|
||||
): boolean => !(questionUsesPostSimilarityPropagationGraphForScoring (question))
|
||||
question: GekanatorQuestion): boolean => !(questionUsesPostSimilarityPropagationGraphForScoring (question))
|
||||
&& !(isUserSuggestedLearnedSemanticQuestion (question))
|
||||
|
||||
|
||||
@@ -1160,8 +1136,7 @@ const usesLearnedTagExamples = (question: GekanatorQuestion): boolean =>
|
||||
|
||||
const searchedQuestionsFor = (
|
||||
questions: GekanatorQuestion[],
|
||||
search: string,
|
||||
): GekanatorQuestion[] => {
|
||||
search: string): GekanatorQuestion[] => {
|
||||
const needle = search.trim ()
|
||||
if (!(needle))
|
||||
return []
|
||||
@@ -1235,8 +1210,7 @@ type QuestionMatchResolver = {
|
||||
|
||||
const buildGekanatorMatchIndex = (
|
||||
posts: Post[],
|
||||
questions: GekanatorQuestion[],
|
||||
): GekanatorMatchIndex => new Map (
|
||||
questions: GekanatorQuestion[]): GekanatorMatchIndex => new Map (
|
||||
questions.map (question => [
|
||||
question.id,
|
||||
new Set (
|
||||
@@ -1285,8 +1259,7 @@ const matchingPostIdsForQuestion = ({
|
||||
|
||||
|
||||
const positiveMatchingPostIdsForQuestion = (
|
||||
resolver: QuestionMatchResolver,
|
||||
): Set<number> => {
|
||||
resolver: QuestionMatchResolver): Set<number> => {
|
||||
if (isUserSuggestedLearnedSemanticQuestion (resolver.question))
|
||||
{
|
||||
const cached = resolver.dynamicMatchIndex?.get (resolver.question.id)
|
||||
@@ -1356,8 +1329,7 @@ const matchingWeightInCandidates = (
|
||||
materialIndex: GekanatorQuestionMaterialIndex
|
||||
matchIndex: GekanatorMatchIndex
|
||||
question: GekanatorQuestion
|
||||
dynamicMatchIndex?: GekanatorMatchIndex },
|
||||
): number => {
|
||||
dynamicMatchIndex?: GekanatorMatchIndex }): number => {
|
||||
const matched = positiveMatchingPostIdsForQuestion ({
|
||||
posts,
|
||||
materialIndex,
|
||||
@@ -1380,8 +1352,7 @@ const signatureForCandidateIds = (
|
||||
materialIndex: GekanatorQuestionMaterialIndex
|
||||
matchIndex: GekanatorMatchIndex
|
||||
question: GekanatorQuestion
|
||||
dynamicMatchIndex?: GekanatorMatchIndex },
|
||||
): string => {
|
||||
dynamicMatchIndex?: GekanatorMatchIndex }): string => {
|
||||
if (isUserSuggestedLearnedSemanticQuestion (question))
|
||||
{
|
||||
const postById = new Map (posts.map (post => [post.id, post]))
|
||||
@@ -1421,8 +1392,7 @@ const postIdsForHardAnswer = (
|
||||
posts: Post[]
|
||||
materialIndex: GekanatorQuestionMaterialIndex
|
||||
matchIndex: GekanatorMatchIndex
|
||||
dynamicMatchIndex?: GekanatorMatchIndex },
|
||||
): number[] => {
|
||||
dynamicMatchIndex?: GekanatorMatchIndex }): number[] => {
|
||||
if (!(questionSupportsAnswerBasedHardFiltering (question)))
|
||||
return candidateIds
|
||||
|
||||
@@ -1562,8 +1532,7 @@ const buildIndexedQuestion = (
|
||||
text: string
|
||||
kind: GekanatorQuestionKind
|
||||
priorityWeight: number
|
||||
materialIndex: GekanatorQuestionMaterialIndex },
|
||||
): GekanatorQuestion => ({
|
||||
materialIndex: GekanatorQuestionMaterialIndex }): GekanatorQuestion => ({
|
||||
id: questionIdForCondition (condition),
|
||||
text,
|
||||
kind,
|
||||
@@ -1578,8 +1547,7 @@ const buildIndexedQuestion = (
|
||||
const rankedEntriesForCounts = <T extends string | number> (
|
||||
{ counts, total, cap }: { counts: Map<T, number>
|
||||
total: number
|
||||
cap: number },
|
||||
): [T, number][] =>
|
||||
cap: number }): [T, number][] =>
|
||||
([...counts.entries ()]
|
||||
.filter (([, count]) => count > 0 && count < total)
|
||||
.sort ((a, b) => Math.abs (total / 2 - a[1]) - Math.abs (total / 2 - b[1]))
|
||||
@@ -1594,8 +1562,7 @@ const buildQuestionsForCandidateIds = (
|
||||
materialIndex: GekanatorQuestionMaterialIndex
|
||||
acceptedQuestions: GekanatorQuestion[]
|
||||
mode?: QuestionBuildMode
|
||||
confirmationPostId?: number | null },
|
||||
): GekanatorQuestion[] => {
|
||||
confirmationPostId?: number | null }): GekanatorQuestion[] => {
|
||||
const total = candidateIds.length
|
||||
const confirmationPost = (() => {
|
||||
if (confirmationPostId == null)
|
||||
@@ -1652,8 +1619,7 @@ const buildQuestionsForCandidateIds = (
|
||||
condition: Extract<
|
||||
GekanatorQuestionCondition,
|
||||
{ type: 'original-year' | 'original-month' | 'original-month-day' }
|
||||
>,
|
||||
): GekanatorQuestion => {
|
||||
>): GekanatorQuestion => {
|
||||
const priorityWeight = (() => {
|
||||
if (condition.type === 'original-year')
|
||||
return 1.04
|
||||
@@ -1673,8 +1639,7 @@ const buildQuestionsForCandidateIds = (
|
||||
const specialMonthDays = rankedEntriesForCounts ({
|
||||
counts: monthDayCounts,
|
||||
total,
|
||||
cap: factCap
|
||||
}).filter (([monthDay]) => specialOriginalMonthDayLabelFor (String (monthDay)) != null)
|
||||
cap: factCap}).filter (([monthDay]) => specialOriginalMonthDayLabelFor (String (monthDay)) != null)
|
||||
|
||||
if (mode === 'split')
|
||||
{
|
||||
@@ -2124,8 +2089,7 @@ type ExclusiveConditionGroup =
|
||||
|
||||
|
||||
const exclusiveConditionGroupFor = (
|
||||
condition: GekanatorQuestion['condition'],
|
||||
): ExclusiveConditionGroup | null => {
|
||||
condition: GekanatorQuestion['condition']): ExclusiveConditionGroup | null => {
|
||||
switch (condition.type)
|
||||
{
|
||||
case 'original-month':
|
||||
@@ -2144,8 +2108,7 @@ const exclusiveConditionGroupFor = (
|
||||
|
||||
const sameConditionValue = (
|
||||
left: GekanatorQuestion['condition'],
|
||||
right: GekanatorQuestion['condition'],
|
||||
): boolean => {
|
||||
right: GekanatorQuestion['condition']): boolean => {
|
||||
const leftTitleLength = titleLengthMinimumForCondition (left)
|
||||
const rightTitleLength = titleLengthMinimumForCondition (right)
|
||||
if (leftTitleLength != null || rightTitleLength != null)
|
||||
@@ -2187,8 +2150,7 @@ const sameConditionValue = (
|
||||
|
||||
const isMonthCrossMatch = (
|
||||
candidate: GekanatorQuestion['condition'],
|
||||
previous: GekanatorQuestion['condition'],
|
||||
): boolean => {
|
||||
previous: GekanatorQuestion['condition']): boolean => {
|
||||
const candidateMonth = monthForCondition (candidate)
|
||||
const previousMonth = monthForCondition (previous)
|
||||
if (candidateMonth == null || previousMonth == null)
|
||||
@@ -2204,8 +2166,7 @@ const isMonthCrossMatch = (
|
||||
|
||||
const isExclusiveContradiction = (
|
||||
candidate: GekanatorQuestion['condition'],
|
||||
previous: GekanatorQuestion['condition'],
|
||||
): boolean => {
|
||||
previous: GekanatorQuestion['condition']): boolean => {
|
||||
const candidateGroup = exclusiveConditionGroupFor (candidate)
|
||||
const previousGroup = exclusiveConditionGroupFor (previous)
|
||||
|
||||
@@ -2242,16 +2203,14 @@ const contradictionPenaltyFor = ({
|
||||
case 'no':
|
||||
if (
|
||||
sameConditionValue (question.condition, previous)
|
||||
|| isMonthCrossMatch (question.condition, previous)
|
||||
)
|
||||
|| isMonthCrossMatch (question.condition, previous))
|
||||
return sum + 40
|
||||
|
||||
return sum
|
||||
case 'probably_no':
|
||||
if (
|
||||
sameConditionValue (question.condition, previous)
|
||||
|| isMonthCrossMatch (question.condition, previous)
|
||||
)
|
||||
|| isMonthCrossMatch (question.condition, previous))
|
||||
return sum + 20
|
||||
|
||||
return sum
|
||||
@@ -2281,8 +2240,7 @@ const chooseQuestion = (
|
||||
recentFirstQuestionPenaltyById: Map<string, number>
|
||||
userPriorWeights: Map<number, number>
|
||||
materialIndex: GekanatorQuestionMaterialIndex
|
||||
matchIndex: GekanatorMatchIndex },
|
||||
): QuestionSelection | null => {
|
||||
matchIndex: GekanatorMatchIndex }): QuestionSelection | null => {
|
||||
const dynamicMatchIndex = new Map<string, Set<number>> ()
|
||||
|
||||
const invertedSignature = (signature: string): string =>
|
||||
@@ -2327,8 +2285,7 @@ const chooseQuestion = (
|
||||
const rank = (
|
||||
questionsToRank: GekanatorQuestion[],
|
||||
candidates: { post: Post; score: number }[],
|
||||
weightedCandidates: { post: Post; score: number; weight: number }[],
|
||||
) => {
|
||||
weightedCandidates: { post: Post; score: number; weight: number }[]) => {
|
||||
const redundant = redundantSignatures (candidates.map (item => item.post))
|
||||
const candidateById = new Map (candidates.map (item => [item.post.id, item.post]))
|
||||
const candidateIds = candidates.map (item => item.post.id)
|
||||
@@ -2613,8 +2570,7 @@ const chooseQuestion = (
|
||||
if (
|
||||
effectiveRatio < targetEffectiveUserSuggestedQuestionRatio
|
||||
&& totalUserSuggestedRatio < targetTotalUserSuggestedQuestionRatio
|
||||
&& effectiveUserSuggestedPool.length > 0
|
||||
)
|
||||
&& effectiveUserSuggestedPool.length > 0)
|
||||
{
|
||||
selectedPool = effectiveUserSuggestedPool
|
||||
selectedPurpose = 'effective_user_suggested'
|
||||
@@ -2622,8 +2578,7 @@ const chooseQuestion = (
|
||||
else if (
|
||||
learningRatio < targetLearningUserSuggestedQuestionRatio
|
||||
&& totalUserSuggestedRatio < targetTotalUserSuggestedQuestionRatio
|
||||
&& learningUserSuggestedPool.length > 0
|
||||
)
|
||||
&& learningUserSuggestedPool.length > 0)
|
||||
{
|
||||
selectedPool = learningUserSuggestedPool
|
||||
selectedPurpose = 'learning_user_suggested'
|
||||
@@ -2683,8 +2638,7 @@ const chooseQuestion = (
|
||||
|
||||
|
||||
const winningRunPriorityFor = (
|
||||
expected: GekanatorAnswerValue,
|
||||
): number | null => {
|
||||
expected: GekanatorAnswerValue): number | null => {
|
||||
if (expected === 'yes')
|
||||
return 0
|
||||
if (expected === 'partial')
|
||||
@@ -2719,8 +2673,7 @@ const chooseWinningRunQuestion = ({
|
||||
materialIndex,
|
||||
acceptedQuestions,
|
||||
mode: 'confirmation',
|
||||
confirmationPostId: targetPost.id
|
||||
})
|
||||
confirmationPostId: targetPost.id})
|
||||
.filter (question => {
|
||||
if (askedIds.has (question.id))
|
||||
return false
|
||||
@@ -2829,8 +2782,7 @@ const chooseFallbackQuestion = ({
|
||||
materialIndex,
|
||||
acceptedQuestions: [],
|
||||
mode: 'confirmation',
|
||||
confirmationPostId: post.id
|
||||
})))
|
||||
confirmationPostId: post.id})))
|
||||
.slice (0, 32)
|
||||
const dynamicMatchIndex = new Map<string, Set<number>> ()
|
||||
const ranked = mergeQuestions ([
|
||||
@@ -2905,8 +2857,7 @@ const chooseFallbackQuestion = ({
|
||||
|
||||
|
||||
const shouldEnterGuessPhase = (
|
||||
reason: GuessReason | null,
|
||||
): reason is 'hard_max_questions' | 'winning_run_finished' | 'question_count_checkpoint' =>
|
||||
reason: GuessReason | null): reason is 'hard_max_questions' | 'winning_run_finished' | 'question_count_checkpoint' =>
|
||||
(reason === 'hard_max_questions'
|
||||
|| reason === 'winning_run_finished'
|
||||
|| reason === 'question_count_checkpoint')
|
||||
@@ -2914,15 +2865,13 @@ const shouldEnterGuessPhase = (
|
||||
|
||||
const isWinningRunActive = (
|
||||
winningRunTargetId: number | null,
|
||||
winningRunStartAnswerCount: number | null,
|
||||
): boolean =>
|
||||
winningRunStartAnswerCount: number | null): boolean =>
|
||||
winningRunTargetId != null && winningRunStartAnswerCount != null
|
||||
|
||||
|
||||
const winningRunQuestionCount = (
|
||||
answers: GekanatorAnswerLog[],
|
||||
winningRunStartAnswerCount: number | null,
|
||||
): number => {
|
||||
winningRunStartAnswerCount: number | null): number => {
|
||||
if (winningRunStartAnswerCount == null)
|
||||
return 0
|
||||
|
||||
@@ -2962,8 +2911,7 @@ const nextQuestionPlanFor = (
|
||||
matchIndex: GekanatorMatchIndex
|
||||
lastGuessQuestionCount: number
|
||||
winningRunTargetId: number | null
|
||||
winningRunStartAnswerCount: number | null },
|
||||
): { question: GekanatorQuestion | null
|
||||
winningRunStartAnswerCount: number | null }): { question: GekanatorQuestion | null
|
||||
guess: Post | null
|
||||
guessReason: GuessReason | null
|
||||
questionMode: QuestionMode
|
||||
@@ -3013,8 +2961,7 @@ const nextQuestionPlanFor = (
|
||||
if (
|
||||
isWinningRunActive (winningRunTargetId, winningRunStartAnswerCount)
|
||||
&& winningRunTargetId === nextWinningRunTargetId
|
||||
&& winningRunStartAnswerCount != null
|
||||
)
|
||||
&& winningRunStartAnswerCount != null)
|
||||
return winningRunStartAnswerCount
|
||||
|
||||
return answers.length
|
||||
@@ -3188,8 +3135,7 @@ const mascotStateFor = (
|
||||
resultWon: boolean | null,
|
||||
eligiblePostCount: number,
|
||||
bestConfidencePercent: number,
|
||||
winningRunActive: boolean,
|
||||
): MascotState => {
|
||||
winningRunActive: boolean): MascotState => {
|
||||
const resultPhase =
|
||||
phase === 'end'
|
||||
|| phase === 'review'
|
||||
@@ -3210,13 +3156,11 @@ const mascotStateFor = (
|
||||
if (
|
||||
winningRunActive
|
||||
|| eligiblePostCount <= 2
|
||||
|| bestConfidencePercent >= 70
|
||||
)
|
||||
|| bestConfidencePercent >= 70)
|
||||
return 'thinking_near'
|
||||
if (
|
||||
eligiblePostCount >= 15
|
||||
&& bestConfidencePercent < 45
|
||||
)
|
||||
&& bestConfidencePercent < 45)
|
||||
return 'thinking_far'
|
||||
return 'thinking_mid'
|
||||
case 'guess':
|
||||
@@ -3327,8 +3271,7 @@ const GekanatorBackdrop: FC<{
|
||||
|
||||
const settingsForMode = useCallback (
|
||||
(
|
||||
mode: 'normal' | 'winning_run' | 'guess',
|
||||
): { columns: number; rows: number; opacity: number } => {
|
||||
mode: 'normal' | 'winning_run' | 'guess'): { columns: number; rows: number; opacity: number } => {
|
||||
if (mode === 'winning_run' || mode === 'guess')
|
||||
return { columns: 8, rows: 8, opacity: motionMode === 'calm' ? .18 : .24 }
|
||||
|
||||
@@ -3342,8 +3285,7 @@ const GekanatorBackdrop: FC<{
|
||||
const scaleForMode = useCallback (
|
||||
(
|
||||
mode: 'normal' | 'winning_run' | 'guess',
|
||||
displayedWinningCount: number,
|
||||
): number => {
|
||||
displayedWinningCount: number): number => {
|
||||
if (mode === 'guess')
|
||||
return 8
|
||||
|
||||
@@ -3355,8 +3297,7 @@ const GekanatorBackdrop: FC<{
|
||||
[])
|
||||
|
||||
const postsForMode = useCallback ((
|
||||
mode: 'normal' | 'winning_run' | 'guess',
|
||||
): Post[] => {
|
||||
mode: 'normal' | 'winning_run' | 'guess'): Post[] => {
|
||||
if (mode === 'guess' && displayedGuess)
|
||||
return [displayedGuess]
|
||||
if (mode === 'winning_run' && winningRunTargetPost)
|
||||
@@ -3366,8 +3307,7 @@ const GekanatorBackdrop: FC<{
|
||||
|
||||
const thumbnailsForMode = useCallback ((
|
||||
mode: 'normal' | 'winning_run' | 'guess',
|
||||
count: number,
|
||||
): string[] => {
|
||||
count: number): string[] => {
|
||||
const modePosts = postsForMode (mode)
|
||||
if (modePosts.length === 0)
|
||||
return []
|
||||
@@ -3734,8 +3674,7 @@ const GekanatorBackdrop: FC<{
|
||||
|
||||
const expectedAnswerFor = (
|
||||
question: GekanatorQuestion | undefined,
|
||||
correctPost: Post | null,
|
||||
): GekanatorAnswerValue | null =>
|
||||
correctPost: Post | null): GekanatorAnswerValue | null =>
|
||||
expectedAnswerForQuestion (question, correctPost)
|
||||
|
||||
|
||||
@@ -4169,8 +4108,7 @@ const GekanatorPage: FC<{ user: User | null }> = ({ user }) => {
|
||||
setSaved (true)
|
||||
setSavedGameId (data.id)
|
||||
setLearnedExampleCount (data.learnedExampleCount)
|
||||
setResultWon (variables.guessedPostId === variables.correctPostId)
|
||||
}})
|
||||
setResultWon (variables.guessedPostId === variables.correctPostId)}})
|
||||
const questionSuggestionMutation = useMutation ({
|
||||
mutationFn: saveGekanatorQuestionSuggestion,
|
||||
onSuccess: async data => {
|
||||
@@ -4180,15 +4118,13 @@ const GekanatorPage: FC<{ user: User | null }> = ({ user }) => {
|
||||
setQuestionSuggestionSearch ('')
|
||||
setQuestionSuggestionSelectedId (null)
|
||||
setQuestionSuggestion ('')
|
||||
setQuestionSuggestionAnswer ('yes')
|
||||
}})
|
||||
setQuestionSuggestionAnswer ('yes')}})
|
||||
const extraQuestionAnswersMutation = useMutation ({
|
||||
mutationFn: saveGekanatorExtraQuestionAnswers,
|
||||
onSuccess: async () => {
|
||||
await queryClient.refetchQueries ({ queryKey: gekanatorKeys.questions () })
|
||||
setExtraQuestionState ('saved')
|
||||
setPhase ('end')
|
||||
}})
|
||||
setPhase ('end')}})
|
||||
|
||||
const resetExtraQuestionState = () => {
|
||||
const next = resettableExtraQuestionState ()
|
||||
@@ -4330,8 +4266,7 @@ const GekanatorPage: FC<{ user: User | null }> = ({ user }) => {
|
||||
if (
|
||||
!(allowPreQuestionRecovery)
|
||||
|| recoveredEligiblePosts.length === 0
|
||||
|| recoveredEligiblePosts.length === 1
|
||||
)
|
||||
|| recoveredEligiblePosts.length === 1)
|
||||
return false
|
||||
|
||||
const nextQuestion = chooseQuestion ({
|
||||
@@ -4493,8 +4428,7 @@ const GekanatorPage: FC<{ user: User | null }> = ({ user }) => {
|
||||
if (
|
||||
!(nextPlan.question)
|
||||
&& !(shouldEnterGuessPhase (nextPlan.guessReason))
|
||||
&& recovered.eligiblePosts.length !== 1
|
||||
)
|
||||
&& recovered.eligiblePosts.length !== 1)
|
||||
{
|
||||
const recoveredForQuestion = recoverQuestionState ({
|
||||
nextAnswers,
|
||||
@@ -4602,8 +4536,7 @@ const GekanatorPage: FC<{ user: User | null }> = ({ user }) => {
|
||||
!(canPersistGame)
|
||||
|| reviewGuessedPostId == null
|
||||
|| reviewCorrectPostId == null
|
||||
|| saveMutation.isPending
|
||||
)
|
||||
|| saveMutation.isPending)
|
||||
return
|
||||
|
||||
if (savedGameId != null)
|
||||
@@ -4666,8 +4599,7 @@ const GekanatorPage: FC<{ user: User | null }> = ({ user }) => {
|
||||
!(canPersistGame)
|
||||
|| savedGameId == null
|
||||
|| extraQuestionAnswersMutation.isPending
|
||||
|| extraQuestions.some (question => !(extraQuestionAnswers[String (question.id)]))
|
||||
)
|
||||
|| extraQuestions.some (question => !(extraQuestionAnswers[String (question.id)])))
|
||||
return
|
||||
|
||||
extraQuestionAnswersMutation.mutate ({
|
||||
@@ -4870,8 +4802,7 @@ const GekanatorPage: FC<{ user: User | null }> = ({ user }) => {
|
||||
|
||||
const answerExtraQuestion = (
|
||||
questionId: number,
|
||||
value: GekanatorAnswerValue,
|
||||
) => {
|
||||
value: GekanatorAnswerValue) => {
|
||||
setExtraQuestionAnswers ({
|
||||
...extraQuestionAnswers,
|
||||
[String (questionId)]: value })
|
||||
@@ -4909,8 +4840,7 @@ const GekanatorPage: FC<{ user: User | null }> = ({ user }) => {
|
||||
|| isLoading
|
||||
|| acceptedQuestionsLoading
|
||||
|| shouldEnterGuessPhase (questionPlan.guessReason)
|
||||
|| eligiblePosts.length === 1
|
||||
)
|
||||
|| eligiblePosts.length === 1)
|
||||
return
|
||||
|
||||
const recovered = recoverQuestionState ({
|
||||
@@ -4926,8 +4856,7 @@ const GekanatorPage: FC<{ user: User | null }> = ({ user }) => {
|
||||
if (
|
||||
recovered.recoveryStepCount === recoveryStepCount
|
||||
&& recovered.recoveredCandidatePosts.size === recoveredCandidatePosts.size
|
||||
&& recovered.softenedQuestionIds.size === softenedQuestionIds.size
|
||||
)
|
||||
&& recovered.softenedQuestionIds.size === softenedQuestionIds.size)
|
||||
return
|
||||
|
||||
setSoftenedQuestionIds (recovered.softenedQuestionIds)
|
||||
@@ -4954,15 +4883,13 @@ const GekanatorPage: FC<{ user: User | null }> = ({ user }) => {
|
||||
if (
|
||||
phase !== 'question'
|
||||
|| isLoading
|
||||
|| acceptedQuestionsLoading
|
||||
)
|
||||
|| acceptedQuestionsLoading)
|
||||
return
|
||||
|
||||
if (
|
||||
currentQuestion
|
||||
|| !(questionPlan.guess)
|
||||
|| !(shouldEnterGuessPhase (questionPlan.guessReason))
|
||||
)
|
||||
|| !(shouldEnterGuessPhase (questionPlan.guessReason)))
|
||||
return
|
||||
|
||||
setWinningRunTargetId (questionPlan.winningRunTargetId)
|
||||
|
||||
@@ -145,8 +145,7 @@ const DeerjikistDetailPage: FC = () => {
|
||||
return rtn
|
||||
})}/>)}
|
||||
</FormField>
|
||||
</fieldset>
|
||||
))}
|
||||
</fieldset>))}
|
||||
|
||||
<div className="py-3">
|
||||
<button
|
||||
@@ -169,8 +168,7 @@ const DeerjikistDetailPage: FC = () => {
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
)}
|
||||
</div>)}
|
||||
</MainArea>)
|
||||
}
|
||||
|
||||
|
||||
@@ -45,8 +45,7 @@ const MaterialDetailPage: FC<{ user: User | null }> = ({ user }) => {
|
||||
const { data: material, isError, isLoading } = useQuery ({
|
||||
queryKey: materialsKeys.show (id ?? ''),
|
||||
queryFn: () => fetchMaterial (id ?? ''),
|
||||
enabled: id != null,
|
||||
})
|
||||
enabled: id != null})
|
||||
const materialTitle = material
|
||||
? material.tag?.name ?? `素材 #${ material.id }`
|
||||
: ''
|
||||
@@ -60,8 +59,8 @@ const MaterialDetailPage: FC<{ user: User | null }> = ({ user }) => {
|
||||
setExportPath (material.exportPaths.legacyDrive ?? '')
|
||||
if (material.file && material.contentType)
|
||||
{
|
||||
setFilePreview (material.file)
|
||||
setFile (null)
|
||||
setFilePreview (material.file)
|
||||
setFile (null)
|
||||
}
|
||||
}, [material])
|
||||
|
||||
@@ -71,42 +70,40 @@ const MaterialDetailPage: FC<{ user: User | null }> = ({ user }) => {
|
||||
|
||||
const updateMutation = useMutation ({
|
||||
mutationFn: async () => {
|
||||
const formData = new FormData
|
||||
if (tag.trim ())
|
||||
formData.append ('tag', tag)
|
||||
if (file)
|
||||
formData.append ('file', file)
|
||||
if (url.trim ())
|
||||
formData.append ('url', url)
|
||||
formData.append ('export_paths[legacy_drive]', exportPath)
|
||||
const formData = new FormData
|
||||
if (tag.trim ())
|
||||
formData.append ('tag', tag)
|
||||
if (file)
|
||||
formData.append ('file', file)
|
||||
if (url.trim ())
|
||||
formData.append ('url', url)
|
||||
formData.append ('export_paths[legacy_drive]', exportPath)
|
||||
|
||||
return await updateMaterial (id ?? '', formData)
|
||||
return await updateMaterial (id ?? '', formData)
|
||||
},
|
||||
onSuccess: async data => {
|
||||
qc.setQueryData (materialsKeys.show (id ?? ''), data)
|
||||
await invalidateMaterialQueries ()
|
||||
toast ({ title: '更新成功!' })
|
||||
qc.setQueryData (materialsKeys.show (id ?? ''), data)
|
||||
await invalidateMaterialQueries ()
|
||||
toast ({ title: '更新成功!' })
|
||||
},
|
||||
onError: error => {
|
||||
applyValidationError (error)
|
||||
toast ({ title: '更新失敗……', description: '入力を見直してください.' })
|
||||
},
|
||||
})
|
||||
applyValidationError (error)
|
||||
toast ({ title: '更新失敗……', description: '入力を見直してください.' })
|
||||
}})
|
||||
|
||||
const suppressMutation = useMutation ({
|
||||
mutationFn: async (reason: string) =>
|
||||
await suppressMaterialFile (id ?? '', { reason }),
|
||||
await suppressMaterialFile (id ?? '', { reason }),
|
||||
onSuccess: async data => {
|
||||
qc.setQueryData (materialsKeys.show (id ?? ''), data)
|
||||
setFile (null)
|
||||
setFilePreview ('')
|
||||
await invalidateMaterialQueries ()
|
||||
toast ({ title: '抑止しました' })
|
||||
qc.setQueryData (materialsKeys.show (id ?? ''), data)
|
||||
setFile (null)
|
||||
setFilePreview ('')
|
||||
await invalidateMaterialQueries ()
|
||||
toast ({ title: '抑止しました' })
|
||||
},
|
||||
onError: () => {
|
||||
toast ({ title: '抑止に失敗しました' })
|
||||
},
|
||||
})
|
||||
toast ({ title: '抑止に失敗しました' })
|
||||
}})
|
||||
|
||||
const handleSubmit = () => {
|
||||
clearValidationErrors ()
|
||||
@@ -125,155 +122,153 @@ const MaterialDetailPage: FC<{ user: User | null }> = ({ user }) => {
|
||||
|
||||
return (
|
||||
<MainArea>
|
||||
{material && (
|
||||
<Helmet>
|
||||
<title>{`${ materialTitle } 素材照会 | ${ SITE_TITLE }`}</title>
|
||||
</Helmet>)}
|
||||
{material && (
|
||||
<Helmet>
|
||||
<title>{`${ materialTitle } 素材照会 | ${ SITE_TITLE }`}</title>
|
||||
</Helmet>)}
|
||||
|
||||
{isLoading ? 'Loading...' : isError ? (
|
||||
<p className="text-red-600 dark:text-red-300">
|
||||
素材の取得に失敗しました.
|
||||
</p>
|
||||
) : material == null ? (
|
||||
<p className="text-stone-700 dark:text-stone-300">
|
||||
素材が見つかりませんでした.
|
||||
</p>
|
||||
) : (
|
||||
<>
|
||||
<PageTitle>
|
||||
{material.tag
|
||||
? (
|
||||
<TagLink
|
||||
tag={material.tag}
|
||||
withWiki={false}
|
||||
withCount={false}/>)
|
||||
: materialTitle}
|
||||
</PageTitle>
|
||||
{isLoading ? 'Loading...' : isError ? (
|
||||
<p className="text-red-600 dark:text-red-300">
|
||||
素材の取得に失敗しました.
|
||||
</p>) : material == null ? (
|
||||
<p className="text-stone-700 dark:text-stone-300">
|
||||
素材が見つかりませんでした.
|
||||
</p>) : (
|
||||
<>
|
||||
<PageTitle>
|
||||
{material.tag
|
||||
? (
|
||||
<TagLink
|
||||
tag={material.tag}
|
||||
withWiki={false}
|
||||
withCount={false}/>)
|
||||
: materialTitle}
|
||||
</PageTitle>
|
||||
|
||||
{material.fileSuppressedAt && (
|
||||
<div className="mb-4 rounded border border-red-300 bg-red-50 p-3
|
||||
text-red-900 dark:border-red-800 dark:bg-red-950
|
||||
dark:text-red-100">
|
||||
<span>素材ファイルは抑止済みです。</span>
|
||||
{material.fileSuppressionReason && (
|
||||
<span> 理由: {material.fileSuppressionReason}</span>)}
|
||||
</div>)}
|
||||
{material.fileSuppressedAt && (
|
||||
<div className="mb-4 rounded border border-red-300 bg-red-50 p-3
|
||||
text-red-900 dark:border-red-800 dark:bg-red-950
|
||||
dark:text-red-100">
|
||||
<span>素材ファイルは抑止済みです。</span>
|
||||
{material.fileSuppressionReason && (
|
||||
<span> 理由: {material.fileSuppressionReason}</span>)}
|
||||
</div>)}
|
||||
|
||||
{(!material.fileSuppressedAt && material.file && material.contentType) && (
|
||||
(/image\/.*/.test (material.contentType) && (
|
||||
<img src={material.file} alt={material.tag?.name || undefined}/>))
|
||||
|| (/video\/.*/.test (material.contentType) && (
|
||||
<video src={material.file} controls/>))
|
||||
|| (/audio\/.*/.test (material.contentType) && (
|
||||
<audio src={material.file} controls/>)))}
|
||||
{(!material.fileSuppressedAt && material.file && material.contentType) && (
|
||||
(/image\/.*/.test (material.contentType) && (
|
||||
<img src={material.file} alt={material.tag?.name || undefined}/>))
|
||||
|| (/video\/.*/.test (material.contentType) && (
|
||||
<video src={material.file} controls/>))
|
||||
|| (/audio\/.*/.test (material.contentType) && (
|
||||
<audio src={material.file} controls/>)))}
|
||||
|
||||
<TabGroup>
|
||||
<Tab name="Wiki">
|
||||
{material.tag
|
||||
? (
|
||||
<WikiBody
|
||||
title={material.tag.name}
|
||||
body={material.wikiPageBody ?? undefined}/>)
|
||||
: (
|
||||
<p className="text-stone-700 dark:text-stone-300">
|
||||
タグ未設定の素材です.
|
||||
</p>)}
|
||||
</Tab>
|
||||
<TabGroup>
|
||||
<Tab name="Wiki">
|
||||
{material.tag
|
||||
? (
|
||||
<WikiBody
|
||||
title={material.tag.name}
|
||||
body={material.wikiPageBody ?? undefined}/>)
|
||||
: (
|
||||
<p className="text-stone-700 dark:text-stone-300">
|
||||
タグ未設定の素材です.
|
||||
</p>)}
|
||||
</Tab>
|
||||
|
||||
<Tab name="編輯">
|
||||
<div className="max-w-wl space-y-4 pt-2">
|
||||
<FieldError messages={baseErrors}/>
|
||||
<Tab name="編輯">
|
||||
<div className="max-w-wl space-y-4 pt-2">
|
||||
<FieldError messages={baseErrors}/>
|
||||
|
||||
<FormField label="タグ" messages={fieldErrors.tag}>
|
||||
{({ describedBy, invalid }) => (
|
||||
<TagInput
|
||||
describedBy={describedBy}
|
||||
invalid={invalid}
|
||||
value={tag}
|
||||
setValue={setTag}/>)}
|
||||
</FormField>
|
||||
<FormField label="タグ" messages={fieldErrors.tag}>
|
||||
{({ describedBy, invalid }) => (
|
||||
<TagInput
|
||||
describedBy={describedBy}
|
||||
invalid={invalid}
|
||||
value={tag}
|
||||
setValue={setTag}/>)}
|
||||
</FormField>
|
||||
|
||||
<FormField label="ファイル" messages={fieldErrors.file}>
|
||||
{({ describedBy, invalid }) => (
|
||||
<>
|
||||
<input
|
||||
type="file"
|
||||
accept="image/*,video/*,audio/*"
|
||||
aria-describedby={describedBy}
|
||||
aria-invalid={invalid}
|
||||
onChange={e => {
|
||||
const nextFile = e.target.files?.[0]
|
||||
setFile (nextFile ?? null)
|
||||
setFilePreview (
|
||||
nextFile ? URL.createObjectURL (nextFile) : '')
|
||||
}}/>
|
||||
{(file && filePreview) && (
|
||||
(/image\/.*/.test (file.type) && (
|
||||
<img
|
||||
src={filePreview}
|
||||
alt="preview"
|
||||
className="mt-2 max-h-48 rounded border"/>))
|
||||
|| (/video\/.*/.test (file.type) && (
|
||||
<video
|
||||
src={filePreview}
|
||||
controls
|
||||
className="mt-2 max-h-48 rounded border"/>))
|
||||
|| (/audio\/.*/.test (file.type) && (
|
||||
<audio
|
||||
src={filePreview}
|
||||
controls
|
||||
className="mt-2 max-h-48"/>))
|
||||
|| (
|
||||
<p className="text-red-600 dark:text-red-400">
|
||||
その形式のファイルには対応していません.
|
||||
</p>))}
|
||||
</>)}
|
||||
</FormField>
|
||||
<FormField label="ファイル" messages={fieldErrors.file}>
|
||||
{({ describedBy, invalid }) => (
|
||||
<>
|
||||
<input
|
||||
type="file"
|
||||
accept="image/*,video/*,audio/*"
|
||||
aria-describedby={describedBy}
|
||||
aria-invalid={invalid}
|
||||
onChange={e => {
|
||||
const nextFile = e.target.files?.[0]
|
||||
setFile (nextFile ?? null)
|
||||
setFilePreview (
|
||||
nextFile ? URL.createObjectURL (nextFile) : '')
|
||||
}}/>
|
||||
{(file && filePreview) && (
|
||||
(/image\/.*/.test (file.type) && (
|
||||
<img
|
||||
src={filePreview}
|
||||
alt="preview"
|
||||
className="mt-2 max-h-48 rounded border"/>))
|
||||
|| (/video\/.*/.test (file.type) && (
|
||||
<video
|
||||
src={filePreview}
|
||||
controls
|
||||
className="mt-2 max-h-48 rounded border"/>))
|
||||
|| (/audio\/.*/.test (file.type) && (
|
||||
<audio
|
||||
src={filePreview}
|
||||
controls
|
||||
className="mt-2 max-h-48"/>))
|
||||
|| (
|
||||
<p className="text-red-600 dark:text-red-400">
|
||||
その形式のファイルには対応していません.
|
||||
</p>))}
|
||||
</>)}
|
||||
</FormField>
|
||||
|
||||
<FormField label="参考 URL" messages={fieldErrors.url}>
|
||||
{({ describedBy, invalid }) => (
|
||||
<input
|
||||
type="url"
|
||||
value={url}
|
||||
onChange={e => setURL (e.target.value)}
|
||||
aria-describedby={describedBy}
|
||||
aria-invalid={invalid}
|
||||
className={inputClass (invalid)}/>)}
|
||||
</FormField>
|
||||
<FormField label="参考 URL" messages={fieldErrors.url}>
|
||||
{({ describedBy, invalid }) => (
|
||||
<input
|
||||
type="url"
|
||||
value={url}
|
||||
onChange={e => setURL (e.target.value)}
|
||||
aria-describedby={describedBy}
|
||||
aria-invalid={invalid}
|
||||
className={inputClass (invalid)}/>)}
|
||||
</FormField>
|
||||
|
||||
<FormField label="ZIP 出力パス" messages={fieldErrors.exportPaths}>
|
||||
{({ describedBy, invalid }) => (
|
||||
<input
|
||||
type="text"
|
||||
value={exportPath}
|
||||
onChange={e => setExportPath (e.target.value)}
|
||||
placeholder="伊地知ニジカ/表情/泣き.png"
|
||||
aria-describedby={describedBy}
|
||||
aria-invalid={invalid}
|
||||
className={inputClass (invalid)}/>)}
|
||||
</FormField>
|
||||
<FormField label="ZIP 出力パス" messages={fieldErrors.exportPaths}>
|
||||
{({ describedBy, invalid }) => (
|
||||
<input
|
||||
type="text"
|
||||
value={exportPath}
|
||||
onChange={e => setExportPath (e.target.value)}
|
||||
placeholder="伊地知ニジカ/表情/泣き.png"
|
||||
aria-describedby={describedBy}
|
||||
aria-invalid={invalid}
|
||||
className={inputClass (invalid)}/>)}
|
||||
</FormField>
|
||||
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button
|
||||
onClick={handleSubmit}
|
||||
className="rounded bg-blue-600 px-4 py-2 text-white
|
||||
disabled:bg-gray-400"
|
||||
disabled={updateMutation.isPending}>
|
||||
更新
|
||||
</Button>
|
||||
{user?.role === 'admin' && !material.fileSuppressedAt && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="destructive"
|
||||
onClick={handleSuppress}
|
||||
disabled={suppressMutation.isPending}>
|
||||
ファイルを抑止
|
||||
</Button>)}
|
||||
</div>
|
||||
</div>
|
||||
</Tab>
|
||||
</TabGroup>
|
||||
</>)}
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button
|
||||
onClick={handleSubmit}
|
||||
className="rounded bg-blue-600 px-4 py-2 text-white
|
||||
disabled:bg-gray-400"
|
||||
disabled={updateMutation.isPending}>
|
||||
更新
|
||||
</Button>
|
||||
{user?.role === 'admin' && !material.fileSuppressedAt && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="destructive"
|
||||
onClick={handleSuppress}
|
||||
disabled={suppressMutation.isPending}>
|
||||
ファイルを抑止
|
||||
</Button>)}
|
||||
</div>
|
||||
</div>
|
||||
</Tab>
|
||||
</TabGroup>
|
||||
</>)}
|
||||
</MainArea>)
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,7 @@ import type {
|
||||
MaterialIndexSort,
|
||||
MaterialIndexSuppression,
|
||||
MaterialIndexTagState,
|
||||
MaterialIndexView,
|
||||
} from '@/types'
|
||||
MaterialIndexView } from '@/types'
|
||||
|
||||
const MEDIA_KIND_LABELS: Record<Material['mediaKind'], string> = {
|
||||
image: '画像',
|
||||
@@ -34,8 +33,7 @@ const MEDIA_KIND_LABELS: Record<Material['mediaKind'], string> = {
|
||||
audio: '音声',
|
||||
file_other: 'その他ファイル',
|
||||
url_only: 'URL のみ',
|
||||
suppressed: '抑止済み',
|
||||
}
|
||||
suppressed: '抑止済み'}
|
||||
|
||||
const MEDIA_FILTER_LABELS: Record<MaterialIndexMediaKind, string> = {
|
||||
all: 'すべて',
|
||||
@@ -43,8 +41,7 @@ const MEDIA_FILTER_LABELS: Record<MaterialIndexMediaKind, string> = {
|
||||
video: '動画',
|
||||
audio: '音声',
|
||||
file_other: 'その他ファイル',
|
||||
url_only: 'URL のみ',
|
||||
}
|
||||
url_only: 'URL のみ'}
|
||||
|
||||
const SORT_LABELS: Record<MaterialIndexSort, string> = {
|
||||
created_at: '作成日時',
|
||||
@@ -53,8 +50,7 @@ const SORT_LABELS: Record<MaterialIndexSort, string> = {
|
||||
media_kind: '種類',
|
||||
file_byte_size: 'ファイルサイズ',
|
||||
version_no: 'バージョン',
|
||||
id: 'ID',
|
||||
}
|
||||
id: 'ID'}
|
||||
|
||||
|
||||
const setIf = (qs: URLSearchParams, key: string, value: string | null) => {
|
||||
@@ -67,8 +63,7 @@ const setIf = (qs: URLSearchParams, key: string, value: string | null) => {
|
||||
const parseOption = <T extends string> (
|
||||
value: string | null,
|
||||
allowed: readonly T[],
|
||||
fallback: T,
|
||||
): T => allowed.includes (value as T) ? value as T : fallback
|
||||
fallback: T): T => allowed.includes (value as T) ? value as T : fallback
|
||||
|
||||
|
||||
const fileSizeText = (bytes: number | null): string => {
|
||||
@@ -88,92 +83,88 @@ const materialTitle = (material: Material): string =>
|
||||
|
||||
const MaterialThumb: FC<{ material: Material }> = ({ material }) => (
|
||||
<div
|
||||
className={`flex aspect-square h-[180px] w-[180px] items-center justify-center
|
||||
overflow-hidden rounded-lg border text-center shadow-sm ${
|
||||
material.fileSuppressedAt
|
||||
? [
|
||||
'border-red-300 bg-red-50 text-red-900 dark:border-red-800',
|
||||
'dark:bg-red-950 dark:text-red-100',
|
||||
].join (' ')
|
||||
: [
|
||||
'border-stone-200 bg-white text-stone-900 dark:border-stone-700',
|
||||
'dark:bg-stone-900 dark:text-stone-100',
|
||||
].join (' ') }`}>
|
||||
className={`flex aspect-square h-[180px] w-[180px] items-center justify-center
|
||||
overflow-hidden rounded-lg border text-center shadow-sm ${
|
||||
material.fileSuppressedAt
|
||||
? [
|
||||
'border-red-300 bg-red-50 text-red-900 dark:border-red-800',
|
||||
'dark:bg-red-950 dark:text-red-100'].join (' ')
|
||||
: [
|
||||
'border-stone-200 bg-white text-stone-900 dark:border-stone-700',
|
||||
'dark:bg-stone-900 dark:text-stone-100'].join (' ') }`}>
|
||||
{material.thumbnail
|
||||
? <img src={material.thumbnail} alt="" className="h-full w-full object-contain"/>
|
||||
: (
|
||||
<span
|
||||
className="px-2 text-2xl leading-tight"
|
||||
style={{ fontFamily: material.thumbnailFallbackKind === 'tag_name'
|
||||
<span
|
||||
className="px-2 text-2xl leading-tight"
|
||||
style={{ fontFamily: material.thumbnailFallbackKind === 'tag_name'
|
||||
? 'Nikumaru'
|
||||
: undefined }}>
|
||||
{material.thumbnailFallbackText}
|
||||
</span>)}
|
||||
{material.thumbnailFallbackText}
|
||||
</span>)}
|
||||
</div>)
|
||||
|
||||
|
||||
const MaterialCard: FC<{ material: Material }> = ({ material }) => (
|
||||
<article className="w-[180px] justify-self-center">
|
||||
<PrefetchLink to={`/materials/${ material.id }`} className="block">
|
||||
<MaterialThumb material={material}/>
|
||||
<div className="mt-2 w-[180px]">
|
||||
<p className="truncate text-sm font-medium text-stone-900 dark:text-stone-100">
|
||||
{materialTitle (material)}
|
||||
</p>
|
||||
<p className="truncate text-xs text-stone-600 dark:text-stone-300">
|
||||
{MEDIA_KIND_LABELS[material.mediaKind]} / {dateString (material.createdAt)}
|
||||
</p>
|
||||
</div>
|
||||
<MaterialThumb material={material}/>
|
||||
<div className="mt-2 w-[180px]">
|
||||
<p className="truncate text-sm font-medium text-stone-900 dark:text-stone-100">
|
||||
{materialTitle (material)}
|
||||
</p>
|
||||
<p className="truncate text-xs text-stone-600 dark:text-stone-300">
|
||||
{MEDIA_KIND_LABELS[material.mediaKind]} / {dateString (material.createdAt)}
|
||||
</p>
|
||||
</div>
|
||||
</PrefetchLink>
|
||||
</article>)
|
||||
|
||||
|
||||
const MaterialListItem: FC<{ material: Material }> = ({ material }) => (
|
||||
<article
|
||||
className={`rounded-lg border p-3 shadow-sm ${
|
||||
material.fileSuppressedAt
|
||||
? [
|
||||
'border-red-200 bg-red-50 text-red-900 dark:border-red-900',
|
||||
'dark:bg-red-950 dark:text-red-100',
|
||||
].join (' ')
|
||||
: [
|
||||
'border-stone-200 bg-white text-stone-900 dark:border-stone-700',
|
||||
'dark:bg-stone-900 dark:text-stone-100',
|
||||
].join (' ')}`}>
|
||||
className={`rounded-lg border p-3 shadow-sm ${
|
||||
material.fileSuppressedAt
|
||||
? [
|
||||
'border-red-200 bg-red-50 text-red-900 dark:border-red-900',
|
||||
'dark:bg-red-950 dark:text-red-100'].join (' ')
|
||||
: [
|
||||
'border-stone-200 bg-white text-stone-900 dark:border-stone-700',
|
||||
'dark:bg-stone-900 dark:text-stone-100'].join (' ')}`}>
|
||||
<div className="flex gap-3">
|
||||
<MaterialThumb material={material}/>
|
||||
<div className="min-w-0 flex-1 space-y-2">
|
||||
<div>
|
||||
<PrefetchLink
|
||||
to={`/materials/${ material.id }`}
|
||||
className="font-medium text-sky-700 underline underline-offset-2
|
||||
dark:text-sky-300">
|
||||
{materialTitle (material)}
|
||||
</PrefetchLink>
|
||||
{material.fileSuppressedAt && (
|
||||
<p className="mt-1 text-sm text-red-700 dark:text-red-200">抑止済み</p>)}
|
||||
</div>
|
||||
<dl className="space-y-1 text-sm text-stone-600 dark:text-stone-300">
|
||||
<div>
|
||||
<dt className="inline">種類: </dt>
|
||||
<dd className="inline">{MEDIA_KIND_LABELS[material.mediaKind]}</dd>
|
||||
</div>
|
||||
{material.fileByteSize != null && (
|
||||
<div>
|
||||
<dt className="inline">サイズ: </dt>
|
||||
<dd className="inline">{fileSizeText (material.fileByteSize)}</dd>
|
||||
</div>)}
|
||||
{material.url && (
|
||||
<div>
|
||||
<dt className="inline">URL: </dt>
|
||||
<dd className="inline break-all">{material.url}</dd>
|
||||
</div>)}
|
||||
<div>
|
||||
<dt className="inline">作成: </dt>
|
||||
<dd className="inline">{dateString (material.createdAt)}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</div>
|
||||
<MaterialThumb material={material}/>
|
||||
<div className="min-w-0 flex-1 space-y-2">
|
||||
<div>
|
||||
<PrefetchLink
|
||||
to={`/materials/${ material.id }`}
|
||||
className="font-medium text-sky-700 underline underline-offset-2
|
||||
dark:text-sky-300">
|
||||
{materialTitle (material)}
|
||||
</PrefetchLink>
|
||||
{material.fileSuppressedAt && (
|
||||
<p className="mt-1 text-sm text-red-700 dark:text-red-200">抑止済み</p>)}
|
||||
</div>
|
||||
<dl className="space-y-1 text-sm text-stone-600 dark:text-stone-300">
|
||||
<div>
|
||||
<dt className="inline">種類: </dt>
|
||||
<dd className="inline">{MEDIA_KIND_LABELS[material.mediaKind]}</dd>
|
||||
</div>
|
||||
{material.fileByteSize != null && (
|
||||
<div>
|
||||
<dt className="inline">サイズ: </dt>
|
||||
<dd className="inline">{fileSizeText (material.fileByteSize)}</dd>
|
||||
</div>)}
|
||||
{material.url && (
|
||||
<div>
|
||||
<dt className="inline">URL: </dt>
|
||||
<dd className="inline break-all">{material.url}</dd>
|
||||
</div>)}
|
||||
<div>
|
||||
<dt className="inline">作成: </dt>
|
||||
<dd className="inline">{dateString (material.createdAt)}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
</article>)
|
||||
|
||||
@@ -190,9 +181,9 @@ const MaterialListPage: FC = () => {
|
||||
const tagState = query.get ('unclassified') === '1'
|
||||
? 'untagged'
|
||||
: parseOption<MaterialIndexTagState> (
|
||||
query.get ('tag_state'),
|
||||
['all', 'tagged', 'untagged'],
|
||||
'all')
|
||||
query.get ('tag_state'),
|
||||
['all', 'tagged', 'untagged'],
|
||||
'all')
|
||||
const mediaKind = parseOption<MaterialIndexMediaKind> (
|
||||
query.get ('media_kind'),
|
||||
['all', 'image', 'video', 'audio', 'file_other', 'url_only'],
|
||||
@@ -239,12 +230,10 @@ const MaterialListPage: FC = () => {
|
||||
direction,
|
||||
view,
|
||||
page,
|
||||
limit,
|
||||
}
|
||||
limit}
|
||||
const { data, isLoading, isError } = useQuery ({
|
||||
queryKey: materialsKeys.index (keys),
|
||||
queryFn: () => fetchMaterials (keys),
|
||||
})
|
||||
queryFn: () => fetchMaterials (keys)})
|
||||
const materials = data?.materials ?? []
|
||||
const totalPages = data ? Math.ceil (data.count / limit) : 0
|
||||
|
||||
@@ -289,214 +278,203 @@ const MaterialListPage: FC = () => {
|
||||
|
||||
return (
|
||||
<MainArea>
|
||||
<Helmet>
|
||||
<style>
|
||||
{`
|
||||
@font-face
|
||||
{
|
||||
font-family: 'Nikumaru';
|
||||
src: url(${ nikumaru }) format('opentype');
|
||||
}`}
|
||||
</style>
|
||||
<title>{`素材一覧 | ${ SITE_TITLE }`}</title>
|
||||
</Helmet>
|
||||
<Helmet>
|
||||
<style>
|
||||
{`
|
||||
@font-face
|
||||
{
|
||||
font-family: 'Nikumaru';
|
||||
src: url(${ nikumaru }) format('opentype');
|
||||
}`}
|
||||
</style>
|
||||
<title>{`素材一覧 | ${ SITE_TITLE }`}</title>
|
||||
</Helmet>
|
||||
|
||||
<div className="space-y-5">
|
||||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||
<PageTitle>素材一覧</PageTitle>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<PrefetchLink
|
||||
to={`/materials?tag_state=untagged&material_filter=${ materialFilter }`}
|
||||
className="rounded-full border border-stone-300 bg-white px-4 py-2 text-sm
|
||||
text-stone-900 hover:bg-stone-100 dark:border-stone-700
|
||||
dark:bg-stone-900 dark:text-stone-100 dark:hover:bg-stone-800">
|
||||
未分類素材
|
||||
</PrefetchLink>
|
||||
<PrefetchLink
|
||||
to="/materials/new"
|
||||
className="rounded-full border border-stone-300 bg-white px-4 py-2 text-sm
|
||||
text-stone-900 hover:bg-stone-100 dark:border-stone-700
|
||||
dark:bg-stone-900 dark:text-stone-100 dark:hover:bg-stone-800">
|
||||
新規素材を追加
|
||||
</PrefetchLink>
|
||||
<a
|
||||
href={`${ API_BASE_URL }/materials/download.zip?profile=legacy_drive`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="rounded-full border border-stone-300 bg-white px-4 py-2 text-sm
|
||||
text-stone-900 hover:bg-stone-100 dark:border-stone-700
|
||||
dark:bg-stone-900 dark:text-stone-100 dark:hover:bg-stone-800">
|
||||
ZIP をダウンロード
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-y-5">
|
||||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||
<PageTitle>素材一覧</PageTitle>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<PrefetchLink
|
||||
to="/materials/new"
|
||||
className="rounded-full border border-stone-300 bg-white px-4 py-2 text-sm
|
||||
text-stone-900 hover:bg-stone-100 dark:border-stone-700
|
||||
dark:bg-stone-900 dark:text-stone-100 dark:hover:bg-stone-800">
|
||||
新規素材を追加
|
||||
</PrefetchLink>
|
||||
<a
|
||||
href={`${ API_BASE_URL }/materials/download.zip?profile=legacy_drive`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="rounded-full border border-stone-300 bg-white px-4 py-2 text-sm
|
||||
text-stone-900 hover:bg-stone-100 dark:border-stone-700
|
||||
dark:bg-stone-900 dark:text-stone-100 dark:hover:bg-stone-800">
|
||||
ZIP をダウンロード
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{tagState === 'untagged' && (
|
||||
<PrefetchLink
|
||||
to={`/materials?material_filter=${ materialFilter }`}
|
||||
className="text-sm text-sky-700 underline underline-offset-2 dark:text-sky-300">
|
||||
素材検索トップへ戻る
|
||||
</PrefetchLink>)}
|
||||
{tagState === 'untagged' && (
|
||||
<PrefetchLink
|
||||
to={`/materials?material_filter=${ materialFilter }`}
|
||||
className="text-sm text-sky-700 underline underline-offset-2 dark:text-sky-300">
|
||||
素材検索トップへ戻る
|
||||
</PrefetchLink>)}
|
||||
|
||||
<form
|
||||
onSubmit={search}
|
||||
className="max-w-3xl rounded-lg border border-stone-200 bg-white p-4
|
||||
text-stone-900 dark:border-stone-700 dark:bg-stone-900
|
||||
dark:text-stone-100">
|
||||
<div className="space-y-3">
|
||||
<FormField label="検索">
|
||||
{({ invalid }) => (
|
||||
<input
|
||||
type="search"
|
||||
value={q}
|
||||
onChange={e => setQ (e.target.value)}
|
||||
placeholder="タグ名 / URL / ファイル名"
|
||||
className={inputClass (invalid)}/>)}
|
||||
</FormField>
|
||||
<form
|
||||
onSubmit={search}
|
||||
className="max-w-3xl rounded-lg border border-stone-200 bg-white p-4
|
||||
text-stone-900 dark:border-stone-700 dark:bg-stone-900
|
||||
dark:text-stone-100">
|
||||
<div className="space-y-3">
|
||||
<FormField label="検索">
|
||||
{({ invalid }) => (
|
||||
<input
|
||||
type="search"
|
||||
value={q}
|
||||
onChange={e => setQ (e.target.value)}
|
||||
placeholder="タグ名 / URL / ファイル名"
|
||||
className={inputClass (invalid)}/>)}
|
||||
</FormField>
|
||||
|
||||
<FormField label="タグ状態">
|
||||
{({ invalid }) => (
|
||||
<select
|
||||
value={tagStateInput}
|
||||
onChange={e => setTagStateInput (
|
||||
e.target.value as MaterialIndexTagState)}
|
||||
className={inputClass (invalid)}>
|
||||
<option value="all">すべて</option>
|
||||
<option value="tagged">タグあり</option>
|
||||
<option value="untagged">タグなし</option>
|
||||
</select>)}
|
||||
</FormField>
|
||||
<FormField label="タグ状態">
|
||||
{({ invalid }) => (
|
||||
<select
|
||||
value={tagStateInput}
|
||||
onChange={e => setTagStateInput (
|
||||
e.target.value as MaterialIndexTagState)}
|
||||
className={inputClass (invalid)}>
|
||||
<option value="all">すべて</option>
|
||||
<option value="tagged">タグあり</option>
|
||||
<option value="untagged">タグなし</option>
|
||||
</select>)}
|
||||
</FormField>
|
||||
|
||||
<FormField label="メディア">
|
||||
{({ invalid }) => (
|
||||
<select
|
||||
value={mediaKindInput}
|
||||
onChange={e => setMediaKindInput (
|
||||
e.target.value as MaterialIndexMediaKind)}
|
||||
className={inputClass (invalid)}>
|
||||
{Object.entries (MEDIA_FILTER_LABELS).map (([value, label]) => (
|
||||
<option key={value} value={value}>
|
||||
{label}
|
||||
</option>))}
|
||||
</select>)}
|
||||
</FormField>
|
||||
<FormField label="メディア">
|
||||
{({ invalid }) => (
|
||||
<select
|
||||
value={mediaKindInput}
|
||||
onChange={e => setMediaKindInput (
|
||||
e.target.value as MaterialIndexMediaKind)}
|
||||
className={inputClass (invalid)}>
|
||||
{Object.entries (MEDIA_FILTER_LABELS).map (([value, label]) => (
|
||||
<option key={value} value={value}>
|
||||
{label}
|
||||
</option>))}
|
||||
</select>)}
|
||||
</FormField>
|
||||
|
||||
<FormField label="抑止状態">
|
||||
{({ invalid }) => (
|
||||
<select
|
||||
value={suppressionInput}
|
||||
onChange={e => setSuppressionInput (
|
||||
e.target.value as MaterialIndexSuppression)}
|
||||
className={inputClass (invalid)}>
|
||||
<option value="active">有効のみ</option>
|
||||
<option value="suppressed">抑止済みのみ</option>
|
||||
<option value="all">すべて</option>
|
||||
</select>)}
|
||||
</FormField>
|
||||
<FormField label="抑止状態">
|
||||
{({ invalid }) => (
|
||||
<select
|
||||
value={suppressionInput}
|
||||
onChange={e => setSuppressionInput (
|
||||
e.target.value as MaterialIndexSuppression)}
|
||||
className={inputClass (invalid)}>
|
||||
<option value="active">有効のみ</option>
|
||||
<option value="suppressed">抑止済みのみ</option>
|
||||
<option value="all">すべて</option>
|
||||
</select>)}
|
||||
</FormField>
|
||||
|
||||
<FormField label="作成日時">
|
||||
{() => (
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<DateTimeField value={createdFrom ?? undefined} onChange={setCreatedFrom}/>
|
||||
<span>〜</span>
|
||||
<DateTimeField value={createdTo ?? undefined} onChange={setCreatedTo}/>
|
||||
</div>)}
|
||||
</FormField>
|
||||
<FormField label="作成日時">
|
||||
{() => (
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<DateTimeField value={createdFrom ?? undefined} onChange={setCreatedFrom}/>
|
||||
<span>〜</span>
|
||||
<DateTimeField value={createdTo ?? undefined} onChange={setCreatedTo}/>
|
||||
</div>)}
|
||||
</FormField>
|
||||
|
||||
<FormField label="更新日時">
|
||||
{() => (
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<DateTimeField value={updatedFrom ?? undefined} onChange={setUpdatedFrom}/>
|
||||
<span>〜</span>
|
||||
<DateTimeField value={updatedTo ?? undefined} onChange={setUpdatedTo}/>
|
||||
</div>)}
|
||||
</FormField>
|
||||
</div>
|
||||
<FormField label="更新日時">
|
||||
{() => (
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<DateTimeField value={updatedFrom ?? undefined} onChange={setUpdatedFrom}/>
|
||||
<span>〜</span>
|
||||
<DateTimeField value={updatedTo ?? undefined} onChange={setUpdatedTo}/>
|
||||
</div>)}
|
||||
</FormField>
|
||||
</div>
|
||||
|
||||
<div className="mt-4 flex flex-wrap gap-3">
|
||||
<button
|
||||
type="submit"
|
||||
className="rounded bg-sky-600 px-4 py-2 text-white hover:bg-sky-700
|
||||
dark:bg-sky-500 dark:text-stone-950 dark:hover:bg-sky-400">
|
||||
検索
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
<div className="mt-4 flex flex-wrap gap-3">
|
||||
<button
|
||||
type="submit"
|
||||
className="rounded bg-sky-600 px-4 py-2 text-white hover:bg-sky-700
|
||||
dark:bg-sky-500 dark:text-stone-950 dark:hover:bg-sky-400">
|
||||
検索
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => updateQuery ({ view: 'card' })}
|
||||
className={`rounded-full border px-4 py-2 text-sm ${
|
||||
view === 'card'
|
||||
? [
|
||||
'border-sky-500 bg-sky-50 text-sky-700 dark:border-sky-400',
|
||||
'dark:bg-sky-950 dark:text-sky-100',
|
||||
].join (' ')
|
||||
: [
|
||||
'border-stone-300 bg-white text-stone-900 dark:border-stone-700',
|
||||
'dark:bg-stone-900 dark:text-stone-100',
|
||||
].join (' ') }`}>
|
||||
カード
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => updateQuery ({ view: 'list' })}
|
||||
className={`rounded-full border px-4 py-2 text-sm ${
|
||||
view === 'list'
|
||||
? [
|
||||
'border-sky-500 bg-sky-50 text-sky-700 dark:border-sky-400',
|
||||
'dark:bg-sky-950 dark:text-sky-100',
|
||||
].join (' ')
|
||||
: [
|
||||
'border-stone-300 bg-white text-stone-900 dark:border-stone-700',
|
||||
'dark:bg-stone-900 dark:text-stone-100',
|
||||
].join (' ') }`}>
|
||||
一覧
|
||||
</button>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => updateQuery ({ view: 'card' })}
|
||||
className={`rounded-full border px-4 py-2 text-sm ${
|
||||
view === 'card'
|
||||
? [
|
||||
'border-sky-500 bg-sky-50 text-sky-700 dark:border-sky-400',
|
||||
'dark:bg-sky-950 dark:text-sky-100'].join (' ')
|
||||
: [
|
||||
'border-stone-300 bg-white text-stone-900 dark:border-stone-700',
|
||||
'dark:bg-stone-900 dark:text-stone-100'].join (' ') }`}>
|
||||
カード
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => updateQuery ({ view: 'list' })}
|
||||
className={`rounded-full border px-4 py-2 text-sm ${
|
||||
view === 'list'
|
||||
? [
|
||||
'border-sky-500 bg-sky-50 text-sky-700 dark:border-sky-400',
|
||||
'dark:bg-sky-950 dark:text-sky-100'].join (' ')
|
||||
: [
|
||||
'border-stone-300 bg-white text-stone-900 dark:border-stone-700',
|
||||
'dark:bg-stone-900 dark:text-stone-100'].join (' ') }`}>
|
||||
一覧
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-2 text-sm">
|
||||
<select
|
||||
value={sort}
|
||||
onChange={e => updateQuery ({ sort: e.target.value, page: '1' })}
|
||||
className={inputClass (false, 'w-auto')}>
|
||||
{Object.entries (SORT_LABELS).map (([value, label]) => (
|
||||
<option key={value} value={value}>
|
||||
{label}
|
||||
</option>))}
|
||||
</select>
|
||||
<select
|
||||
value={direction}
|
||||
onChange={e => updateQuery ({ direction: e.target.value, page: '1' })}
|
||||
className={inputClass (false, 'w-auto')}>
|
||||
<option value="desc">降順</option>
|
||||
<option value="asc">昇順</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-2 text-sm">
|
||||
<select
|
||||
value={sort}
|
||||
onChange={e => updateQuery ({ sort: e.target.value, page: '1' })}
|
||||
className={inputClass (false, 'w-auto')}>
|
||||
{Object.entries (SORT_LABELS).map (([value, label]) => (
|
||||
<option key={value} value={value}>
|
||||
{label}
|
||||
</option>))}
|
||||
</select>
|
||||
<select
|
||||
value={direction}
|
||||
onChange={e => updateQuery ({ direction: e.target.value, page: '1' })}
|
||||
className={inputClass (false, 'w-auto')}>
|
||||
<option value="desc">降順</option>
|
||||
<option value="asc">昇順</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{isLoading && <p>Loading...</p>}
|
||||
{isError && (
|
||||
<p className="text-red-600 dark:text-red-300">素材一覧の取得に失敗しました.</p>)}
|
||||
{(!isLoading && !isError && materials.length === 0) && (
|
||||
<p>素材はありません.</p>)}
|
||||
{materials.length > 0 && (
|
||||
view === 'card'
|
||||
? (
|
||||
<div className="grid grid-cols-[repeat(auto-fill,minmax(196px,1fr))]
|
||||
justify-items-center gap-4">
|
||||
{materials.map (material => (
|
||||
<MaterialCard key={material.id} material={material}/>))}
|
||||
</div>)
|
||||
: (
|
||||
<div className="space-y-3">
|
||||
{materials.map (material => (
|
||||
<MaterialListItem key={material.id} material={material}/>))}
|
||||
</div>))}
|
||||
<Pagination page={page} totalPages={totalPages}/>
|
||||
</div>
|
||||
{isLoading && <p>Loading...</p>}
|
||||
{isError && (
|
||||
<p className="text-red-600 dark:text-red-300">素材一覧の取得に失敗しました.</p>)}
|
||||
{(!isLoading && !isError && materials.length === 0) && (
|
||||
<p>素材はありません.</p>)}
|
||||
{materials.length > 0 && (
|
||||
view === 'card'
|
||||
? (
|
||||
<div className="grid grid-cols-[repeat(auto-fill,minmax(196px,1fr))]
|
||||
justify-items-center gap-4">
|
||||
{materials.map (material => (
|
||||
<MaterialCard key={material.id} material={material}/>))}
|
||||
</div>)
|
||||
: (
|
||||
<div className="space-y-3">
|
||||
{materials.map (material => (
|
||||
<MaterialListItem key={material.id} material={material}/>))}
|
||||
</div>))}
|
||||
<Pagination page={page} totalPages={totalPages}/>
|
||||
</div>
|
||||
</MainArea>)
|
||||
}
|
||||
|
||||
|
||||
@@ -40,27 +40,26 @@ const MaterialNewPage: FC = () => {
|
||||
|
||||
const createMutation = useMutation ({
|
||||
mutationFn: async () => {
|
||||
const formData = new FormData
|
||||
if (tag)
|
||||
formData.append ('tag', tag)
|
||||
if (file)
|
||||
formData.append ('file', file)
|
||||
if (url)
|
||||
formData.append ('url', url)
|
||||
formData.append ('export_paths[legacy_drive]', exportPath)
|
||||
const formData = new FormData
|
||||
if (tag)
|
||||
formData.append ('tag', tag)
|
||||
if (file)
|
||||
formData.append ('file', file)
|
||||
if (url)
|
||||
formData.append ('url', url)
|
||||
formData.append ('export_paths[legacy_drive]', exportPath)
|
||||
|
||||
return await createMaterial (formData)
|
||||
return await createMaterial (formData)
|
||||
},
|
||||
onSuccess: async () => {
|
||||
await qc.invalidateQueries ({ queryKey: materialsKeys.root })
|
||||
toast ({ title: '送信成功!' })
|
||||
navigate (`/materials?tag=${ encodeURIComponent (tag) }`)
|
||||
await qc.invalidateQueries ({ queryKey: materialsKeys.root })
|
||||
toast ({ title: '送信成功!' })
|
||||
navigate (`/materials?tag=${ encodeURIComponent (tag) }`)
|
||||
},
|
||||
onError: error => {
|
||||
applyValidationError (error)
|
||||
toast ({ title: '送信失敗……', description: '入力を見直してください.' })
|
||||
},
|
||||
})
|
||||
applyValidationError (error)
|
||||
toast ({ title: '送信失敗……', description: '入力を見直してください.' })
|
||||
}})
|
||||
|
||||
const handleSubmit = () => {
|
||||
clearValidationErrors ()
|
||||
|
||||
@@ -62,8 +62,7 @@ const PostDetailPage: FC<Props> = ({ user }) => {
|
||||
toast ({ title: '失敗……', description: '通信に失敗しました……' })
|
||||
},
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries ({ queryKey: postsKeys.root })
|
||||
} })
|
||||
qc.invalidateQueries ({ queryKey: postsKeys.root })} })
|
||||
|
||||
useEffect (() => {
|
||||
if (!(errorFlg))
|
||||
@@ -114,8 +113,7 @@ const PostDetailPage: FC<Props> = ({ user }) => {
|
||||
<PostList posts={[{ ...post, childPosts: [{ } as Post] },
|
||||
...post.childPosts!.map (p => ({
|
||||
...p, parentPosts: [{ } as Post] }))]}/>
|
||||
</div>
|
||||
)}
|
||||
</div>)}
|
||||
{(post.parentPosts ?? []).map (pp => {
|
||||
const siblings = post.siblingPosts?.[String (pp.id) as `${ number }`]
|
||||
if (!(siblings))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { Check, LoaderCircle, Pencil, X } from 'lucide-react'
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { Fragment, useEffect, useMemo, useState } from 'react'
|
||||
import { Helmet } from 'react-helmet-async'
|
||||
import { useLocation, useNavigate } from 'react-router-dom'
|
||||
|
||||
@@ -87,8 +87,7 @@ const NicoTagListPage: FC<Props> = ({ user }) => {
|
||||
const defaultDirection = {
|
||||
name: 'asc',
|
||||
created_at: 'desc',
|
||||
updated_at: 'desc',
|
||||
} as const
|
||||
updated_at: 'desc'} as const
|
||||
|
||||
const beginEdit = async (tag: NicoTag) => {
|
||||
const editingTag = nicoTags.find (tag => tag.id === editingId)
|
||||
@@ -99,15 +98,13 @@ const NicoTagListPage: FC<Props> = ({ user }) => {
|
||||
&& !(await dialogue.confirm ({
|
||||
title: '編集中の内容を破棄しますか?',
|
||||
confirmText: '破棄',
|
||||
variant: 'danger',
|
||||
})))
|
||||
variant: 'danger'})))
|
||||
return
|
||||
|
||||
setEditingId (tag.id)
|
||||
setRawTags (rawTags => ({
|
||||
...rawTags,
|
||||
[tag.id]: tag.linkedTags.map (linkedTag => linkedTag.name).join (' '),
|
||||
}))
|
||||
[tag.id]: tag.linkedTags.map (linkedTag => linkedTag.name).join (' ')}))
|
||||
setErrorsByTagId (errors => ({ ...errors, [tag.id]: [] }))
|
||||
}
|
||||
|
||||
@@ -115,8 +112,7 @@ const NicoTagListPage: FC<Props> = ({ user }) => {
|
||||
setEditingId (null)
|
||||
setRawTags (rawTags => ({
|
||||
...rawTags,
|
||||
[tag.id]: tag.linkedTags.map (linkedTag => linkedTag.name).join (' '),
|
||||
}))
|
||||
[tag.id]: tag.linkedTags.map (linkedTag => linkedTag.name).join (' ')}))
|
||||
setErrorsByTagId (errors => ({ ...errors, [tag.id]: [] }))
|
||||
}
|
||||
|
||||
@@ -141,8 +137,7 @@ const NicoTagListPage: FC<Props> = ({ user }) => {
|
||||
...errors,
|
||||
[id]: validationError?.fieldErrors.tags
|
||||
?? validationError?.baseErrors
|
||||
?? ['更新できませんでした.'],
|
||||
}))
|
||||
?? ['更新できませんでした.']}))
|
||||
toast ({ title: '更新失敗', description: '入力内容を確認してください.' })
|
||||
}
|
||||
finally
|
||||
@@ -166,8 +161,7 @@ const NicoTagListPage: FC<Props> = ({ user }) => {
|
||||
|
||||
setRawTags (Object.fromEntries (data.tags.map (tag => [
|
||||
tag.id,
|
||||
tag.linkedTags.map (linkedTag => linkedTag.name).join (' '),
|
||||
])))
|
||||
tag.linkedTags.map (linkedTag => linkedTag.name).join (' ')])))
|
||||
}, [data])
|
||||
|
||||
useEffect (() => {
|
||||
@@ -282,7 +276,8 @@ const NicoTagListPage: FC<Props> = ({ user }) => {
|
||||
{nicoTags.map (tag => {
|
||||
const isEditing = editingId === tag.id
|
||||
|
||||
return [
|
||||
return (
|
||||
<Fragment key={tag.id}>
|
||||
<tr
|
||||
key={tag.id}
|
||||
className={cn (
|
||||
@@ -321,8 +316,8 @@ const NicoTagListPage: FC<Props> = ({ user }) => {
|
||||
編集
|
||||
</button>)}
|
||||
</td>)}
|
||||
</tr>,
|
||||
isEditing && (
|
||||
</tr>
|
||||
{isEditing && (
|
||||
<tr key={`${ tag.id }-edit`}
|
||||
className="border-b border-rose-200 bg-rose-50 dark:border-rose-900
|
||||
dark:bg-rose-950/30">
|
||||
@@ -340,8 +335,7 @@ const NicoTagListPage: FC<Props> = ({ user }) => {
|
||||
placeholder="タグ名を空白または改行で区切って入力"
|
||||
onChange={e => setRawTags (rawTags => ({
|
||||
...rawTags,
|
||||
[tag.id]: e.target.value,
|
||||
}))}/>
|
||||
[tag.id]: e.target.value}))}/>
|
||||
<FieldError messages={errorsByTagId[tag.id]}/>
|
||||
<div className="flex justify-end gap-2">
|
||||
<button
|
||||
@@ -368,8 +362,8 @@ const NicoTagListPage: FC<Props> = ({ user }) => {
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>),
|
||||
]
|
||||
</tr>)}
|
||||
</Fragment>)
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -69,8 +69,7 @@ const userName = (user: Pick<User, 'id' | 'name'> | null | undefined): string =>
|
||||
|
||||
const commentBox = (
|
||||
comment: TheatreComment,
|
||||
programme: TheatreProgramme | null = null,
|
||||
): ReactNode[] =>
|
||||
programme: TheatreProgramme | null = null): ReactNode[] =>
|
||||
[(
|
||||
<div key={`${ comment.no }-content`} className="w-full">
|
||||
{comment.deleted
|
||||
@@ -120,8 +119,7 @@ const tagsByCategory = (tags: Tag[]): Partial<Record<Category, Tag[]>> => {
|
||||
|
||||
|
||||
const TagList: FC<{ tags: Tag[]; compact?: boolean; flow?: TagFlow }> = (
|
||||
{ tags, compact, flow = 'vertical' },
|
||||
) => {
|
||||
{ tags, compact, flow = 'vertical' }) => {
|
||||
const grouped = tagsByCategory (tags)
|
||||
|
||||
if (flow === 'horizontal')
|
||||
|
||||
新しい課題から参照
ユーザをブロックする