Skip to content

Commit

Permalink
Added recently used characters.
Browse files Browse the repository at this point in the history
  • Loading branch information
Morgul committed Dec 11, 2024
1 parent 6a8b1fe commit e25e0b3
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 75 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
.cache
dist
*.tsbuildinfo
/src/client/components.d.ts

# Node artifacts
node_modules
Expand Down
7 changes: 4 additions & 3 deletions src/client/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,6 @@ declare global
}
}

const appVersion = await versionRA.getAppVersion();
window.RPGKeeper = appVersion;

//----------------------------------------------------------------------------------------------------------------------
// App Initialization
//----------------------------------------------------------------------------------------------------------------------
Expand All @@ -158,6 +155,10 @@ async function init() : Promise<void>
// Mount the application
app.mount('#rpgkeeper');

// Set the app version on window
const appVersion = await versionRA.getAppVersion();
window.RPGKeeper = appVersion;

// Print out an initialization message
console.info(`RPGKeeper v${ appVersion.version.full } initialized.`);
}
Expand Down
67 changes: 0 additions & 67 deletions src/client/components.d.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/client/lib/resource-access/character.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class CharacterResourceAccess
color: randomColor(),
campaign: '',
details: { ...system.defaults } as Details,
created: Date.now(),
updated: Date.now(),
...def,
};
}
Expand Down
8 changes: 8 additions & 0 deletions src/client/lib/stores/characters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ export const useCharactersStore = defineStore('characters', {
characters: [],
};
},
getters: {
recentCharacters() : Character[]
{
return this.characters
.slice()
.sort((charA, charB) => charB.updated - charA.updated);
},
},
actions: {
async load() : Promise<void>
{
Expand Down
35 changes: 35 additions & 0 deletions src/client/pages/dashboardPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@

<template>
<BContainer id="dashboard" class="pb-0">
<h3>Recently Used</h3>
<div class="d-flex gap-2 mb-5">
<BCard v-for="char in recentCharacters" :key="char.id">
<div class="d-flex">
<div style="min-width: 64px">
<CharThumbnail :char="char" />
</div>
<div class="ms-2 flex-column d-flex justify-content-center">
<h5 class="mb-1">
{{ char.name }}
</h5>
<p class="text-muted m-0">
<BBadge class="me-1">
{{ getSystem(char.system).name }}
</BBadge>
</p>
<p class="text-muted m-0">
<small>{{ char.campaign }}</small>
</p>
</div>
</div>
</BCard>
</div>
<BFormRow>
<BCol cols="12" class="mb-3">
<!-- Characters Card -->
Expand Down Expand Up @@ -226,6 +249,18 @@
return [];
});

const recentCharacters = computed(() =>
{
if(account.value)
{
return charStore.recentCharacters
.filter((char) => char.accountID == account.value.id)
.slice(0, 5);
}

return [];
});

//------------------------------------------------------------------------------------------------------------------
// Methods
//------------------------------------------------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion src/common/models/character.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export interface Character<Details extends SystemDetails = SystemDetails>
campaign ?: string;
accountID : string;
noteID : string;
details : Details
details : Details;
created : number;
updated : number;
}

//----------------------------------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export async function up(knex : Knex) : Promise<Knex.QueryBuilder>
.insert(characters.map((character) =>
{
return {
character_id: character.hash_id,
character_id: character.character_id,
system: character.system,
name: character.name,
description: character.description,
Expand Down
2 changes: 1 addition & 1 deletion src/server/resource-access/character.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export async function update(charID : string, updateChar : Partial<Character>) :
// Update the database
const db = await getDB();
await db('character')
.update(newCharacter)
.update({ ...newCharacter, updated: db.fn.now() })
.where({ character_id: charID });

const newChar = await get(charID);
Expand Down
8 changes: 6 additions & 2 deletions src/server/resource-access/transforms/character.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ export interface CharacterDBSchema
details : string | null;
note_id : string;
account_id : string;
created : string;
updated : string;
}

// ---------------------------------------------------------------------------------------------------------------------

export function toDB(character : Character) : CharacterDBSchema
export function toDB(character : Character) : Omit<CharacterDBSchema, 'created' | 'updated'>
{
const { id, details, accountID, noteID, ...rest } = character;
const { id, details, accountID, noteID, created, updated, ...rest } = character;
return {
...rest,
character_id: id,
Expand All @@ -49,6 +51,8 @@ export function fromDB(character : CharacterDBSchema) : Character
details: JSON.parse(character.details),
noteID: character.note_id,
accountID: character.account_id,
created: (new Date(character.created)).getTime() / 1000,
updated: (new Date(character.updated)).getTime() / 1000,
};
}

Expand Down

0 comments on commit e25e0b3

Please sign in to comment.