-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* User settings
- Loading branch information
Showing
26 changed files
with
703 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { handleError } from "./lib/handle-error/handle-error.ts"; | ||
import { getUser } from "./services/get-user.ts"; | ||
import { createAuthFailedResponse } from "./lib/json-response/create-auth-failed-response.ts"; | ||
import { createBadRequestResponse } from "./lib/json-response/create-bad-request-response.ts"; | ||
import { envSchema } from "./env/env-schema.ts"; | ||
import { z } from "zod"; | ||
import { getDatabase } from "./db/get-database.ts"; | ||
import { DatabaseException } from "./db/database-exception.ts"; | ||
import { createJsonResponse } from "./lib/json-response/create-json-response.ts"; | ||
import { Database } from "./db/databaseTypes.ts"; | ||
|
||
const requestSchema = z.object({ | ||
isRemindNotifyEnabled: z.boolean(), | ||
remindNotificationTime: z.string(), | ||
}); | ||
|
||
export type UserSettingsRequest = z.infer<typeof requestSchema>; | ||
export type UserSettingsResponse = null; | ||
|
||
type UpdateUserSettingsDatabaseType = Partial< | ||
Database["public"]["Tables"]["user"]["Update"] | ||
>; | ||
|
||
export const onRequestPut = handleError(async ({ request, env }) => { | ||
const user = await getUser(request, env); | ||
if (!user) return createAuthFailedResponse(); | ||
|
||
const input = requestSchema.safeParse(await request.json()); | ||
if (!input.success) { | ||
return createBadRequestResponse(); | ||
} | ||
|
||
const envSafe = envSchema.parse(env); | ||
|
||
const updateBody: UpdateUserSettingsDatabaseType = { | ||
is_remind_enabled: input.data.isRemindNotifyEnabled, | ||
last_reminded_date: input.data.remindNotificationTime, | ||
}; | ||
|
||
const db = getDatabase(envSafe); | ||
const { error } = await db.from("user").update(updateBody).eq("id", user.id); | ||
|
||
if (error) { | ||
throw new DatabaseException(error); | ||
} | ||
|
||
return createJsonResponse<UserSettingsResponse>(null, 200); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
payload: { | ||
client: { | ||
javascript: { | ||
code_version: '1.0.0', | ||
code_version: '1.0.1', | ||
} | ||
}, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const range = (n: number) => { | ||
return Array.from({ length: n }, (x, i) => i); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import WebApp from "@twa-dev/sdk"; | ||
|
||
export const getCloudValue = (key: string): Promise<string | undefined> => { | ||
return new Promise((resolve, reject) => { | ||
WebApp.CloudStorage.getItem(key, (err, value) => { | ||
if (err != null) { | ||
return reject(err); | ||
} else { | ||
return resolve(value); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
export const setCloudValue = (key: string, value: string) => { | ||
return new Promise((resolve, reject) => { | ||
WebApp.CloudStorage.setItem(key, value, (err, result) => { | ||
if (err != null) { | ||
return reject(err); | ||
} else { | ||
return resolve(result); | ||
} | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/ui/modal.tsx → ...reens/deck-review/deck-finished-modal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.