Skip to content

Commit

Permalink
Move types
Browse files Browse the repository at this point in the history
  • Loading branch information
timmo001 committed Sep 3, 2024
1 parent 0a13828 commit 54fc44b
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 139 deletions.
4 changes: 2 additions & 2 deletions src/app/_components/forecast-hourly.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import dayjs from "dayjs";
import { CloudSun } from "lucide-react";

import { getLocationFromLocalStorage } from "~/lib/localStorage";
import { getWeatherForecastHourly } from "~/lib/serverActions/tomorrowio";
import {
type WeatherForecastErrorResponse,
type WeatherForecastHourly,
getWeatherForecastHourly,
} from "~/lib/serverActions/tomorrowio";
} from "~/lib/types/tomorrowio";

export function ForecastHourly() {
const location = useQuery({
Expand Down
4 changes: 2 additions & 2 deletions src/app/_components/forecast-now.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import dayjs from "dayjs";
import relativeTime from "dayjs/plugin/relativeTime";

import { getLocationFromLocalStorage } from "~/lib/localStorage";
import { getWeatherForecastNow } from "~/lib/serverActions/tomorrowio";
import {
type WeatherForecastErrorResponse,
type WeatherForecastNow,
getWeatherForecastNow,
} from "~/lib/serverActions/tomorrowio";
} from "~/lib/types/tomorrowio";

dayjs.extend(relativeTime);

Expand Down
144 changes: 9 additions & 135 deletions src/lib/serverActions/tomorrowio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import { unstable_cache } from "next/cache";

import { env } from "~/env";
import { type Location } from "~/lib/schema";
import {
type WeatherForecastErrorResponse,
type WeatherForecastNow,
type WeatherForecastNowResponse,
type WeatherForecastHourly,
type WeatherForecastHourlyResponse,
type WeatherForecastDaily,
type WeatherForecastDailyResponse,
} from "~/lib/types/tomorrowio";

// TODO: https://docs.tomorrow.io/reference/rate-limiting
// TODO: Check fetch response status
Expand All @@ -16,65 +25,6 @@ const BASE_REQUEST_OPTIONS: RequestInit = {
},
};

export type WeatherForecastErrorResponse = {
code: 429001 | number;
type: "Too Many Calls" | string;
message: string;
};

export type WeatherForecastNowResponse = {
data: {
time: Date;
values: {
cloudBase: number;
cloudCeiling: number;
cloudCover: number;
dewPoint: number;
freezingRainIntensity: number;
humidity: number;
precipitationProbability: number;
pressureSurfaceLevel: number;
rainIntensity: number;
sleetIntensity: number;
snowIntensity: number;
temperature: number;
temperatureApparent: number;
uvHealthConcern: number;
uvIndex: number;
visibility: number;
weatherCode: number;
windDirection: number;
windGust: number;
windSpeed: number;
};
};
location: { lat: number; lon: number };
};

export type WeatherForecastNow = {
time: Date;
cloudBase: number;
cloudCeiling: number;
cloudCover: number;
dewPoint: number;
freezingRainIntensity: number;
humidity: number;
precipitationProbability: number;
pressureSurfaceLevel: number;
rainIntensity: number;
sleetIntensity: number;
snowIntensity: number;
temperature: number;
temperatureApparent: number;
uvHealthConcern: number;
uvIndex: number;
visibility: number;
weatherCode: number;
windDirection: number;
windGust: number;
windSpeed: number;
};

export async function getWeatherForecastNow(
location: Location,
): Promise<WeatherForecastErrorResponse | WeatherForecastNow> {
Expand Down Expand Up @@ -103,78 +53,6 @@ export async function getWeatherForecastNow(
)();
}

export type WeatherForecastHourlyResponse = {
timelines: {
hourly: Array<{
time: Date;
values: {
cloudBase: number;
cloudCeiling: number;
cloudCover: number;
dewPoint: number;
evapotranspiration: number;
freezingRainIntensity: number;
humidity: number;
iceAccumulation: number;
iceAccumulationLwe: number;
precipitationProbability: number;
pressureSurfaceLevel: number;
rainAccumulation: number;
rainAccumulationLwe: number;
rainIntensity: number;
sleetAccumulation: number;
sleetAccumulationLwe: number;
sleetIntensity: number;
snowAccumulation: number;
snowAccumulationLwe: number;
snowIntensity: number;
temperature: number;
temperatureApparent: number;
visibility: number;
weatherCode: number;
windDirection: number;
windGust: number;
windSpeed: number;
};
}>;
};
location: {
lat: number;
lon: number;
};
};

export type WeatherForecastHourly = Array<{
time: Date;
cloudBase: number;
cloudCeiling: number;
cloudCover: number;
dewPoint: number;
evapotranspiration: number;
freezingRainIntensity: number;
humidity: number;
iceAccumulation: number;
iceAccumulationLwe: number;
precipitationProbability: number;
pressureSurfaceLevel: number;
rainAccumulation: number;
rainAccumulationLwe: number;
rainIntensity: number;
sleetAccumulation: number;
sleetAccumulationLwe: number;
sleetIntensity: number;
snowAccumulation: number;
snowAccumulationLwe: number;
snowIntensity: number;
temperature: number;
temperatureApparent: number;
visibility: number;
weatherCode: number;
windDirection: number;
windGust: number;
windSpeed: number;
}>;

export async function getWeatherForecastHourly(
location: Location,
): Promise<WeatherForecastErrorResponse | WeatherForecastHourly> {
Expand Down Expand Up @@ -203,10 +81,6 @@ export async function getWeatherForecastHourly(
)();
}

export type WeatherForecastDailyResponse = any;

export type WeatherForecastDaily = any;

export async function getWeatherForecastDaily(
location: Location,
): Promise<WeatherForecastErrorResponse | WeatherForecastDaily> {
Expand Down
134 changes: 134 additions & 0 deletions src/lib/types/tomorrowio.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
export type WeatherForecastErrorResponse = {
code: 429001 | number;
type: "Too Many Calls" | string;
message: string;
};

export type WeatherForecastNowResponse = {
data: {
time: Date;
values: {
cloudBase: number;
cloudCeiling: number;
cloudCover: number;
dewPoint: number;
freezingRainIntensity: number;
humidity: number;
precipitationProbability: number;
pressureSurfaceLevel: number;
rainIntensity: number;
sleetIntensity: number;
snowIntensity: number;
temperature: number;
temperatureApparent: number;
uvHealthConcern: number;
uvIndex: number;
visibility: number;
weatherCode: number;
windDirection: number;
windGust: number;
windSpeed: number;
};
};
location: { lat: number; lon: number };
};

export type WeatherForecastNow = {
time: Date;
cloudBase: number;
cloudCeiling: number;
cloudCover: number;
dewPoint: number;
freezingRainIntensity: number;
humidity: number;
precipitationProbability: number;
pressureSurfaceLevel: number;
rainIntensity: number;
sleetIntensity: number;
snowIntensity: number;
temperature: number;
temperatureApparent: number;
uvHealthConcern: number;
uvIndex: number;
visibility: number;
weatherCode: number;
windDirection: number;
windGust: number;
windSpeed: number;
};

export type WeatherForecastHourlyResponse = {
timelines: {
hourly: Array<{
time: Date;
values: {
cloudBase: number;
cloudCeiling: number;
cloudCover: number;
dewPoint: number;
evapotranspiration: number;
freezingRainIntensity: number;
humidity: number;
iceAccumulation: number;
iceAccumulationLwe: number;
precipitationProbability: number;
pressureSurfaceLevel: number;
rainAccumulation: number;
rainAccumulationLwe: number;
rainIntensity: number;
sleetAccumulation: number;
sleetAccumulationLwe: number;
sleetIntensity: number;
snowAccumulation: number;
snowAccumulationLwe: number;
snowIntensity: number;
temperature: number;
temperatureApparent: number;
visibility: number;
weatherCode: number;
windDirection: number;
windGust: number;
windSpeed: number;
};
}>;
};
location: {
lat: number;
lon: number;
};
};

export type WeatherForecastHourly = Array<{
time: Date;
cloudBase: number;
cloudCeiling: number;
cloudCover: number;
dewPoint: number;
evapotranspiration: number;
freezingRainIntensity: number;
humidity: number;
iceAccumulation: number;
iceAccumulationLwe: number;
precipitationProbability: number;
pressureSurfaceLevel: number;
rainAccumulation: number;
rainAccumulationLwe: number;
rainIntensity: number;
sleetAccumulation: number;
sleetAccumulationLwe: number;
sleetIntensity: number;
snowAccumulation: number;
snowAccumulationLwe: number;
snowIntensity: number;
temperature: number;
temperatureApparent: number;
visibility: number;
weatherCode: number;
windDirection: number;
windGust: number;
windSpeed: number;
}>;

export type WeatherForecastDailyResponse = any;

export type WeatherForecastDaily = any;

0 comments on commit 54fc44b

Please sign in to comment.