From a48a1870865658be6d140a61d3e8e2b808d854ff Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sat, 11 Jun 2022 23:08:41 +0200 Subject: [PATCH] Reset follow button after blocking a user --- app/javascript/retrospring/features/user/action.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/javascript/retrospring/features/user/action.ts b/app/javascript/retrospring/features/user/action.ts index 3774091b..780c5212 100644 --- a/app/javascript/retrospring/features/user/action.ts +++ b/app/javascript/retrospring/features/user/action.ts @@ -56,16 +56,14 @@ export function userActionHandler(event: Event): void { button.classList.add('btn-default'); break; case 'unfollow': - button.dataset.action = 'follow'; - button.innerText = I18n.translate('views.actions.follow'); - button.classList.remove('btn-default'); - button.classList.add('btn-primary'); + resetFollowButton(button); break; case 'block': button.dataset.action = 'unblock'; button.querySelector('span').innerText = I18n.translate('views.actions.unblock'); button.classList.remove('btn-primary'); button.classList.add('btn-default'); + resetFollowButton(document.querySelector('button[data-action="unfollow"]')); break; case 'unblock': button.dataset.action = 'block'; @@ -76,4 +74,11 @@ export function userActionHandler(event: Event): void { } } }); +} + +function resetFollowButton(button: HTMLButtonElement) { + button.dataset.action = 'follow'; + button.innerText = I18n.translate('views.actions.follow'); + button.classList.remove('btn-default'); + button.classList.add('btn-primary'); } \ No newline at end of file