panel-linter-fix
Some checks failed
Deploy on push / deploy (push) Failing after 2m15s

This commit is contained in:
2025-08-18 20:23:25 +03:00
parent 1b48675b92
commit e13267a868
14 changed files with 188 additions and 145 deletions

View File

@@ -1,13 +1,13 @@
import { Component, createEffect, createSignal, For, on, onMount, Show, untrack } from 'solid-js'
import { useTableSort } from '../context/sort'
import { COMMUNITIES_SORT_CONFIG } from '../context/sortConfig'
import { query } from '../graphql'
import {
CREATE_COMMUNITY_MUTATION,
DELETE_COMMUNITY_MUTATION,
UPDATE_COMMUNITY_MUTATION
} from '../graphql/mutations'
import { GET_COMMUNITIES_QUERY } from '../graphql/queries'
import { query } from '../graphql'
import CommunityEditModal from '../modals/CommunityEditModal'
import styles from '../styles/Table.module.css'
import Button from '../ui/Button'
@@ -22,19 +22,13 @@ interface Community {
id: number
slug: string
name: string
desc?: string
pic: string
created_at: number
created_by?: { // Делаем created_by необязательным
id: number
name: string
email: string
} | null
stat: {
shouts: number
followers: number
authors: number
}
description: string
created_at: string
updated_at: string
creator_id: number
creator_name: string
followers_count: number
shouts_count: number
}
interface CommunitiesRouteProps {
@@ -42,6 +36,53 @@ interface CommunitiesRouteProps {
onSuccess: (message: string) => void
}
// Types for GraphQL responses
interface CommunitiesResponse {
get_communities_all: Array<{
id: number
name: string
slug: string
description: string
created_at: string
updated_at: string
creator_id: number
creator_name: string
followers_count: number
shouts_count: number
}>
}
interface CreateCommunityResponse {
create_community: {
success: boolean
error?: string
community?: {
id: number
name: string
slug: string
}
}
}
interface UpdateCommunityResponse {
update_community: {
success: boolean
error?: string
community?: {
id: number
name: string
slug: string
}
}
}
interface DeleteCommunityResponse {
delete_community: {
success: boolean
error?: string
}
}
/**
* Компонент для управления сообществами
*/
@@ -78,7 +119,7 @@ const CommunitiesRoute: Component<CommunitiesRouteProps> = (props) => {
const result = await query('/graphql', GET_COMMUNITIES_QUERY)
// Получаем данные и сортируем их на клиенте
const communitiesData = (result as any)?.get_communities_all || []
const communitiesData = (result as CommunitiesResponse)?.get_communities_all || []
const sortedCommunities = sortCommunities(communitiesData)
setCommunities(sortedCommunities)
} catch (error) {
@@ -91,8 +132,8 @@ const CommunitiesRoute: Component<CommunitiesRouteProps> = (props) => {
/**
* Форматирует дату
*/
const formatDate = (timestamp: number): string => {
return new Date(timestamp * 1000).toLocaleDateString('ru-RU')
const formatDate = (dateString: string): string => {
return new Date(dateString).toLocaleDateString('ru-RU')
}
/**
@@ -115,22 +156,22 @@ const CommunitiesRoute: Component<CommunitiesRouteProps> = (props) => {
comparison = (a.slug || '').localeCompare(b.slug || '', 'ru')
break
case 'created_at':
comparison = a.created_at - b.created_at
comparison = a.created_at.localeCompare(b.created_at, 'ru')
break
case 'created_by': {
const aName = a.created_by?.name || a.created_by?.email || ''
const bName = b.created_by?.name || b.created_by?.email || ''
const aName = a.creator_name || ''
const bName = b.creator_name || ''
comparison = aName.localeCompare(bName, 'ru')
break
}
case 'shouts':
comparison = (a.stat?.shouts || 0) - (b.stat?.shouts || 0)
comparison = (a.shouts_count || 0) - (b.shouts_count || 0)
break
case 'followers':
comparison = (a.stat?.followers || 0) - (b.stat?.followers || 0)
comparison = (a.followers_count || 0) - (b.followers_count || 0)
break
case 'authors':
comparison = (a.stat?.authors || 0) - (b.stat?.authors || 0)
comparison = (a.creator_id || 0) - (b.creator_id || 0)
break
default:
comparison = a.id - b.id
@@ -163,13 +204,15 @@ const CommunitiesRoute: Component<CommunitiesRouteProps> = (props) => {
const mutation = isCreating ? CREATE_COMMUNITY_MUTATION : UPDATE_COMMUNITY_MUTATION
// Удаляем created_by, если он null или undefined
if (communityData.created_by === null || communityData.created_by === undefined) {
delete communityData.created_by
if (communityData.creator_id === null || communityData.creator_id === undefined) {
delete communityData.creator_id
}
const result = await query('/graphql', mutation, { community_input: communityData })
const resultData = isCreating ? (result as any).create_community : (result as any).update_community
const resultData = isCreating
? (result as CreateCommunityResponse).create_community
: (result as UpdateCommunityResponse).update_community
if (resultData.error) {
throw new Error(resultData.error)
}
@@ -191,7 +234,7 @@ const CommunitiesRoute: Component<CommunitiesRouteProps> = (props) => {
const deleteCommunity = async (slug: string) => {
try {
const result = await query('/graphql', DELETE_COMMUNITY_MUTATION, { slug })
const deleteResult = (result as any).delete_community
const deleteResult = (result as DeleteCommunityResponse).delete_community
if (deleteResult.error) {
throw new Error(deleteResult.error)
@@ -303,19 +346,17 @@ const CommunitiesRoute: Component<CommunitiesRouteProps> = (props) => {
'text-overflow': 'ellipsis',
'white-space': 'nowrap'
}}
title={community.desc}
title={community.description}
>
{community.desc || '—'}
{community.description || '—'}
</div>
</td>
<td>
<Show when={community.created_by} fallback={<span></span>}>
<span>{community.created_by?.name || community.created_by?.email || ''}</span>
</Show>
<span>{community.creator_name || ''}</span>
</td>
<td>{community.stat.shouts}</td>
<td>{community.stat.followers}</td>
<td>{community.stat.authors}</td>
<td>{community.shouts_count}</td>
<td>{community.followers_count}</td>
<td>{community.creator_id}</td>
<td>{formatDate(community.created_at)}</td>
<td onClick={(e) => e.stopPropagation()}>
<button