Skip to content

Commit

Permalink
Merge pull request #226 from SimonStnn/refactor/new-account-creation
Browse files Browse the repository at this point in the history
Don't set a default username
  • Loading branch information
SimonStnn authored Jun 16, 2024
2 parents d6897e2 + 7114047 commit 9eae850
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/background/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const updateBadgeColors = () => {
let localUser = await storage.sync.get('user');
// If the user is not in the local storage, get a new user from the remote
if (!localUser) {
const usr = await remote.NewUser('Anonymous');
const usr = await remote.NewUser();
await storage.sync.set('token', usr.token);
localUser = usr;
}
Expand Down
4 changes: 2 additions & 2 deletions src/balloons/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ export default class Default extends Balloon {
/**
* The image element for the balloon image.
*/
protected readonly balloonImage: HTMLImageElement =
public readonly balloonImage: HTMLImageElement =
document.createElement('img');

/**
* The sound element for the pop sound.
*/
private readonly popSound: HTMLAudioElement = new Audio();
public readonly popSound: HTMLAudioElement = new Audio();

/**
* The URL of the balloon image.
Expand Down
2 changes: 1 addition & 1 deletion src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const initalConfig: _initialConfig = {

export type User = {
id: string;
username: string;
username?: string;
email?: string;
count: number;
updatedAt: string;
Expand Down
7 changes: 5 additions & 2 deletions src/popup/components/forms/UpdateUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default () => {
const loadUser = async () => {
const storedUser = await storage.sync.get('user');
setUser(storedUser);
form.setValue('username', storedUser.username);
form.setValue('username', storedUser.username || '');
form.setValue('email', storedUser.email || '');
};

Expand All @@ -56,7 +56,10 @@ export default () => {

const onSubmit = async ({ username, email }: z.infer<typeof formSchema>) => {
if (username === user?.username && email === user?.email) return;
const newUser = await remote.putUser({ username, email });
const newUser = await remote.putUser({
username: username !== '' ? username : undefined,
email: email !== '' ? email : undefined,
});
setUser(newUser);
await storage.sync.set('user', newUser);
};
Expand Down
2 changes: 1 addition & 1 deletion src/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class BackendAPI {
);
}

public async NewUser(username: string, email?: string) {
public async NewUser(username?: string, email?: string) {
return await this.request<
Prettify<{ token: string } & RemoteResponse['user']>
>('POST', '/user/new', {
Expand Down

0 comments on commit 9eae850

Please sign in to comment.