coyotte508 HF staff commited on
Commit
da7f5d6
1 Parent(s): b3563cb

🐛 Some users have a time too different, let's set the date ourselves (#163)

Browse files
src/lib/components/EthicsModal.svelte CHANGED
@@ -35,7 +35,7 @@
35
  <!-- The updateSettings call will invalidate the settings, which will reload the page without the modal -->
36
  <button
37
  type="button"
38
- on:click={() => updateSettings({ ...settings, ethicsModalAcceptedAt: new Date() })}
39
  class="mt-2 rounded-full bg-black px-5 py-2 text-lg font-semibold text-gray-100 transition-colors hover:bg-yellow-500"
40
  >
41
  Start chatting
 
35
  <!-- The updateSettings call will invalidate the settings, which will reload the page without the modal -->
36
  <button
37
  type="button"
38
+ on:click={() => updateSettings({ ...settings, ethicsModalAccepted: true })}
39
  class="mt-2 rounded-full bg-black px-5 py-2 text-lg font-semibold text-gray-100 transition-colors hover:bg-yellow-500"
40
  >
41
  Start chatting
src/lib/updateSettings.ts CHANGED
@@ -5,7 +5,9 @@ import type { Settings } from "./types/Settings";
5
  import { UrlDependency } from "./types/UrlDependency";
6
 
7
  export async function updateSettings(
8
- settings: Partial<Omit<Settings, "sessionId">>
 
 
9
  ): Promise<boolean> {
10
  try {
11
  const res = await fetch(`${base}/settings`, {
 
5
  import { UrlDependency } from "./types/UrlDependency";
6
 
7
  export async function updateSettings(
8
+ settings: Partial<
9
+ Omit<Settings, "sessionId" | "ethicsModalAcceptedAt"> & { ethicsModalAccepted?: boolean }
10
+ >
11
  ): Promise<boolean> {
12
  try {
13
  const res = await fetch(`${base}/settings`, {
src/routes/settings/+server.ts CHANGED
@@ -1,14 +1,13 @@
1
  import { collections } from "$lib/server/database.js";
2
- import { subMinutes } from "date-fns";
3
  import { z } from "zod";
4
 
5
  export async function PATCH({ locals, request }) {
6
  const json = await request.json();
7
 
8
- const settings = z
9
  .object({
10
  shareConversationsWithModelAuthors: z.boolean().default(true),
11
- ethicsModalAcceptedAt: z.optional(z.date({ coerce: true }).min(subMinutes(new Date(), 5))),
12
  })
13
  .parse(json);
14
 
@@ -19,6 +18,7 @@ export async function PATCH({ locals, request }) {
19
  {
20
  $set: {
21
  ...settings,
 
22
  updatedAt: new Date(),
23
  },
24
  $setOnInsert: {
 
1
  import { collections } from "$lib/server/database.js";
 
2
  import { z } from "zod";
3
 
4
  export async function PATCH({ locals, request }) {
5
  const json = await request.json();
6
 
7
+ const { ethicsModalAccepted, ...settings } = z
8
  .object({
9
  shareConversationsWithModelAuthors: z.boolean().default(true),
10
+ ethicsModalAccepted: z.boolean().optional(),
11
  })
12
  .parse(json);
13
 
 
18
  {
19
  $set: {
20
  ...settings,
21
+ ...(ethicsModalAccepted && { ethicsModalAcceptedAt: new Date() }),
22
  updatedAt: new Date(),
23
  },
24
  $setOnInsert: {