Skip to content

Commit

Permalink
feat: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
CarinaDraganJW committed May 23, 2023
1 parent 384e0e2 commit dfd2f5c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 27 deletions.
12 changes: 6 additions & 6 deletions src/hooks/useOttAnalytics.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { useCallback, useEffect, useState } from 'react';
import jwtDecode from 'jwt-decode';

import type { PlaylistItem } from '#types/playlist';
import { useConfigStore } from '#src/stores/ConfigStore';
import { useAccountStore } from '#src/stores/AccountStore';
import type { DecodedJwtToken } from '#types/account';

const useOttAnalytics = (item?: PlaylistItem, feedId: string = '') => {
const analyticsToken = useConfigStore((s) => s.config.analyticsToken);
const auth = useAccountStore((state) => state.auth);
const isLoggedIn = !!auth;
const user = useAccountStore((state) => state.user);

const userId = Number(user?.id);
const isLoggedIn = !!userId;

const [player, setPlayer] = useState<jwplayer.JWPlayer | null>(null);

const decodedToken: DecodedJwtToken | undefined = isLoggedIn ? jwtDecode(auth?.jwt) : undefined;
const oaid: number | undefined = isLoggedIn ? userId : undefined;

const timeHandler = useCallback(({ position, duration }: jwplayer.TimeParam) => {
window.jwpltx.time(position, duration);
Expand All @@ -34,7 +34,7 @@ const useOttAnalytics = (item?: PlaylistItem, feedId: string = '') => {
return;
}

window.jwpltx.ready(analyticsToken, window.location.hostname, feedId, item.mediaid, item.title, decodedToken?.tid);
window.jwpltx.ready(analyticsToken, window.location.hostname, feedId, item.mediaid, item.title, oaid);
}, [item]);

const completeHandler = useCallback(() => {
Expand Down
21 changes: 0 additions & 21 deletions types/account.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,12 @@ import type { SerializedFavorite } from './favorite';

import type { Config } from '#types/Config';

type UserRole = 'inplayer' | 'merchant' | 'consumer' | 'master' | 'follower' | 'admin' | undefined;

type Scope = 'inheritance' | 'email_inheritance' | undefined;

export type AuthData = {
jwt: string;
customerToken: string;
refreshToken: string;
};

export type DecodedJwtToken = {
aid: number;
aud: string;
ctx: UserRole[];
exp: number;
iat: number;
jti: string;
mid: number;
mui: string;
nbf: number;
oid: number;
scopes: Scope[];
sub: string;
tid: number;
tuuid: string;
};

export type JwtDetails = {
customerId: string;
exp: number;
Expand Down

0 comments on commit dfd2f5c

Please sign in to comment.