Skip to content

Commit

Permalink
fix: Improved Code a bit & fixed values -> value
Browse files Browse the repository at this point in the history
  • Loading branch information
noahonyejese committed Jan 8, 2025
1 parent 79803e2 commit 67d5030
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
5 changes: 1 addition & 4 deletions contexts/chart-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export const ChartProvider: FC<DefaultChildren> = ({ children }) => {
metricConfigs?.views[0].view || 'random'
);

// Cycle through views every X seconds
useEffect(() => {
if (!metricConfigs) return;
const id = setInterval(() => {
Expand All @@ -57,19 +56,17 @@ export const ChartProvider: FC<DefaultChildren> = ({ children }) => {
return () => clearInterval(id);
}, [displayType, metricConfigs]);

// Effect to remove objects from 'changed' after 5 seconds
useEffect(() => {
const intervalId = setInterval(() => {
const now = Date.now();
setChanged((prevChanged) =>
prevChanged.filter((item) => now - item.timestamp < 3000)
);
}, 1000); // Check every second
}, 1000);

return () => clearInterval(intervalId);
}, []);

// Example function to add a change
const addChange = (id: string, cause?: string) => {
setChanged((prevChanged) => [
...prevChanged,
Expand Down
2 changes: 1 addition & 1 deletion server/github/syncs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const validateGithubProjectInputs = (project: Repository) => {
export const projectSync = async (project: Repository) => {
const db = admin.database();
const userRef = db.ref(
`data/team-projects/sensors/github/values/${project.id}`
`data/team-projects/sensors/github/value/${project.id}`
);

const snapshot = await userRef.once('value');
Expand Down
2 changes: 1 addition & 1 deletion types/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export interface DisplayDataBase<T> {
title: string;
description: string;
sensors: {
[key: `sensor-${number}`]: {
[key: string]: {
title: string;
value: T;
};
Expand Down
10 changes: 6 additions & 4 deletions utils/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ export const formatRTDBData = <T extends FormattedDataMapping<any>>(
displayType: DisplayType
): T | null => {
if (!data) return null;

console.log('raw Data', data);
const typedData = data as DisplayDataMapping<typeof displayType>;

const formattedSensors = Object.keys(typedData.sensors).map((sensorKey) => {
const sensor = typedData.sensors[sensorKey as `sensor-${number}`];
const sensor = typedData.sensors[sensorKey as string];

const value =
typeof sensor.value === 'object' && !Array.isArray(sensor.value)
Expand All @@ -31,7 +31,7 @@ export const formatRTDBData = <T extends FormattedDataMapping<any>>(
: sensor.value;

return {
id: sensorKey, // use the sensor key as the id
id: sensorKey,
title: sensor.title,
value,
};
Expand All @@ -43,6 +43,8 @@ export const formatRTDBData = <T extends FormattedDataMapping<any>>(
sensors: formattedSensors,
} as T;

console.log('Formatted Data', formattedData);

return formattedData;
};

Expand Down Expand Up @@ -120,7 +122,7 @@ export const viewTeamPositions = ({

const diagLength = space - margin * 2;

const outerOffset = 50;
const outerOffset = 50;

const half = Math.ceil(members.length / 2);
const positiveDiagonalMembers = members.slice(0, half);
Expand Down

0 comments on commit 67d5030

Please sign in to comment.