Fix initial load breaking.
This commit is contained in:
@@ -18,12 +18,12 @@ import LinksDeletedChart from "./LinksDeletedChart";
|
|||||||
import { LineChartArr } from "@/types/LineChartStats";
|
import { LineChartArr } from "@/types/LineChartStats";
|
||||||
import CommandResponsesChart from "./CommandResponsesChart";
|
import CommandResponsesChart from "./CommandResponsesChart";
|
||||||
import TimedTriggeredChart from "./TimesTriggeredChart";
|
import TimedTriggeredChart from "./TimesTriggeredChart";
|
||||||
import GetStatsRange from "@/graphql/queries/getStatsRange";
|
import Image from "next/image";
|
||||||
import StatsList from "./StatsList";
|
import StatsList from "./StatsList";
|
||||||
import GetTotalGroupsQuery from "@/graphql/queries/getTotalGroups";
|
import GetTotalGroupsQuery from "@/graphql/queries/getTotalGroups";
|
||||||
import GetTotalStatsQuery from "@/graphql/queries/getTotalStats";
|
import GetTotalStatsQuery from "@/graphql/queries/getTotalStats";
|
||||||
import GetTodaysStatsQuery from "@/graphql/queries/getTodaysStats";
|
import GetTodaysStatsQuery from "@/graphql/queries/getTodaysStats";
|
||||||
import Image from "next/image";
|
import GetStatsRange from "@/graphql/queries/getStatsRange";
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
// * Total Groups * //
|
// * Total Groups * //
|
||||||
@@ -57,12 +57,14 @@ export default function Home() {
|
|||||||
// * 30 Day Stats * //
|
// * 30 Day Stats * //
|
||||||
|
|
||||||
// Dates
|
// Dates
|
||||||
const [currDate, setCurrDate] = useState<Date>();
|
const [currDate, setCurrDate] = useState<String>();
|
||||||
const [date30DaysAgo, setDate30DaysAgo] = useState<Date>();
|
const [date30DaysAgo, setDate30DaysAgo] = useState<String>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setCurrDate(new Date());
|
setCurrDate(new Date().toJSON());
|
||||||
setDate30DaysAgo(new Date(new Date().setDate(new Date().getDay() - 30)));
|
setDate30DaysAgo(
|
||||||
|
new Date(new Date().setDate(new Date().getDay() - 30)).toJSON()
|
||||||
|
);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const [
|
const [
|
||||||
@@ -74,8 +76,8 @@ export default function Home() {
|
|||||||
] = useQuery({
|
] = useQuery({
|
||||||
query: GetStatsRange,
|
query: GetStatsRange,
|
||||||
variables: {
|
variables: {
|
||||||
stateDate: currDate,
|
startDate: currDate || "",
|
||||||
endDate: date30DaysAgo
|
endDate: date30DaysAgo || ""
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { gql } from "@urql/next";
|
import { gql } from "@urql/next";
|
||||||
|
|
||||||
const GetStatsRange = gql`
|
const GetStatsRange = gql`
|
||||||
query getStatsRange($startDate: Date, $endDate: Date) {
|
query getStatsRange($startDate: String!, $endDate: String!) {
|
||||||
getStatsRange(endDate: $startDate, startDate: $endDate) {
|
getStatsRange(endDate: $startDate, startDate: $endDate) {
|
||||||
commandResponses
|
commandResponses
|
||||||
createdAt
|
createdAt
|
||||||
|
|||||||
@@ -33,15 +33,20 @@ export const resolvers = {
|
|||||||
}),
|
}),
|
||||||
getStatsRange: async (
|
getStatsRange: async (
|
||||||
_parent: unknown,
|
_parent: unknown,
|
||||||
data: { startDate: Date; endDate: Date }
|
data: { startDate: string; endDate: string }
|
||||||
// _ctx: unknown
|
// _ctx: unknown
|
||||||
) => {
|
) => {
|
||||||
const { startDate, endDate } = data;
|
const { startDate, endDate } = data;
|
||||||
|
|
||||||
|
if (startDate === "" || endDate === "") {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return await prisma.dailyStats.findMany({
|
return await prisma.dailyStats.findMany({
|
||||||
where: {
|
where: {
|
||||||
createdAt: {
|
createdAt: {
|
||||||
gt: startDate,
|
gt: new Date(startDate),
|
||||||
lte: endDate
|
lte: new Date(endDate)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
orderBy: {
|
orderBy: {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ const typeDefs = /* GraphQL */ `
|
|||||||
type Query {
|
type Query {
|
||||||
getTotalGroups: Int!
|
getTotalGroups: Int!
|
||||||
getTodayStats: DailyStats!
|
getTodayStats: DailyStats!
|
||||||
getStatsRange(startDate: Date, endDate: Date): [DailyStats]
|
getStatsRange(startDate: String!, endDate: String!): [DailyStats]
|
||||||
getTotalStats: TotalStats!
|
getTotalStats: TotalStats!
|
||||||
getGroupStats(groupID: BigInt!): Groups
|
getGroupStats(groupID: BigInt!): Groups
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ const config: runtime.GetPrismaClientConfig = {
|
|||||||
"value": "prisma-client"
|
"value": "prisma-client"
|
||||||
},
|
},
|
||||||
"output": {
|
"output": {
|
||||||
"value": "/home/lucid/work/cove-gitea/no-twitter-bot-stats/src/prisma/generated",
|
"value": "/home/lucid/work/WKC/no-twitter-bot-stats/src/prisma/generated",
|
||||||
"fromEnvVar": null
|
"fromEnvVar": null
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
@@ -37,7 +37,7 @@ const config: runtime.GetPrismaClientConfig = {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"previewFeatures": [],
|
"previewFeatures": [],
|
||||||
"sourceFilePath": "/home/lucid/work/cove-gitea/no-twitter-bot-stats/src/prisma/schema.prisma",
|
"sourceFilePath": "/home/lucid/work/WKC/no-twitter-bot-stats/src/prisma/schema.prisma",
|
||||||
"isCustomOutput": true
|
"isCustomOutput": true
|
||||||
},
|
},
|
||||||
"relativePath": "..",
|
"relativePath": "..",
|
||||||
|
|||||||
Reference in New Issue
Block a user