-
Notifications
You must be signed in to change notification settings - Fork 0
Sync DEV #401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Sync DEV #401
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a128db8
Merge pull request #391 from topcoder-platform/dev
vas3a 23b4bfc
Merge pull request #394 from topcoder-platform/dev
kkartunov 38b74ab
Merge pull request #396 from topcoder-platform/dev
kkartunov 12e084b
Re-enable nudges
vas3a 8fec7f2
deploy to dev
vas3a 7dead44
Fetch profile data
vas3a eab68b5
load the nudge app
vas3a 01b7b6d
typefix
vas3a fb87b96
Merge pull request #400 from topcoder-platform/re-enable-nudges
vas3a File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,12 @@ | ||
| const modulePath = BUILD_IS_PROD ? './nudge.js' : '../nudge-app/Nudge.svelte'; | ||
|
|
||
| const loadModule = () => { | ||
| return import(/* @vite-ignore */ modulePath).then(d => d.default) | ||
| } | ||
|
|
||
| export const loadNudgeApp = async (ctx: any, targetEl: Element): Promise<void> => { | ||
| const NudgeApp = await loadModule(); | ||
|
|
||
| // instantiate the nudge app | ||
| new NudgeApp({ target: targetEl, context: ctx }); | ||
| } |
This file contains hidden or 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,67 @@ | ||
| import { TC_API_HOST } from "lib/config"; | ||
| import type { AuthUser } from "lib/app-context"; | ||
| import { DISABLE_NUDGES, NUDGES_DISABLED_HOSTS } from "lib/config/profile-toasts.config"; | ||
|
|
||
| import { getRequestAuthHeaders } from "./auth-jwt"; | ||
|
|
||
| /** | ||
| * Check if we're on a domain that should not show the profile nudges | ||
| * @returns Boolean | ||
| */ | ||
| export function dismissNudgesBasedOnHost(): boolean { | ||
| // Ue the new flag to disable the profile nudges completely (PS-267) | ||
| const locationHostname = window?.location.hostname ?? '' | ||
| return DISABLE_NUDGES || | ||
| (!!NUDGES_DISABLED_HOSTS.find(host => ( | ||
| host.match(new RegExp(`^https?:\/\/${locationHostname}`, 'i')) | ||
| ))); | ||
| } | ||
|
|
||
| // store fetched data in a local cache (de-duplicate immediate api calls) | ||
| const localCache: Record<string, Promise<ProfileCompletednessResponse> | undefined> = {}; | ||
|
|
||
| export interface ProfileCompletednessResponse { | ||
| handle: string | ||
| showToast: string | ||
| data: { | ||
| percentComplete: number | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Fetches the user profile completedness | ||
| * @returns Promise<ProfileCompletednessResponse> | ||
| */ | ||
| export const fetchUserProfileCompletedness = async (user: AuthUser, force = false): Promise<ProfileCompletednessResponse | undefined> => { | ||
| const userHandle = user?.handle; | ||
|
|
||
| if (!userHandle) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const cacheKey = `${userHandle}-completedness`; | ||
| if (!force && localCache[cacheKey]) { | ||
| return await localCache[cacheKey]; | ||
| } | ||
|
|
||
|
|
||
| let resolve!: (value: ProfileCompletednessResponse) => void; | ||
| localCache[cacheKey] = new Promise<ProfileCompletednessResponse>((r) => { resolve = r }); | ||
|
|
||
| // for QA purpose only | ||
| const toastOverrideFlagParam = (window?.location.search.match(/[?&]+toast=(\w+)/i) ?? [])[1]; | ||
| const toastOverrideFlag = toastOverrideFlagParam ? `?toast=${toastOverrideFlagParam}` : ''; | ||
| const requestUrl: string = `${TC_API_HOST}/members/${userHandle}/profileCompleteness${toastOverrideFlag}`; | ||
| const request = fetch(requestUrl, {headers: {...getRequestAuthHeaders()}}); | ||
|
|
||
| const response = await (await request).json(); | ||
| resolve({ | ||
| ...response, | ||
| data: { | ||
| ...response.data, | ||
| percentComplete: (response?.data?.percentComplete ?? 0) * 100, | ||
| }, | ||
| }); | ||
|
|
||
| return localCache[cacheKey]; | ||
| } |
This file contains hidden or 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,43 @@ | ||
| @use 'lib/styles/mixins.scss' as *; | ||
|
|
||
| .nudgeOuter { | ||
| position: absolute; | ||
| top: calc(var(--uninav-header-height) + var(--top-offset)); | ||
| left: 0; | ||
| z-index: 19; | ||
|
|
||
| height: 0; | ||
| width: 100%; | ||
| @include mobile { | ||
| --top-offset: 2px!important; | ||
| } | ||
| } | ||
|
|
||
| .nudgeWrap { | ||
| position: absolute; | ||
| display: flex; | ||
| width: 100%; | ||
| margin: 0 auto; | ||
| @include maxViewWidth; | ||
| left: 50%; | ||
| transform: translateX(-50%); | ||
| } | ||
|
|
||
| .nudgeInner { | ||
| position: absolute; | ||
| right: 0; | ||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: flex-end; | ||
|
|
||
| padding: 8px 32px; | ||
|
|
||
| @include tablet { | ||
| padding: 8px 16px; | ||
| } | ||
|
|
||
| @include mobile { | ||
| padding: 0 2px; | ||
| width: 100%; | ||
| } | ||
| } |
This file contains hidden or 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,36 @@ | ||
| <script lang="ts"> | ||
| import { getAppContext } from 'lib/app-context'; | ||
| import Toastr from './components/Toastr.svelte'; | ||
| import styles from './Nudge.module.scss'; | ||
| import type { ToastType } from 'lib/config/profile-toasts.config'; | ||
| import { getToast, hideToast } from './toast-manager'; | ||
| import Sticky from 'lib/components/sticky/Sticky.svelte'; | ||
| import type { ProfileCompletionData } from 'lib/app-context/profile-completion.model'; | ||
|
|
||
| const ctx = getAppContext(); | ||
|
|
||
| $: ({ | ||
| ready: isReady, | ||
| user, | ||
| profileCompletionData, | ||
| } = $ctx.auth) | ||
|
|
||
| let toast: ToastType | undefined; | ||
|
|
||
| function dismissToast() { | ||
| toast = undefined; | ||
| hideToast(); | ||
| } | ||
|
|
||
| $: toast = isReady ? getToast(profileCompletionData as ProfileCompletionData) : undefined; | ||
| </script> | ||
|
|
||
| {#if toast} | ||
| <Sticky class={styles.nudgeOuter} yOffset={10}> | ||
| <div class={styles.nudgeWrap}> | ||
| <div class={styles.nudgeInner}> | ||
| <Toastr userhandle={user.handle} toast={toast} on:dismiss={dismissToast} /> | ||
| </div> | ||
| </div> | ||
| </Sticky> | ||
| {/if} |
This file contains hidden or 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,12 @@ | ||
| .animation { | ||
| width: 100%; | ||
| height: 100%; | ||
|
|
||
| svg { | ||
| transform: none!important; | ||
| } | ||
|
|
||
| img { | ||
| object-fit: contain; | ||
| } | ||
| } |
This file contains hidden or 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,53 @@ | ||
| <script lang="ts"> | ||
| import { createEventDispatcher, onMount } from 'svelte'; | ||
| import { getPublicPath } from 'lib/utils/paths'; | ||
| import styles from './Animation.module.scss'; | ||
|
|
||
| export let animation: string; | ||
| export let cover: string; | ||
|
|
||
| let ref: Element | undefined = undefined; | ||
| let coverRef: HTMLDivElement | undefined = undefined; | ||
| const dispatch = createEventDispatcher(); | ||
|
|
||
| function triggerLoaded(animation: any = false) { | ||
| dispatch('loaded', {animation: animation === true}); | ||
| } | ||
|
|
||
| const loadAnimation = (path) => { | ||
| var animData = { | ||
| container: ref, | ||
| renderer: 'svg', | ||
| loop: true, | ||
| autoplay: true, | ||
| path: getPublicPath(`/assets/nudge/anim/${path}.json`), | ||
| rendererSettings: { | ||
| progressiveLoad: true | ||
| }, | ||
| }; | ||
| const bmAnim = window['bodymovin'].loadAnimation(animData); | ||
| bmAnim.addEventListener('data_ready', () => { | ||
| if (coverRef) { | ||
| Object.assign(coverRef.style, {display: 'none'}); | ||
| } | ||
|
|
||
| triggerLoaded(true); | ||
| }); | ||
| } | ||
|
|
||
| onMount(async () => { | ||
| await import(/* @vite-ignore */getPublicPath('/assets/nudge/bodymovin.js')); | ||
| loadAnimation(animation); | ||
| }); | ||
|
|
||
| </script> | ||
|
|
||
| <div class={styles.animation} bind:this={ref}> | ||
| {#if cover} | ||
| <img | ||
| src={getPublicPath(`/assets/nudge/anim/${cover}`)} | ||
| alt="icon" | ||
| bind:this={coverRef} on:load={triggerLoaded} | ||
| /> | ||
| {/if} | ||
| </div> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.