Try to clean it up a little
All checks were successful
Build and Publish Docker Container / build (push) Successful in 3m45s
All checks were successful
Build and Publish Docker Container / build (push) Successful in 3m45s
This commit is contained in:
parent
9752ede109
commit
17edc05ec4
@ -1,64 +1,7 @@
|
||||
import {NextRequest} from "next/server";
|
||||
import {getData, OverviewConfig} from "@/data/fetchWithSQL";
|
||||
|
||||
export const semester1Revision: OverviewConfig = {
|
||||
title: 'Semester 1 Revision',
|
||||
periodKey: 'y5-s1-revision',
|
||||
goalHours: 4,
|
||||
subjects: [
|
||||
{
|
||||
projectId: 195482340,
|
||||
},
|
||||
{
|
||||
title: 'Measure Theory',
|
||||
projectId: 195519024,
|
||||
},
|
||||
{
|
||||
title: 'Quantum Mechanics',
|
||||
projectId: 195518593,
|
||||
},
|
||||
{
|
||||
projectId: 195754611,
|
||||
}
|
||||
],
|
||||
timePeriod: {
|
||||
start: "2023-12-15T00:00:00.000Z",
|
||||
end: "2024-01-25T00:00:00.000Z"
|
||||
}
|
||||
}
|
||||
|
||||
export const semester2: OverviewConfig = {
|
||||
title: 'Semester 2',
|
||||
periodKey: 'y5-s2',
|
||||
goalHours: 7.5,
|
||||
subjects: [
|
||||
{
|
||||
projectId: 195754611,
|
||||
},
|
||||
{
|
||||
projectId: 199383703,
|
||||
},
|
||||
{
|
||||
projectId: 199383691,
|
||||
},
|
||||
{
|
||||
projectId: 198859760,
|
||||
},
|
||||
{
|
||||
projectId: 199383698,
|
||||
},
|
||||
],
|
||||
timePeriod: {
|
||||
start: "2024-02-03T00:00:00.000Z",
|
||||
end: "2024-05-10T00:00:00.000Z"
|
||||
}
|
||||
}
|
||||
|
||||
export type PeriodKey = keyof typeof periodMap;
|
||||
const periodMap = {
|
||||
'y5-s1-revision': semester1Revision,
|
||||
'y5-s2': semester2,
|
||||
}
|
||||
import {getData} from "@/data/fetchData";
|
||||
import {periodMap} from "@/data/periods";
|
||||
|
||||
export async function GET(request: NextRequest): Promise<Response> {
|
||||
const period = request.nextUrl.searchParams.get('period');
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import {semester1Revision} from "@/app/api/route";
|
||||
import OverviewPageWrapper from "@/components/PageWrapper";
|
||||
|
||||
export default function Home() {
|
||||
return <OverviewPageWrapper config={semester1Revision}/>
|
||||
return <OverviewPageWrapper period={'y5-s1-revision'}/>
|
||||
}
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import {semester2} from "@/app/api/route";
|
||||
import OverviewPageWrapper from "@/components/PageWrapper";
|
||||
|
||||
export default function Home() {
|
||||
return <OverviewPageWrapper config={semester2}/>
|
||||
return <OverviewPageWrapper period={'y5-s2'}/>
|
||||
}
|
||||
|
||||
@ -3,10 +3,9 @@
|
||||
import {SubjectComparisonCard} from "@/components/cards/subjectComparisonCard";
|
||||
import {CalendarOverviewCard} from "@/components/cards/calendarOverviewCard";
|
||||
import {SubjectOverviewCard} from "@/components/cards/subjectOverviewCard";
|
||||
import {PeriodKey} from "@/app/api/route";
|
||||
import useSWR from "swr";
|
||||
import {Data} from "@/data/fetchData";
|
||||
import {OverviewConfig} from "@/data/fetchWithSQL";
|
||||
import {Data, OverviewConfig} from "@/data/fetchData";
|
||||
import {PeriodKey} from "@/data/periods";
|
||||
|
||||
function useData(periodKey: PeriodKey, initialData: Data = {
|
||||
projects: [],
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
"use server";
|
||||
|
||||
import {getData, OverviewConfig} from "@/data/fetchWithSQL";
|
||||
import OverviewPage from "@/components/OverviewPage";
|
||||
import {getData} from "@/data/fetchData";
|
||||
import {PeriodKey, periodMap} from "@/data/periods";
|
||||
|
||||
export default async function OverviewPageWrapper({config}: {
|
||||
config: OverviewConfig
|
||||
export default async function OverviewPageWrapper({period}: {
|
||||
period: PeriodKey
|
||||
}) {
|
||||
const config = periodMap[period];
|
||||
const data = await getData(config);
|
||||
return <OverviewPage config={config} initialData={data}/>;
|
||||
}
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
"use server";
|
||||
|
||||
import {db} from "@/data/database";
|
||||
import * as dFns from "date-fns";
|
||||
import {PeriodKey} from "@/data/periods";
|
||||
|
||||
export interface Data {
|
||||
projects: {
|
||||
projectId: number,
|
||||
@ -15,3 +19,61 @@ export interface Data {
|
||||
// description: string,
|
||||
}[],
|
||||
}
|
||||
|
||||
export interface OverviewConfig {
|
||||
title: string,
|
||||
periodKey: PeriodKey,
|
||||
|
||||
subjects: {
|
||||
title?: string,
|
||||
projectId: number,
|
||||
}[],
|
||||
|
||||
goalHours: number,
|
||||
|
||||
timePeriod: {
|
||||
start: string,
|
||||
end: string
|
||||
},
|
||||
}
|
||||
|
||||
export async function getData(config: OverviewConfig): Promise<Data> {
|
||||
// If we're in build-time, we don't have access to the database
|
||||
if (!db) {
|
||||
return {
|
||||
projects: [],
|
||||
timeEntries: [],
|
||||
}
|
||||
}
|
||||
|
||||
console.log('fetching data from SQL')
|
||||
|
||||
let projectIds = config.subjects.map((subject) => subject.projectId.toString());
|
||||
|
||||
const projects = await db.selectFrom('project')
|
||||
.select('raw_json')
|
||||
.where('project.toggl_id', 'in', projectIds)
|
||||
.execute();
|
||||
|
||||
const timeEntries = await db.selectFrom('time_entry')
|
||||
.select(['project_id', 'raw_json'])
|
||||
.where('project_id', 'in', projectIds)
|
||||
.where('start', '>', dFns.parseISO(config.timePeriod.start))
|
||||
.where('start', '<', dFns.parseISO(config.timePeriod.end))
|
||||
.execute();
|
||||
|
||||
return {
|
||||
projects: projects.map((project) => ({
|
||||
projectId: project.raw_json.id,
|
||||
name: project.raw_json.name,
|
||||
color: project.raw_json.color,
|
||||
})),
|
||||
|
||||
timeEntries: timeEntries.map((timeEntry) => ({
|
||||
projectId: parseInt(timeEntry.project_id!),
|
||||
start: timeEntry.raw_json.start,
|
||||
end: timeEntry.raw_json.end,
|
||||
duration: timeEntry.raw_json.seconds,
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,62 +0,0 @@
|
||||
import {Data} from "@/data/fetchData";
|
||||
import {db} from "@/data/database";
|
||||
import * as dFns from "date-fns";
|
||||
import {PeriodKey} from "@/app/api/route";
|
||||
|
||||
export interface OverviewConfig {
|
||||
title: string,
|
||||
periodKey: PeriodKey,
|
||||
|
||||
subjects: {
|
||||
title?: string,
|
||||
projectId: number,
|
||||
}[],
|
||||
|
||||
goalHours: number,
|
||||
|
||||
timePeriod: {
|
||||
start: string,
|
||||
end: string
|
||||
},
|
||||
}
|
||||
|
||||
export async function getData(config: OverviewConfig): Promise<Data> {
|
||||
// If we're in build-time, we don't have access to the database
|
||||
if (!db) {
|
||||
return {
|
||||
projects: [],
|
||||
timeEntries: [],
|
||||
}
|
||||
}
|
||||
|
||||
console.log('fetching data from SQL')
|
||||
|
||||
let projectIds = config.subjects.map((subject) => subject.projectId.toString());
|
||||
|
||||
const projects = await db.selectFrom('project')
|
||||
.select('raw_json')
|
||||
.where('project.toggl_id', 'in', projectIds)
|
||||
.execute();
|
||||
|
||||
const timeEntries = await db.selectFrom('time_entry')
|
||||
.select(['project_id', 'raw_json'])
|
||||
.where('project_id', 'in', projectIds)
|
||||
.where('start', '>', dFns.parseISO(config.timePeriod.start))
|
||||
.where('start', '<', dFns.parseISO(config.timePeriod.end))
|
||||
.execute();
|
||||
|
||||
return {
|
||||
projects: projects.map((project) => ({
|
||||
projectId: project.raw_json.id,
|
||||
name: project.raw_json.name,
|
||||
color: project.raw_json.color,
|
||||
})),
|
||||
|
||||
timeEntries: timeEntries.map((timeEntry) => ({
|
||||
projectId: parseInt(timeEntry.project_id!),
|
||||
start: timeEntry.raw_json.start,
|
||||
end: timeEntry.raw_json.end,
|
||||
duration: timeEntry.raw_json.seconds,
|
||||
})),
|
||||
}
|
||||
}
|
||||
60
src/data/periods.ts
Normal file
60
src/data/periods.ts
Normal file
@ -0,0 +1,60 @@
|
||||
import {OverviewConfig} from "@/data/fetchData";
|
||||
|
||||
export const semester1Revision: OverviewConfig = {
|
||||
title: 'Semester 1 Revision',
|
||||
periodKey: 'y5-s1-revision',
|
||||
goalHours: 4,
|
||||
subjects: [
|
||||
{
|
||||
projectId: 195482340,
|
||||
},
|
||||
{
|
||||
title: 'Measure Theory',
|
||||
projectId: 195519024,
|
||||
},
|
||||
{
|
||||
title: 'Quantum Mechanics',
|
||||
projectId: 195518593,
|
||||
},
|
||||
{
|
||||
projectId: 195754611,
|
||||
}
|
||||
],
|
||||
timePeriod: {
|
||||
start: "2023-12-15T00:00:00.000Z",
|
||||
end: "2024-01-25T00:00:00.000Z"
|
||||
}
|
||||
}
|
||||
|
||||
export const semester2: OverviewConfig = {
|
||||
title: 'Semester 2',
|
||||
periodKey: 'y5-s2',
|
||||
goalHours: 7.5,
|
||||
subjects: [
|
||||
{
|
||||
projectId: 195754611,
|
||||
},
|
||||
{
|
||||
projectId: 199383703,
|
||||
},
|
||||
{
|
||||
projectId: 199383691,
|
||||
},
|
||||
{
|
||||
projectId: 198859760,
|
||||
},
|
||||
{
|
||||
projectId: 199383698,
|
||||
},
|
||||
],
|
||||
timePeriod: {
|
||||
start: "2024-02-03T00:00:00.000Z",
|
||||
end: "2024-05-10T00:00:00.000Z"
|
||||
}
|
||||
}
|
||||
|
||||
export type PeriodKey = keyof typeof periodMap;
|
||||
export const periodMap = {
|
||||
'y5-s1-revision': semester1Revision,
|
||||
'y5-s2': semester2,
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user