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