diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 07aca1a6..d4196907 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -77,8 +77,11 @@ class UserController extends Controller 'remaining_time' => $this->getUserSignRemainingTimeWithPrecision() ]); } else { + $remaining_time = $this->getUserSignRemainingTimeWithPrecision(); return json(trans('user.cant-sign-until', [ - 'time' => $this->getUserSignRemainingTimeWithPrecision() + 'time' => $remaining_time >= 1 ?: round($remaining_time * 60), + 'unit' => $remaining_time >= 1 + ? trans('user.time-unit-hour') : trans('user.time-unit-min') ]), 1); } } @@ -87,7 +90,7 @@ class UserController extends Controller { $hours = $this->user->getSignRemainingTime() / 3600; - return round($hours) ?: round($hours, 1); + return $hours > 1 ? round($hours) : $hours; } public function profile() diff --git a/resources/assets/src/js/__tests__/user.test.js b/resources/assets/src/js/__tests__/user.test.js index 9da5fb06..968687f8 100644 --- a/resources/assets/src/js/__tests__/user.test.js +++ b/resources/assets/src/js/__tests__/user.test.js @@ -834,7 +834,7 @@ describe('tests for "sign" module', () => { errno: 0, msg: 'success', score: 100, - remaining_time: 24, + remaining_time: 0.1, storage: { used: 50, total: 100, @@ -870,7 +870,10 @@ describe('tests for "sign" module', () => { dataType: 'json' }); expect($('#score').html()).toBe('100'); - expect(trans).toBeCalledWith('user.signRemainingTime', { time: '24' }); + expect(trans).toBeCalledWith( + 'user.signRemainingTime', + { time: '6', unit: 'user.timeUnitMin' } + ); expect($('#sign-button').html()).toBe( ' user.signRemainingTime' ); @@ -880,6 +883,10 @@ describe('tests for "sign" module', () => { expect(swal).toBeCalledWith({ type: 'success', html: 'success' }); await sign(); + expect(trans).toBeCalledWith( + 'user.signRemainingTime', + { time: '24', unit: 'user.timeUnitHour' } + ); expect($('#user-storage').html()).toBe('2/ 4 MB'); await sign(); diff --git a/resources/assets/src/js/user/sign.js b/resources/assets/src/js/user/sign.js index 2e59b42e..6dc90718 100644 --- a/resources/assets/src/js/user/sign.js +++ b/resources/assets/src/js/user/sign.js @@ -6,7 +6,12 @@ function sign() { }).then(result => { if (result.errno == 0) { $('#score').html(result.score); - var dom = ' ' + trans('user.signRemainingTime', { time: String(result.remaining_time) }); + const dom = ' ' + trans( + 'user.signRemainingTime', + result.remaining_time >= 1 + ? { time: result.remaining_time.toString(), unit: trans('user.timeUnitHour') } + : { time: (result.remaining_time * 60).toFixed(), unit: trans('user.timeUnitMin') } + ); $('#sign-button').attr('disabled', 'disabled').html(dom); diff --git a/resources/lang/en/locale.js b/resources/lang/en/locale.js index 725247ce..6161a3b8 100644 --- a/resources/lang/en/locale.js +++ b/resources/lang/en/locale.js @@ -79,7 +79,10 @@ deleteNotice: 'Are you sure to delete this texture?' }, user: { - signRemainingTime: 'Available after :time hours', + // Signing in + signRemainingTime: 'Available after :time :unit', + timeUnitHour: 'h', + timeUnitMin: 'min', // Closet emptyClosetMsg: '
Nothing in your closet...
Why not explore the Skin Library for a while?
', diff --git a/resources/lang/en/user.yml b/resources/lang/en/user.yml index d314bc7f..c841dafb 100644 --- a/resources/lang/en/user.yml +++ b/resources/lang/en/user.yml @@ -7,9 +7,11 @@ cur-score: Current Score score-notice: Click the score to show introduction. sign: Sign sign-success: Signed successfully. You got :score scores. -cant-sign-until: You can't sign in in :time hours +time-unit-hour: h +time-unit-min: min +cant-sign-until: You can't sign in in :time :unit last-sign: Last signed at :time -sign-remain-time: Available after :time hours +sign-remain-time: Available after :time :unit announcement: Announcement score-intro: diff --git a/resources/lang/zh_CN/locale.js b/resources/lang/zh_CN/locale.js index 3f0cef04..09f6da57 100644 --- a/resources/lang/zh_CN/locale.js +++ b/resources/lang/zh_CN/locale.js @@ -81,7 +81,10 @@ deleteNotice: '真的要删除此材质吗?' }, user: { - signRemainingTime: ':time 小时后可签到', + // Signing in + signRemainingTime: ':time :unit 后可签到', + timeUnitHour: '小时', + timeUnitMin: '分钟', // Closet emptyClosetMsg: '衣柜里啥都没有哦~
去皮肤库看看吧~
', diff --git a/resources/lang/zh_CN/user.yml b/resources/lang/zh_CN/user.yml index 93a092e4..3a9dddfd 100644 --- a/resources/lang/zh_CN/user.yml +++ b/resources/lang/zh_CN/user.yml @@ -7,9 +7,11 @@ cur-score: 当前积分 score-notice: 点击积分查看说明 sign: 每日签到 sign-success: 签到成功,获得了 :score 积分~ -cant-sign-until: :time 小时后才能再次签到哦~ +time-unit-hour: 小时 +time-unit-min: 分钟 +cant-sign-until: :time :unit 后才能再次签到哦~ last-sign: 上次签到于 :time -sign-remain-time: :time 小时后可签到 +sign-remain-time: :time :unit 后可签到 announcement: 公告 score-intro: diff --git a/resources/views/user/index.tpl b/resources/views/user/index.tpl index d142ee3a..3e7b8619 100644 --- a/resources/views/user/index.tpl +++ b/resources/views/user/index.tpl @@ -77,7 +77,11 @@ @endif