fix i18n of missing uploader
This commit is contained in:
parent
33e249f5d2
commit
31ebd8bd35
|
|
@ -95,7 +95,7 @@ class SkinlibController extends Controller
|
|||
}
|
||||
|
||||
$badges = [];
|
||||
$uploader = User::find($texture->uploader);
|
||||
$uploader = $texture->owner;
|
||||
if ($uploader) {
|
||||
if ($uploader->isAdmin()) {
|
||||
$badges[] = ['text' => 'STAFF', 'color' => 'primary'];
|
||||
|
|
@ -125,7 +125,8 @@ class SkinlibController extends Controller
|
|||
'currentUid' => $user ? $user->uid : 0,
|
||||
'admin' => $user && $user->isAdmin(),
|
||||
'inCloset' => $user && $user->closet()->where('tid', $texture->tid)->count() > 0,
|
||||
'nickname' => ($up = User::find($texture->uploader)) ? $up->nickname : null,
|
||||
'uploaderExists' => (bool) $uploader,
|
||||
'nickname' => optional($uploader)->nickname ?? trans('general.unexistent-user'),
|
||||
'report' => intval(option('reporter_score_modification', 0)),
|
||||
'badges' => $badges,
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,8 @@ const Show: React.FC = () => {
|
|||
const [texture, setTexture] = useState<Texture>({} as Texture)
|
||||
const [showModalApply, setShowModalApply] = useState(false)
|
||||
const [liked, setLiked] = useState(false)
|
||||
const nickname = useBlessingExtra<string | null>('nickname')
|
||||
const nickname = useBlessingExtra<string>('nickname')
|
||||
const isUploaderExists = useBlessingExtra<boolean>('uploaderExists')
|
||||
const currentUid = useBlessingExtra<number>('currentUid', 0)
|
||||
const isAdmin = useBlessingExtra<boolean>('admin')
|
||||
const badges = useBlessingExtra<Badge[]>('badges', [])
|
||||
|
|
@ -77,7 +78,7 @@ const Show: React.FC = () => {
|
|||
)
|
||||
if (code === 0) {
|
||||
toast.success(message)
|
||||
setTexture(texture => ({ ...texture, name }))
|
||||
setTexture((texture) => ({ ...texture, name }))
|
||||
} else {
|
||||
toast.error(message)
|
||||
}
|
||||
|
|
@ -111,7 +112,7 @@ const Show: React.FC = () => {
|
|||
)
|
||||
if (code === 0) {
|
||||
toast.success(message)
|
||||
setTexture(texture => ({ ...texture, type }))
|
||||
setTexture((texture) => ({ ...texture, type }))
|
||||
} else {
|
||||
toast.error(message)
|
||||
}
|
||||
|
|
@ -120,7 +121,7 @@ const Show: React.FC = () => {
|
|||
const handleAddItemClick = async () => {
|
||||
const ok = await addClosetItem(texture)
|
||||
if (ok) {
|
||||
setTexture(texture => ({ ...texture, likes: texture.likes + 1 }))
|
||||
setTexture((texture) => ({ ...texture, likes: texture.likes + 1 }))
|
||||
setLiked(true)
|
||||
}
|
||||
}
|
||||
|
|
@ -128,7 +129,7 @@ const Show: React.FC = () => {
|
|||
const handleRemoveItemClick = async () => {
|
||||
const ok = await removeClosetItem(texture.tid)
|
||||
if (ok) {
|
||||
setTexture(texture => ({ ...texture, likes: texture.likes - 1 }))
|
||||
setTexture((texture) => ({ ...texture, likes: texture.likes - 1 }))
|
||||
setLiked(false)
|
||||
}
|
||||
}
|
||||
|
|
@ -196,7 +197,7 @@ const Show: React.FC = () => {
|
|||
)
|
||||
if (code === 0) {
|
||||
toast.success(message)
|
||||
setTexture(texture => ({ ...texture, public: !texture.public }))
|
||||
setTexture((texture) => ({ ...texture, public: !texture.public }))
|
||||
} else {
|
||||
toast.error(message)
|
||||
}
|
||||
|
|
@ -366,7 +367,7 @@ const Show: React.FC = () => {
|
|||
<div className="row my-4">
|
||||
<div className="col-4">{t('skinlib.show.uploader')}</div>
|
||||
<div className={`col-8 ${styles.truncate}`}>
|
||||
{nickname !== null ? (
|
||||
{isUploaderExists ? (
|
||||
<>
|
||||
<div>
|
||||
<a href={linkToUploader} target="_blank">
|
||||
|
|
@ -374,7 +375,7 @@ const Show: React.FC = () => {
|
|||
</a>
|
||||
</div>
|
||||
<div>
|
||||
{badges.map(badge => (
|
||||
{badges.map((badge) => (
|
||||
<span
|
||||
className={`badge bg-${badge.color} mr-2`}
|
||||
key={badge.text}
|
||||
|
|
@ -385,7 +386,7 @@ const Show: React.FC = () => {
|
|||
</div>
|
||||
</>
|
||||
) : (
|
||||
t('general.unexistent-user')
|
||||
nickname
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ beforeEach(() => {
|
|||
download: true,
|
||||
currentUid: 0,
|
||||
admin: false,
|
||||
uploaderExists: true,
|
||||
nickname: 'author',
|
||||
inCloset: false,
|
||||
report: 0,
|
||||
|
|
@ -88,12 +89,13 @@ test('authenticated but not uploader', async () => {
|
|||
})
|
||||
|
||||
test('uploader is not existed', async () => {
|
||||
window.blessing.extra.nickname = null
|
||||
window.blessing.extra.nickname = 'not existed'
|
||||
window.blessing.extra.uploaderExists = false
|
||||
fetch.get.mockResolvedValue({ data: fixtureSkin })
|
||||
|
||||
const { queryByText } = render(<Show />)
|
||||
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
|
||||
expect(queryByText(t('general.unexistent-user'))).toBeInTheDocument()
|
||||
expect(queryByText('not existed')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('badges', async () => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user