From eae19bb1b047b3568e7a9a624b50e80886e56331 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Mon, 4 Nov 2024 13:47:50 +0300 Subject: feat/frontend: optimizing imports, file extensions (#230) Co-authored-by: FifthWit --- frontend/src/utils/Jwt.ts | 44 ++++++++++++++++++++++++++++++++++++++++++++ frontend/src/utils/Jwt.tsx | 44 -------------------------------------------- frontend/src/utils/Time.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ frontend/src/utils/Time.tsx | 42 ------------------------------------------ 4 files changed, 86 insertions(+), 86 deletions(-) create mode 100644 frontend/src/utils/Jwt.ts delete mode 100644 frontend/src/utils/Jwt.tsx create mode 100644 frontend/src/utils/Time.ts delete mode 100644 frontend/src/utils/Time.tsx (limited to 'frontend/src/utils') diff --git a/frontend/src/utils/Jwt.ts b/frontend/src/utils/Jwt.ts new file mode 100644 index 0000000..ce351fb --- /dev/null +++ b/frontend/src/utils/Jwt.ts @@ -0,0 +1,44 @@ +// llm ahh funcs +export function get_user_id_from_token(token: string | undefined): string | undefined { + if (!token) { + return undefined; + } + const parts = token.split('.'); + if (parts.length !== 3) { + return undefined; + } + const base64Url = parts[1]; + const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/'); + + const jsonPayload = decodeURIComponent( + atob(base64) + .split('') + .map(function (c) { + return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); + }) + .join('') + ); + return JSON.parse(jsonPayload).sub; +}; + +export function get_user_mod_from_token(token: string | undefined): boolean | undefined { + if (!token) { + return undefined; + } + const parts = token.split('.'); + if (parts.length !== 3) { + return undefined; + } + const base64Url = parts[1]; + const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/'); + + const jsonPayload = decodeURIComponent( + atob(base64) + .split('') + .map(function (c) { + return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); + }) + .join('') + ); + return JSON.parse(jsonPayload).mod; +}; diff --git a/frontend/src/utils/Jwt.tsx b/frontend/src/utils/Jwt.tsx deleted file mode 100644 index ce351fb..0000000 --- a/frontend/src/utils/Jwt.tsx +++ /dev/null @@ -1,44 +0,0 @@ -// llm ahh funcs -export function get_user_id_from_token(token: string | undefined): string | undefined { - if (!token) { - return undefined; - } - const parts = token.split('.'); - if (parts.length !== 3) { - return undefined; - } - const base64Url = parts[1]; - const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/'); - - const jsonPayload = decodeURIComponent( - atob(base64) - .split('') - .map(function (c) { - return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); - }) - .join('') - ); - return JSON.parse(jsonPayload).sub; -}; - -export function get_user_mod_from_token(token: string | undefined): boolean | undefined { - if (!token) { - return undefined; - } - const parts = token.split('.'); - if (parts.length !== 3) { - return undefined; - } - const base64Url = parts[1]; - const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/'); - - const jsonPayload = decodeURIComponent( - atob(base64) - .split('') - .map(function (c) { - return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); - }) - .join('') - ); - return JSON.parse(jsonPayload).mod; -}; diff --git a/frontend/src/utils/Time.ts b/frontend/src/utils/Time.ts new file mode 100644 index 0000000..b83a7ed --- /dev/null +++ b/frontend/src/utils/Time.ts @@ -0,0 +1,42 @@ +export function time_ago(date: any) { + const now = new Date().getTime(); + + const localDate = new Date(date.getTime() - (date.getTimezoneOffset() * 60000)); + const seconds = Math.floor((now - localDate.getTime()) / 1000); + + let interval = Math.floor(seconds / 31536000); + if (interval === 1) {return interval + ' year ago';} + if (interval > 1) {return interval + ' years ago';} + + interval = Math.floor(seconds / 2592000); + if (interval === 1) {return interval + ' month ago';} + if (interval > 1) {return interval + ' months ago';} + + interval = Math.floor(seconds / 86400); + if (interval === 1) {return interval + ' day ago';} + if (interval > 1) {return interval + ' days ago';} + + interval = Math.floor(seconds / 3600); + if (interval === 1) {return interval + ' hour ago';} + if (interval > 1) {return interval + ' hours ago';} + + interval = Math.floor(seconds / 60); + if (interval === 1) {return interval + ' minute ago';} + if (interval > 1) {return interval + ' minutes ago';} + + if(seconds < 10) return 'just now'; + + return Math.floor(seconds) + ' seconds ago'; +}; + +export function ticks_to_time(ticks: number) { + let seconds = Math.floor(ticks / 60) + let minutes = Math.floor(seconds / 60) + let hours = Math.floor(minutes / 60) + + let milliseconds = Math.floor((ticks % 60) * 1000 / 60) + seconds = seconds % 60; + minutes = minutes % 60; + + return `${hours === 0 ? "" : hours + ":"}${minutes === 0 ? "" : hours > 0 ? minutes.toString().padStart(2, '0') + ":" : (minutes + ":")}${minutes > 0 ? seconds.toString().padStart(2, '0') : seconds}.${milliseconds.toString().padStart(3, '0')}`; +}; \ No newline at end of file diff --git a/frontend/src/utils/Time.tsx b/frontend/src/utils/Time.tsx deleted file mode 100644 index b83a7ed..0000000 --- a/frontend/src/utils/Time.tsx +++ /dev/null @@ -1,42 +0,0 @@ -export function time_ago(date: any) { - const now = new Date().getTime(); - - const localDate = new Date(date.getTime() - (date.getTimezoneOffset() * 60000)); - const seconds = Math.floor((now - localDate.getTime()) / 1000); - - let interval = Math.floor(seconds / 31536000); - if (interval === 1) {return interval + ' year ago';} - if (interval > 1) {return interval + ' years ago';} - - interval = Math.floor(seconds / 2592000); - if (interval === 1) {return interval + ' month ago';} - if (interval > 1) {return interval + ' months ago';} - - interval = Math.floor(seconds / 86400); - if (interval === 1) {return interval + ' day ago';} - if (interval > 1) {return interval + ' days ago';} - - interval = Math.floor(seconds / 3600); - if (interval === 1) {return interval + ' hour ago';} - if (interval > 1) {return interval + ' hours ago';} - - interval = Math.floor(seconds / 60); - if (interval === 1) {return interval + ' minute ago';} - if (interval > 1) {return interval + ' minutes ago';} - - if(seconds < 10) return 'just now'; - - return Math.floor(seconds) + ' seconds ago'; -}; - -export function ticks_to_time(ticks: number) { - let seconds = Math.floor(ticks / 60) - let minutes = Math.floor(seconds / 60) - let hours = Math.floor(minutes / 60) - - let milliseconds = Math.floor((ticks % 60) * 1000 / 60) - seconds = seconds % 60; - minutes = minutes % 60; - - return `${hours === 0 ? "" : hours + ":"}${minutes === 0 ? "" : hours > 0 ? minutes.toString().padStart(2, '0') + ":" : (minutes + ":")}${minutes > 0 ? seconds.toString().padStart(2, '0') : seconds}.${milliseconds.toString().padStart(3, '0')}`; -}; \ No newline at end of file -- cgit v1.2.3