This commit is contained in:
2023-07-24 23:46:18 +03:00
commit 6051ed0b82
121 changed files with 14058 additions and 0 deletions

65
src/utils/apiTypes.ts Normal file
View File

@@ -0,0 +1,65 @@
export interface Showcase {
id: string;
title: string;
summary: string;
body: string;
createdAt: Date;
updatedAt: Date;
tags: ShowcaseTag[];
nodes?: Node[];
materials?: Material[];
author?: Author;
authorId?: string;
}
export interface ShowcaseTag {
id: string;
label: string;
description: string;
color: string;
showcases?: Showcase[];
}
export interface Node {
id: string;
latitude: string;
longitude: string;
showcase?: Showcase;
showcaseId?: string;
}
export interface Material {
id: string;
name: string;
details: string;
image: string;
url: string;
showcases?: Showcase[];
}
export interface Author {
id: string;
githubUsername: string;
bio: string;
showcase?: Showcase[];
}
export interface DeviceFirmwareResource {
id: string;
title: string;
page_url?: string;
zip_url?: string;
}
export interface FirmwareReleases {
releases: {
stable: DeviceFirmwareResource[];
alpha: DeviceFirmwareResource[];
};
pullRequests: DeviceFirmwareResource[];
}

1
src/utils/breakpoints.ts Normal file
View File

@@ -0,0 +1 @@
export const BREAKPOINTS = { sm: 640, md: 768, lg: 1024, xl: 1280 };

23
src/utils/calculateADC.ts Normal file
View File

@@ -0,0 +1,23 @@
export default function calculateADC() {
//const variables
const BAT_MILLIVOLTS_FULL = 4.2;
const BAT_MILLIVOLTS_EMPTY = 3.27;
const BAT_FULL_PERCENT = 1;
//variable
const batteryChargePercent =
parseFloat(
(<HTMLInputElement>document.getElementById("batteryChargePercent")).value,
) / 100;
const operativeAdcMultiplier = parseFloat(
(<HTMLInputElement>document.getElementById("operativeAdcMultiplier")).value,
);
const result =
(operativeAdcMultiplier *
((BAT_FULL_PERCENT - 1) * BAT_MILLIVOLTS_EMPTY -
BAT_FULL_PERCENT * BAT_MILLIVOLTS_FULL)) /
((batteryChargePercent - 1) * BAT_MILLIVOLTS_EMPTY -
batteryChargePercent * BAT_MILLIVOLTS_FULL);
(<HTMLInputElement>(
document.getElementById("newOperativeAdcMultiplier")
)).value = result.toFixed(4);
}

13
src/utils/map.ts Normal file
View File

@@ -0,0 +1,13 @@
import { Node } from "./apiTypes";
export const mapUrl = (nodes: Node[]): string => {
const width = 900;
const height = 400;
const access_token =
"pk.eyJ1Ijoic2FjaGF3IiwiYSI6ImNrNW9meXozZjBsdW0zbHBjM2FnNnV6cmsifQ.3E4n8eFGD9ZOFo-XDVeZnQ";
const nodeCoords = nodes.map(
({ latitude, longitude }) => `pin-l+67ea94(${longitude},${latitude})`,
);
return `https://api.mapbox.com/styles/v1/mapbox/satellite-v9/static/${nodeCoords}/auto/${width}x${height}@2x?access_token=${access_token}`;
};

22
src/utils/showcase.ts Normal file
View File

@@ -0,0 +1,22 @@
export const sortBy = <T>(array: T[], getter: (item: T) => unknown): T[] => {
const sortedArray = [...array];
sortedArray.sort((a, b) =>
getter(a) > getter(b) ? 1 : getter(b) > getter(a) ? -1 : 0,
);
return sortedArray;
};
export const difference = <T>(...arrays: T[][]): T[] => {
return arrays.reduce((a, b) => a.filter((c) => !b.includes(c)));
};
export const toggleListItem = <T>(list: T[], item: T): T[] => {
const itemIndex = list.indexOf(item);
if (itemIndex === -1) {
return list.concat(item);
} else {
const newList = [...list];
newList.splice(itemIndex, 1);
return newList;
}
};

1
src/utils/swr.ts Normal file
View File

@@ -0,0 +1 @@
export const fetcher = (url: string) => fetch(url).then((res) => res.json());