clean code
This commit is contained in:
parent
377a55574d
commit
f184950cbb
@ -1,5 +1,5 @@
|
|||||||
<script lang='ts'>
|
<script lang='ts'>
|
||||||
import { stockTicker, userRegion, getCache, setCache, displayCompanyName, screenWidth, numberOfUnreadNotification } from '$lib/store';
|
import { stockTicker, getCache, setCache, displayCompanyName, screenWidth, numberOfUnreadNotification } from '$lib/store';
|
||||||
import InfiniteLoading from '$lib/components/InfiniteLoading.svelte';
|
import InfiniteLoading from '$lib/components/InfiniteLoading.svelte';
|
||||||
import { page } from '$app/stores';
|
import { page } from '$app/stores';
|
||||||
|
|
||||||
@ -12,28 +12,12 @@
|
|||||||
let notDestroyed = true;
|
let notDestroyed = true;
|
||||||
|
|
||||||
let charNumber = 20;
|
let charNumber = 20;
|
||||||
let displayQuarter = '1';
|
let displayQuarter = data?.quarter;
|
||||||
let displayYear = '2024';
|
let displayYear = data?.year;
|
||||||
let quarter = displayQuarter;
|
let quarter = displayQuarter;
|
||||||
let year = displayYear;
|
let year = displayYear;
|
||||||
let isLoaded = true;
|
let isLoaded = true;
|
||||||
|
|
||||||
const usRegion = ['cle1','iad1','pdx1','sfo1'];
|
|
||||||
|
|
||||||
let apiURL;
|
|
||||||
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
|
|
||||||
|
|
||||||
|
|
||||||
userRegion.subscribe(value => {
|
|
||||||
|
|
||||||
if (usRegion.includes(value)) {
|
|
||||||
apiURL = import.meta.env.VITE_USEAST_API_URL;
|
|
||||||
} else {
|
|
||||||
apiURL = import.meta.env.VITE_EU_API_URL;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
function backToTop() {
|
function backToTop() {
|
||||||
window.scrollTo({
|
window.scrollTo({
|
||||||
top: 0,
|
top: 0,
|
||||||
@ -68,12 +52,12 @@ let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
|
|||||||
quarter: quarter,
|
quarter: quarter,
|
||||||
year: year
|
year: year
|
||||||
};
|
};
|
||||||
|
console.log('test')
|
||||||
// make the POST request to the endpoint
|
// make the POST request to the endpoint
|
||||||
const response = await fetch(apiURL + '/earnings-call-transcripts', {
|
const response = await fetch(data?.apiURL + '/earnings-call-transcripts', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json", "X-API-KEY": apiKey
|
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
|
||||||
},
|
},
|
||||||
body: JSON.stringify(postData)
|
body: JSON.stringify(postData)
|
||||||
});
|
});
|
||||||
@ -162,13 +146,13 @@ let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
|
|||||||
|
|
||||||
|
|
||||||
<div class="flex flex-row items-center mb-5 pt-3 justify-center sm:justify-end">
|
<div class="flex flex-row items-center mb-5 pt-3 justify-center sm:justify-end">
|
||||||
<label for="quarterModal" class="ml-1 sm:ml-3 text-sm cursor-pointer bg-[#09090B] sm:hover:bg-[#09090B] duration-100 transition ease-in-out px-4 py-1.5 rounded-lg shadow-md">
|
<label for="quarterModal" class="ml-1 sm:ml-3 text-sm cursor-pointer bg-purple-600 sm:hover:bg-purple-700 duration-100 transition ease-in-out px-4 py-1.5 rounded-lg shadow-md">
|
||||||
Quarter: Q{quarter}
|
Quarter: Q{quarter}
|
||||||
</label>
|
</label>
|
||||||
<label for="yearModal" class="ml-3 text-sm cursor-pointer bg-[#09090B] sm:hover:bg-[#09090B] duration-100 transition ease-in-out px-4 py-1.5 rounded-lg shadow-md">
|
<label for="yearModal" class="ml-3 text-sm cursor-pointer bg-purple-600 sm:hover:bg-purple-700 duration-100 transition ease-in-out px-4 py-1.5 rounded-lg shadow-md">
|
||||||
Year: {year}
|
Year: {year}
|
||||||
</label>
|
</label>
|
||||||
<label on:click={() => getTranscripts()} class="ml-3 text-sm cursor-pointer bg-[#09090B] sm:hover:bg-[#09090B] duration-100 transition ease-in-out px-4 py-1.5 rounded-lg shadow-md">
|
<label on:click={() => getTranscripts()} class="ml-3 text-sm cursor-pointer bg-purple-600 sm:hover:bg-purple-700 duration-100 transition ease-in-out px-4 py-1.5 rounded-lg shadow-md">
|
||||||
Run
|
Run
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,23 +1,11 @@
|
|||||||
import { userRegion, getCache, setCache } from '$lib/store';
|
import { getCache, setCache } from '$lib/store';
|
||||||
|
|
||||||
|
|
||||||
const usRegion = ['cle1','iad1','pdx1','sfo1'];
|
const now = new Date();
|
||||||
|
const year = now?.getFullYear()?.toString();
|
||||||
|
const quarter = (Math.floor(now?.getMonth() / 3) + 1)?.toString();
|
||||||
|
|
||||||
let apiURL = import.meta.env.VITE_EU_API_URL; // Set a default API URL
|
export const load = async ({ parent, params }) => {
|
||||||
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
|
|
||||||
|
|
||||||
userRegion.subscribe(value => {
|
|
||||||
|
|
||||||
if (usRegion.includes(value)) {
|
|
||||||
apiURL = import.meta.env.VITE_USEAST_API_URL;
|
|
||||||
} else {
|
|
||||||
apiURL = import.meta.env.VITE_EU_API_URL;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export const load = async ({ params }) => {
|
|
||||||
const getTranscripts = async () => {
|
const getTranscripts = async () => {
|
||||||
let output;
|
let output;
|
||||||
|
|
||||||
@ -26,10 +14,12 @@ export const load = async ({ params }) => {
|
|||||||
if (cachedData) {
|
if (cachedData) {
|
||||||
output = cachedData;
|
output = cachedData;
|
||||||
} else {
|
} else {
|
||||||
|
const { apiKey, apiURL } = await parent();
|
||||||
|
|
||||||
const postData = {
|
const postData = {
|
||||||
ticker: params.tickerID,
|
ticker: params.tickerID,
|
||||||
quarter: '1',
|
quarter: quarter,
|
||||||
year: '2024'
|
year: year
|
||||||
};
|
};
|
||||||
|
|
||||||
// make the POST request to the endpoint
|
// make the POST request to the endpoint
|
||||||
@ -44,7 +34,7 @@ export const load = async ({ params }) => {
|
|||||||
output = await response.json();
|
output = await response.json();
|
||||||
|
|
||||||
// Cache the data for this specific tickerID with a specific name 'getTranscripts'
|
// Cache the data for this specific tickerID with a specific name 'getTranscripts'
|
||||||
setCache(`${params.tickerID}-Q-1-2024`, output, 'getTranscripts');
|
setCache(`${params.tickerID}-Q-${quarter}-${year}`, output, 'getTranscripts');
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
@ -52,6 +42,8 @@ export const load = async ({ params }) => {
|
|||||||
|
|
||||||
// Make sure to return a promise
|
// Make sure to return a promise
|
||||||
return {
|
return {
|
||||||
getTranscripts: await getTranscripts()
|
getTranscripts: await getTranscripts(),
|
||||||
|
quarter,
|
||||||
|
year
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user