-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
T236317: Allow users to provide feedback from within the app (#216)
* Introduce feedback component * Fix tests * Adding sendFeedback util * Try to send feedback * Add placeholder and onKeyBackspace functionality * Add input validation * Add hyperlinks to feedback explanation text * Update landscape CSS * Update softkey labels * Update qqq.json * Update to new sucess flow * Polish landscape view and clean up CSS * Update CSS to fit content in banana phone screen * Formatting * Adjust landscape view * Trim feedback message to avoid blank strings * Add CancelConfirmationPopup * Blur textarea before showing confirmation popup * Update feedback explanation language * Add offline handling * Show cancel confirmation dialog even when offline to ensure that text will not be lost accidentally * CSS update: textarea highlight and line height * Rename SearchOfflinePanel to OfflinePanel * Update qqq.json, feedback-explanation Co-authored-by: Stephane Bisson <[email protected]>
- Loading branch information
Showing
16 changed files
with
332 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import { h } from 'preact' | ||
import { useState, useRef, useEffect } from 'preact/hooks' | ||
import { useI18n, useSoftkey, useNavigation, usePopup, useOnlineStatus } from 'hooks' | ||
import { sendFeedback } from 'utils' | ||
import { OfflinePanel } from 'components' | ||
|
||
export const Feedback = ({ close }) => { | ||
const containerRef = useRef() | ||
const i18n = useI18n() | ||
const [message, setMessage] = useState() | ||
const [showSuccessConfirmation] = usePopup(SuccessConfirmationPopup, { stack: true }) | ||
const [showCancelConfirmation] = usePopup(CancelConfirmationPopup, { stack: true }) | ||
const [, setNavigation, getCurrent] = useNavigation('Feedback', containerRef, containerRef, 'y') | ||
const isOnline = useOnlineStatus() | ||
|
||
const items = [ | ||
{ text: `<a data-selectable>${i18n('feedback-privacy-policy')}</a>`, link: 'https://foundation.m.wikimedia.org/wiki/Privacy_policy' }, | ||
{ text: `<a data-selectable>${i18n('feedback-terms-of-use')}</a>`, link: 'https://foundation.m.wikimedia.org/wiki/Terms_of_Use/en' } | ||
] | ||
const hyperlinks = items.map(i => i.text) | ||
|
||
const onKeyRight = () => { | ||
const userMessage = message.trim() | ||
if (isOnline && userMessage) { | ||
sendFeedback(userMessage) | ||
if (getCurrent().type === 'TEXTAREA') { | ||
blurTextarea() | ||
} | ||
showSuccessConfirmation() | ||
} | ||
} | ||
|
||
const onKeyBackspace = () => { | ||
if (!isOnline && message) { | ||
showCancelConfirmation() | ||
} else if (message && getCurrent().type === 'TEXTAREA') { | ||
setMessage(message.slice(0, -1)) | ||
} else { | ||
close() | ||
} | ||
} | ||
|
||
const onKeyCenter = () => { | ||
const { index } = getCurrent() | ||
if (index > 0) { | ||
const item = items[index - 1] | ||
window.open(item.link) | ||
} | ||
} | ||
|
||
const onKeyLeft = () => { | ||
if (message) { | ||
if (isOnline && getCurrent().type === 'TEXTAREA') { | ||
blurTextarea() | ||
} | ||
showCancelConfirmation() | ||
} else { | ||
close() | ||
} | ||
} | ||
|
||
const blurTextarea = () => { | ||
const element = containerRef.current.querySelector('textarea') | ||
element.blur() | ||
} | ||
|
||
useSoftkey('Feedback', { | ||
right: isOnline && message && message.trim() ? i18n('softkey-send') : '', | ||
onKeyRight, | ||
left: i18n('softkey-cancel'), | ||
onKeyLeft, | ||
onKeyBackspace, | ||
onKeyCenter | ||
}, [message, isOnline]) | ||
|
||
useEffect(() => { | ||
setNavigation(0) | ||
}, [isOnline]) | ||
|
||
return ( | ||
<div class='feedback' ref={containerRef}> | ||
<div class='header'> | ||
{i18n('feedback-header')} | ||
</div> | ||
<div class='body'> | ||
{ isOnline | ||
? <div> | ||
<div class='textarea-box'> | ||
<form> | ||
<textarea value={message} placeholder={i18n('feedback-placeholder')} onChange={e => setMessage(e.target.value)} data-selectable /> | ||
</form> | ||
</div> | ||
<div class='explanation-box'> | ||
<p dangerouslySetInnerHTML={{ __html: i18n('feedback-explanation', ...hyperlinks) }}> </p> | ||
</div> | ||
</div> | ||
: <OfflinePanel /> | ||
} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
const SuccessConfirmationPopup = ({ closeAll }) => { | ||
const i18n = useI18n() | ||
|
||
useSoftkey('FeedbackSuccessMessage', { | ||
center: i18n('softkey-ok'), | ||
onKeyCenter: closeAll, | ||
onKeyBackspace: closeAll | ||
}, []) | ||
|
||
return ( | ||
<div class='confirmation-popup'> | ||
<div class='header'>{i18n('feedback-success-header')}</div> | ||
<p class='preview-text success'>{i18n('feedback-success')}</p> | ||
</div> | ||
) | ||
} | ||
|
||
const CancelConfirmationPopup = ({ close, closeAll }) => { | ||
const i18n = useI18n() | ||
|
||
useSoftkey('FeedbackCancelMessage', { | ||
right: i18n('softkey-yes'), | ||
onKeyRight: closeAll, | ||
left: i18n('softkey-no'), | ||
onKeyLeft: close, | ||
onKeyBackspace: close | ||
}, []) | ||
|
||
return ( | ||
<div class='confirmation-popup'> | ||
<div class='header'>{i18n('feedback-cancel-header')}</div> | ||
<p class='preview-text cancel'>{i18n('feedback-cancel')}</p> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { h } from 'preact' | ||
import { useI18n } from 'hooks' | ||
|
||
export const OfflinePanel = () => { | ||
const i18n = useI18n() | ||
return ( | ||
<div class='offline-panel'> | ||
<div class='offline-content'> | ||
<img src='images/offline.svg' /> | ||
<div class='message'>{i18n('offline-message')}</div> | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { appVersion, getAppLanguage, sendEvent } from 'utils' | ||
|
||
export const sendFeedback = feedback => { | ||
sendEvent( | ||
'KaiOSAppFeedback', | ||
20044947, | ||
getAppLanguage(), | ||
{ | ||
version: appVersion(), | ||
feedback | ||
} | ||
) | ||
} |
Oops, something went wrong.