generated from alphane/template
Compare commits
3 Commits
9dfee98b84
...
blog
| Author | SHA1 | Date | |
|---|---|---|---|
| 133d607b2f | |||
| de28a67417 | |||
| 8d9fe8e75d |
@@ -0,0 +1,131 @@
|
|||||||
|
import { isNil } from "lodash"
|
||||||
|
|
||||||
|
import logger from "@/utils/logger"
|
||||||
|
import { BlogPost } from "@/models"
|
||||||
|
import { BlogPostsPolicy } from "@/policies"
|
||||||
|
import { CreateService, DestroyService, UpdateService } from "@/services/blog-posts"
|
||||||
|
import { IndexSerializer, ShowSerializer } from "@/serializers/blog-posts"
|
||||||
|
import BaseController from "@/controllers/base-controller"
|
||||||
|
|
||||||
|
export class BlogPostsController extends BaseController<BlogPost> {
|
||||||
|
async index() {
|
||||||
|
try {
|
||||||
|
const where = this.buildWhere()
|
||||||
|
const scopes = this.buildFilterScopes()
|
||||||
|
const scopedBlogPosts = BlogPostsPolicy.applyScope(scopes, this.currentUser)
|
||||||
|
|
||||||
|
const totalCount = await scopedBlogPosts.count({ where })
|
||||||
|
const blogPosts = await scopedBlogPosts.findAll({
|
||||||
|
where,
|
||||||
|
limit: this.pagination.limit,
|
||||||
|
offset: this.pagination.offset,
|
||||||
|
order: this.buildOrder(),
|
||||||
|
})
|
||||||
|
const serializedBlogPosts = IndexSerializer.perform(blogPosts)
|
||||||
|
return this.response.json({ blogPosts: serializedBlogPosts, totalCount })
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Error fetching blog posts" + error)
|
||||||
|
return this.response.status(400).json({ message: `Error fetching blog posts: ${error}` })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async show() {
|
||||||
|
try {
|
||||||
|
const blogPost = await this.loadBlogPost()
|
||||||
|
if (isNil(blogPost)) {
|
||||||
|
return this.response.status(404).json({ message: "Blog post not found" })
|
||||||
|
}
|
||||||
|
|
||||||
|
const policy = this.buildPolicy(blogPost)
|
||||||
|
if (!policy.show()) {
|
||||||
|
return this.response
|
||||||
|
.status(403)
|
||||||
|
.json({ message: "You are not authorized to view this blog post" })
|
||||||
|
}
|
||||||
|
|
||||||
|
const serializedBlogPost = ShowSerializer.perform(blogPost)
|
||||||
|
return this.response.json({ blogPost: serializedBlogPost, policy })
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Error fetching blog post" + error)
|
||||||
|
return this.response.status(400).json({ message: `Error fetching blog post: ${error}` })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async create() {
|
||||||
|
try {
|
||||||
|
const policy = this.buildPolicy()
|
||||||
|
if (!policy.create()) {
|
||||||
|
return this.response
|
||||||
|
.status(403)
|
||||||
|
.json({ message: "You are not authorized to create blog posts" })
|
||||||
|
}
|
||||||
|
|
||||||
|
const permittedAttributes = policy.permitAttributesForCreate(this.request.body)
|
||||||
|
const blogPost = await CreateService.perform({
|
||||||
|
...permittedAttributes,
|
||||||
|
creatorId: this.currentUser.id,
|
||||||
|
})
|
||||||
|
const serializedBlogPost = ShowSerializer.perform(blogPost)
|
||||||
|
return this.response.status(201).json({ blogPost: serializedBlogPost })
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Error creating blog post" + error)
|
||||||
|
return this.response.status(422).json({ message: `Error creating blog post: ${error}` })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async update() {
|
||||||
|
try {
|
||||||
|
const blogPost = await this.loadBlogPost()
|
||||||
|
if (isNil(blogPost)) {
|
||||||
|
return this.response.status(404).json({ message: "Blog post not found" })
|
||||||
|
}
|
||||||
|
|
||||||
|
const policy = this.buildPolicy(blogPost)
|
||||||
|
if (!policy.update()) {
|
||||||
|
return this.response
|
||||||
|
.status(403)
|
||||||
|
.json({ message: "You are not authorized to update this blog post" })
|
||||||
|
}
|
||||||
|
|
||||||
|
const permittedAttributes = policy.permitAttributes(this.request.body)
|
||||||
|
const updatedBlogPost = await UpdateService.perform(blogPost, permittedAttributes)
|
||||||
|
const serializedBlogPost = ShowSerializer.perform(updatedBlogPost)
|
||||||
|
return this.response.json({ blogPost: serializedBlogPost })
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Error updating blog post" + error)
|
||||||
|
return this.response.status(422).json({ message: `Error updating blog post: ${error}` })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async destroy() {
|
||||||
|
try {
|
||||||
|
const blogPost = await this.loadBlogPost()
|
||||||
|
if (isNil(blogPost)) {
|
||||||
|
return this.response.status(404).json({ message: "Blog post not found" })
|
||||||
|
}
|
||||||
|
|
||||||
|
const policy = this.buildPolicy(blogPost)
|
||||||
|
if (!policy.destroy()) {
|
||||||
|
return this.response
|
||||||
|
.status(403)
|
||||||
|
.json({ message: "You are not authorized to delete this blog post" })
|
||||||
|
}
|
||||||
|
|
||||||
|
await DestroyService.perform(blogPost)
|
||||||
|
return this.response.status(204).send()
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Error deleting blog post" + error)
|
||||||
|
return this.response.status(422).json({ message: `Error deleting blog post: ${error}` })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async loadBlogPost() {
|
||||||
|
return BlogPost.findBySlugOrPk(this.params.blogPostIdOrSlug)
|
||||||
|
}
|
||||||
|
|
||||||
|
private buildPolicy(blogPost: BlogPost = BlogPost.build()) {
|
||||||
|
return new BlogPostsPolicy(this.currentUser, blogPost)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default BlogPostsController
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
// Controllers
|
// Controllers
|
||||||
|
export { BlogPostsController } from "./blog-posts-controller"
|
||||||
export { CurrentUserController } from "./current-user-controller"
|
export { CurrentUserController } from "./current-user-controller"
|
||||||
export { FlashcardDecksController } from "./flashcard-decks-controller"
|
export { FlashcardDecksController } from "./flashcard-decks-controller"
|
||||||
export { FlashcardsController } from "./flashcards-controller"
|
export { FlashcardsController } from "./flashcards-controller"
|
||||||
export { UsersController } from "./users-controller"
|
export { UsersController } from "./users-controller"
|
||||||
|
|
||||||
|
export * as Public from "./public"
|
||||||
|
export * as Users from "./users"
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { Model } from "@sequelize/core"
|
||||||
|
|
||||||
|
import BaseController from "@/controllers/base-controller"
|
||||||
|
|
||||||
|
// Base controller for public, unauthenticated routes: these are mounted
|
||||||
|
// before jwtMiddleware/authorizationMiddleware in router.ts, so no
|
||||||
|
// currentUser is ever available.
|
||||||
|
export class PublicBaseController<TModel extends Model = never> extends BaseController<TModel> {
|
||||||
|
get currentUser(): never {
|
||||||
|
throw new Error("currentUser is not available on public controllers")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PublicBaseController
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import { isNil } from "lodash"
|
||||||
|
|
||||||
|
import logger from "@/utils/logger"
|
||||||
|
import { BlogPost } from "@/models"
|
||||||
|
import { IndexSerializer, ShowSerializer } from "@/serializers/blog-posts"
|
||||||
|
import PublicBaseController from "@/controllers/public/base-controller"
|
||||||
|
|
||||||
|
export class BlogPostsController extends PublicBaseController<BlogPost> {
|
||||||
|
async index() {
|
||||||
|
try {
|
||||||
|
const where = this.buildWhere()
|
||||||
|
const totalCount = await BlogPost.count({ where })
|
||||||
|
const blogPosts = await BlogPost.findAll({
|
||||||
|
where,
|
||||||
|
limit: this.pagination.limit,
|
||||||
|
offset: this.pagination.offset,
|
||||||
|
order: this.buildOrder(),
|
||||||
|
})
|
||||||
|
const serializedBlogPosts = IndexSerializer.perform(blogPosts)
|
||||||
|
return this.response.json({ blogPosts: serializedBlogPosts, totalCount })
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Error fetching blog posts" + error)
|
||||||
|
return this.response.status(400).json({ message: `Error fetching blog posts: ${error}` })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async show() {
|
||||||
|
try {
|
||||||
|
const blogPost = await this.loadBlogPost()
|
||||||
|
if (isNil(blogPost)) {
|
||||||
|
return this.response.status(404).json({ message: "Blog post not found" })
|
||||||
|
}
|
||||||
|
|
||||||
|
const serializedBlogPost = ShowSerializer.perform(blogPost)
|
||||||
|
return this.response.json({ blogPost: serializedBlogPost })
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Error fetching blog post" + error)
|
||||||
|
return this.response.status(400).json({ message: `Error fetching blog post: ${error}` })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async loadBlogPost() {
|
||||||
|
return BlogPost.findBySlugOrPk(this.params.blogPostIdOrSlug)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default BlogPostsController
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
// Public (unauthenticated) controllers
|
||||||
|
export { BlogPostsController } from "./blog-posts-controller"
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export { PreferencesController } from "./preferences-controller"
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import { isNil } from "lodash"
|
||||||
|
|
||||||
|
import logger from "@/utils/logger"
|
||||||
|
|
||||||
|
import { User } from "@/models"
|
||||||
|
import { UpsertService } from "@/services/users/preferences"
|
||||||
|
import { UsersPolicy } from "@/policies/users-policy"
|
||||||
|
import BaseController from "@/controllers/base-controller"
|
||||||
|
|
||||||
|
export class PreferencesController extends BaseController {
|
||||||
|
async update() {
|
||||||
|
try {
|
||||||
|
const user = await this.loadUser()
|
||||||
|
if (isNil(user)) {
|
||||||
|
return this.response.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const policy = this.buildPolicy(user)
|
||||||
|
if (!policy.update()) {
|
||||||
|
return this.response.status(403).json({
|
||||||
|
message: "You are not authorized to update this user",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const key = this.request.params.key as string
|
||||||
|
const { value } = this.request.body
|
||||||
|
await UpsertService.perform(user, key, value)
|
||||||
|
|
||||||
|
return this.response.json({ message: "Successfully upserted user preference" })
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error)
|
||||||
|
return this.response.status(422).json({
|
||||||
|
message: `Error updating user: ${error}`,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async loadUser(): Promise<User | null> {
|
||||||
|
return User.findByPk(this.params.UserId)
|
||||||
|
}
|
||||||
|
|
||||||
|
private buildPolicy(User: User) {
|
||||||
|
return new UsersPolicy(this.currentUser, User)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PreferencesController
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import type { Knex } from "knex"
|
||||||
|
|
||||||
|
export async function up(knex: Knex): Promise<void> {
|
||||||
|
await knex.schema.createTable("blog_posts", function (table) {
|
||||||
|
table.increments("id").notNullable().primary()
|
||||||
|
table.integer("creator_id").notNullable()
|
||||||
|
table.string("title", 255).notNullable()
|
||||||
|
table.string("slug", 255).notNullable()
|
||||||
|
table.text("content").notNullable()
|
||||||
|
table.string("tags", 1024).notNullable().defaultTo("")
|
||||||
|
table.specificType("published_at", "TIMESTAMP WITH TIME ZONE")
|
||||||
|
|
||||||
|
table
|
||||||
|
.specificType("created_at", "TIMESTAMP WITH TIME ZONE")
|
||||||
|
.notNullable()
|
||||||
|
.defaultTo(knex.raw("CURRENT_TIMESTAMP(0)"))
|
||||||
|
table
|
||||||
|
.specificType("updated_at", "TIMESTAMP WITH TIME ZONE")
|
||||||
|
.notNullable()
|
||||||
|
.defaultTo(knex.raw("CURRENT_TIMESTAMP(0)"))
|
||||||
|
table.specificType("deleted_at", "TIMESTAMP WITH TIME ZONE")
|
||||||
|
|
||||||
|
table.foreign("creator_id").references("users.id")
|
||||||
|
table.unique(["slug"], {
|
||||||
|
indexName: "blog_posts_slug_unique",
|
||||||
|
predicate: knex.whereNull("deleted_at"),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(knex: Knex): Promise<void> {
|
||||||
|
await knex.schema.dropTable("blog_posts")
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import type { Knex } from "knex"
|
||||||
|
|
||||||
|
export async function up(knex: Knex): Promise<void> {
|
||||||
|
await knex.schema.createTable("user_preferences", (table) => {
|
||||||
|
table.increments("id").primary()
|
||||||
|
table.integer("user_id").notNullable()
|
||||||
|
table.string("key", 255).notNullable()
|
||||||
|
table.jsonb("value").nullable()
|
||||||
|
table
|
||||||
|
.specificType("created_at", "TIMESTAMP WITH TIME ZONE")
|
||||||
|
.notNullable()
|
||||||
|
.defaultTo(knex.raw("CURRENT_TIMESTAMP(0)"))
|
||||||
|
table
|
||||||
|
.specificType("updated_at", "TIMESTAMP WITH TIME ZONE")
|
||||||
|
.notNullable()
|
||||||
|
.defaultTo(knex.raw("CURRENT_TIMESTAMP(0)"))
|
||||||
|
table.specificType("deleted_at", "TIMESTAMP WITH TIME ZONE")
|
||||||
|
|
||||||
|
table.foreign("user_id").references("users.id")
|
||||||
|
|
||||||
|
table.unique(["user_id", "key"], {
|
||||||
|
indexName: "unique_user_preference_when_deleted_at_is_null",
|
||||||
|
predicate: knex.whereNull("deleted_at"),
|
||||||
|
})
|
||||||
|
|
||||||
|
table.index(["user_id"], "preferences_user_id")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(knex: Knex): Promise<void> {
|
||||||
|
await knex.schema.dropTable("user_preferences")
|
||||||
|
}
|
||||||
@@ -45,25 +45,25 @@ export abstract class BaseModel<
|
|||||||
// identifier: unknown,
|
// identifier: unknown,
|
||||||
// options?: FindByPkOptions<M>,
|
// options?: FindByPkOptions<M>,
|
||||||
// ): Promise<M | null>;
|
// ): Promise<M | null>;
|
||||||
public static async findByIdentifierOrPk<M extends BaseModel>(
|
public static async findBySlugOrPk<M extends BaseModel>(
|
||||||
this: ModelStatic<M>,
|
this: ModelStatic<M>,
|
||||||
identifierOrPk: string | number,
|
slugOrPk: unknown,
|
||||||
options?: Omit<FindOptions<Attributes<M>>, "where">
|
options?: Omit<FindOptions<Attributes<M>>, "where">
|
||||||
): Promise<M | null> {
|
): Promise<M | null> {
|
||||||
if (typeof identifierOrPk === "number" || !isNaN(Number(identifierOrPk))) {
|
if (typeof slugOrPk === "number" || !isNaN(Number(slugOrPk))) {
|
||||||
const primaryKey = identifierOrPk
|
const primaryKey = slugOrPk
|
||||||
return this.findByPk(primaryKey, options)
|
return this.findByPk(primaryKey, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
const identifier = identifierOrPk
|
const slug = slugOrPk
|
||||||
if (!("identifier" in this.getAttributes())) {
|
if (!("slug" in this.getAttributes())) {
|
||||||
throw new Error(`${this.name} does not have a 'identifier' attribute.`)
|
throw new Error(`${this.name} does not have a 'slug' attribute.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.findOne({
|
return this.findOne({
|
||||||
...options,
|
...options,
|
||||||
// @ts-expect-error - We know that the model has a slug attribute, and are ignoring the TS error
|
// @ts-expect-error - We know that the model has a slug attribute, and are ignoring the TS error
|
||||||
where: { identifier },
|
where: { slug },
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
import { type CreationOptional, DataTypes, InferAttributes, InferCreationAttributes, sql } from "@sequelize/core"
|
||||||
|
import { Attribute, AutoIncrement, Default, Index, NotNull, PrimaryKey } from "@sequelize/core/decorators-legacy"
|
||||||
|
import { isNil } from "lodash"
|
||||||
|
|
||||||
|
import BaseModel from "@/models/base-model"
|
||||||
|
|
||||||
|
export class BlogPost extends BaseModel<InferAttributes<BlogPost>, InferCreationAttributes<BlogPost>> {
|
||||||
|
@Attribute(DataTypes.INTEGER)
|
||||||
|
@PrimaryKey
|
||||||
|
@AutoIncrement
|
||||||
|
declare id: CreationOptional<number>
|
||||||
|
|
||||||
|
@Attribute(DataTypes.INTEGER)
|
||||||
|
@NotNull
|
||||||
|
declare creatorId: number
|
||||||
|
|
||||||
|
@Attribute(DataTypes.STRING(255))
|
||||||
|
@NotNull
|
||||||
|
declare title: string
|
||||||
|
|
||||||
|
@Attribute(DataTypes.STRING(255))
|
||||||
|
@NotNull
|
||||||
|
@Index({ unique: true })
|
||||||
|
declare slug: string
|
||||||
|
|
||||||
|
@Attribute(DataTypes.TEXT)
|
||||||
|
@NotNull
|
||||||
|
declare content: string
|
||||||
|
|
||||||
|
@Attribute({
|
||||||
|
type: DataTypes.STRING(1024),
|
||||||
|
get() {
|
||||||
|
const tags = this.getDataValue("tags")
|
||||||
|
if (isNil(tags) || tags === "") {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
return tags.split(",")
|
||||||
|
},
|
||||||
|
set(value: string[]) {
|
||||||
|
this.setDataValue("tags", value.join(","))
|
||||||
|
},
|
||||||
|
})
|
||||||
|
@NotNull
|
||||||
|
@Default("")
|
||||||
|
declare tags: CreationOptional<string[]>
|
||||||
|
|
||||||
|
@Attribute(DataTypes.DATE(0))
|
||||||
|
declare publishedAt: Date | null
|
||||||
|
|
||||||
|
@Attribute(DataTypes.DATE(0))
|
||||||
|
@NotNull
|
||||||
|
@Default(sql.literal("CURRENT_TIMESTAMP"))
|
||||||
|
declare createdAt: CreationOptional<Date>
|
||||||
|
|
||||||
|
@Attribute(DataTypes.DATE(0))
|
||||||
|
@NotNull
|
||||||
|
@Default(sql.literal("CURRENT_TIMESTAMP"))
|
||||||
|
declare updatedAt: CreationOptional<Date>
|
||||||
|
|
||||||
|
@Attribute(DataTypes.DATE(0))
|
||||||
|
declare deletedAt: Date | null
|
||||||
|
|
||||||
|
// Scopes
|
||||||
|
static establishScopes(): void {
|
||||||
|
this.addSearchScope(["title", "content"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default BlogPost
|
||||||
+6
-11
@@ -1,27 +1,22 @@
|
|||||||
import db from "@/db/db-client"
|
import db from "@/db/db-client"
|
||||||
|
|
||||||
// Models
|
// Models
|
||||||
|
import BlogPost from "@/models/blog-post"
|
||||||
import Flashcard from "@/models/flashcard"
|
import Flashcard from "@/models/flashcard"
|
||||||
import FlashcardDeck from "@/models/flashcard-deck"
|
import FlashcardDeck from "@/models/flashcard-deck"
|
||||||
import User, { UserRoles } from "@/models/user"
|
import User, { UserRoles } from "@/models/user"
|
||||||
|
import UserPreference from "@/models/user-preference"
|
||||||
|
|
||||||
db.addModels([
|
db.addModels([BlogPost, Flashcard, FlashcardDeck, User, UserPreference])
|
||||||
Flashcard,
|
|
||||||
FlashcardDeck,
|
|
||||||
User,
|
|
||||||
])
|
|
||||||
|
|
||||||
// Lazy load scopes
|
// Lazy load scopes
|
||||||
|
BlogPost.establishScopes()
|
||||||
Flashcard.establishScopes()
|
Flashcard.establishScopes()
|
||||||
FlashcardDeck.establishScopes()
|
FlashcardDeck.establishScopes()
|
||||||
User.establishScopes()
|
User.establishScopes()
|
||||||
|
UserPreference.establishScopes()
|
||||||
|
|
||||||
export {
|
export { BlogPost, Flashcard, FlashcardDeck, User, UserRoles, UserPreference }
|
||||||
Flashcard,
|
|
||||||
FlashcardDeck,
|
|
||||||
User,
|
|
||||||
UserRoles,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Special db instance will all models loaded
|
// Special db instance will all models loaded
|
||||||
export default db
|
export default db
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { PreferenceKeys, PreferenceValueMap } from "@/models/user-preference"
|
||||||
|
import { isFiniteNumber } from "@/utils/validators"
|
||||||
|
|
||||||
|
export const preferenceValueValidators: {
|
||||||
|
[K in PreferenceKeys]: (value: unknown) => value is PreferenceValueMap[K]
|
||||||
|
} = {
|
||||||
|
[PreferenceKeys.FLASHCARDS_DAY_STREAK]: isFiniteNumber,
|
||||||
|
}
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
import {
|
||||||
|
type CreationOptional,
|
||||||
|
type ForeignKey,
|
||||||
|
DataTypes,
|
||||||
|
InferAttributes,
|
||||||
|
InferCreationAttributes,
|
||||||
|
type NonAttribute,
|
||||||
|
sql,
|
||||||
|
} from "@sequelize/core"
|
||||||
|
import {
|
||||||
|
Attribute,
|
||||||
|
AutoIncrement,
|
||||||
|
BelongsTo,
|
||||||
|
Default,
|
||||||
|
NotNull,
|
||||||
|
PrimaryKey,
|
||||||
|
Table,
|
||||||
|
ValidateAttribute,
|
||||||
|
} from "@sequelize/core/decorators-legacy"
|
||||||
|
|
||||||
|
import BaseModel from "@/models/base-model"
|
||||||
|
import { User } from "@/models/user"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keep in sync with web/src/api/users/preferences-api.ts and
|
||||||
|
* api/src/models/user-preference-value-validators.ts
|
||||||
|
*/
|
||||||
|
export enum PreferenceKeys {
|
||||||
|
FLASHCARDS_DAY_STREAK = "flashcards.day_streak",
|
||||||
|
}
|
||||||
|
|
||||||
|
export type PreferenceValueMap = {
|
||||||
|
[PreferenceKeys.FLASHCARDS_DAY_STREAK]: number
|
||||||
|
}
|
||||||
|
|
||||||
|
@Table({ tableName: "user_preferences", timestamps: true, paranoid: true })
|
||||||
|
export class UserPreference extends BaseModel<
|
||||||
|
InferAttributes<UserPreference>,
|
||||||
|
InferCreationAttributes<UserPreference>
|
||||||
|
> {
|
||||||
|
static readonly Keys = PreferenceKeys
|
||||||
|
|
||||||
|
@Attribute(DataTypes.INTEGER)
|
||||||
|
@PrimaryKey
|
||||||
|
@AutoIncrement
|
||||||
|
declare id: CreationOptional<number>
|
||||||
|
|
||||||
|
@Attribute(DataTypes.INTEGER)
|
||||||
|
@NotNull
|
||||||
|
declare userId: ForeignKey<User["id"]>
|
||||||
|
|
||||||
|
@Attribute(DataTypes.STRING(255))
|
||||||
|
@NotNull
|
||||||
|
@ValidateAttribute({
|
||||||
|
isIn: {
|
||||||
|
args: [Object.values(PreferenceKeys)],
|
||||||
|
msg: `Key must be one of ${Object.values(PreferenceKeys).join(", ")}`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
declare key: PreferenceKeys
|
||||||
|
|
||||||
|
@Attribute(DataTypes.JSONB)
|
||||||
|
declare value: unknown | null
|
||||||
|
|
||||||
|
@Attribute(DataTypes.DATE(0))
|
||||||
|
@NotNull
|
||||||
|
@Default(sql.literal("CURRENT_TIMESTAMP"))
|
||||||
|
declare createdAt: CreationOptional<Date>
|
||||||
|
|
||||||
|
@Attribute(DataTypes.DATE(0))
|
||||||
|
@NotNull
|
||||||
|
@Default(sql.literal("CURRENT_TIMESTAMP"))
|
||||||
|
declare updatedAt: CreationOptional<Date>
|
||||||
|
|
||||||
|
@Attribute(DataTypes.DATE(0))
|
||||||
|
declare deletedAt: Date | null
|
||||||
|
|
||||||
|
// Associations
|
||||||
|
@BelongsTo(() => User, {
|
||||||
|
foreignKey: { name: "userId", allowNull: false },
|
||||||
|
inverse: {
|
||||||
|
as: "userPreferences",
|
||||||
|
type: "hasMany",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
declare user?: NonAttribute<User>
|
||||||
|
|
||||||
|
// Scopes
|
||||||
|
static establishScopes(): void {}
|
||||||
|
|
||||||
|
static async setValue<T extends PreferenceKeys>(
|
||||||
|
userId: number,
|
||||||
|
key: T,
|
||||||
|
value: PreferenceValueMap[T]
|
||||||
|
) {
|
||||||
|
const existing = await UserPreference.findOne({
|
||||||
|
where: { userId, key },
|
||||||
|
})
|
||||||
|
|
||||||
|
if (existing) {
|
||||||
|
return existing.update({ value })
|
||||||
|
}
|
||||||
|
|
||||||
|
return UserPreference.create({ userId, key, value })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default UserPreference
|
||||||
+13
-1
@@ -10,6 +10,7 @@ import {
|
|||||||
Attribute,
|
Attribute,
|
||||||
AutoIncrement,
|
AutoIncrement,
|
||||||
Default,
|
Default,
|
||||||
|
HasMany,
|
||||||
Index,
|
Index,
|
||||||
NotNull,
|
NotNull,
|
||||||
PrimaryKey,
|
PrimaryKey,
|
||||||
@@ -18,6 +19,7 @@ import {
|
|||||||
import { isArray, isNil } from "lodash"
|
import { isArray, isNil } from "lodash"
|
||||||
|
|
||||||
import BaseModel from "@/models/base-model"
|
import BaseModel from "@/models/base-model"
|
||||||
|
import UserPreference from "@/models/user-preference"
|
||||||
|
|
||||||
/** Keep in sync with web/src/api/users-api.ts */
|
/** Keep in sync with web/src/api/users-api.ts */
|
||||||
export enum UserRoles {
|
export enum UserRoles {
|
||||||
@@ -98,12 +100,22 @@ export class User extends BaseModel<InferAttributes<User>, InferCreationAttribut
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Associations
|
// Associations
|
||||||
|
@HasMany(() => UserPreference, {
|
||||||
|
foreignKey: {
|
||||||
|
name: "userId",
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
inverse: "user",
|
||||||
|
})
|
||||||
|
declare userPreferences?: NonAttribute<UserPreference[]>
|
||||||
|
|
||||||
// Scopes
|
// Scopes
|
||||||
static establishScopes(): void {
|
static establishScopes(): void {
|
||||||
this.addSearchScope(["firstName", "lastName", "displayName", "email"])
|
this.addSearchScope(["firstName", "lastName", "displayName", "email"])
|
||||||
|
|
||||||
this.addScope("asCurrentUser", {})
|
this.addScope("asCurrentUser", {
|
||||||
|
include: ["userPreferences"],
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
import { Attributes, FindOptions } from "@sequelize/core"
|
||||||
|
|
||||||
|
import { BlogPost, User } from "@/models"
|
||||||
|
import { ALL_RECORDS_SCOPE, PolicyFactory } from "@/policies/base-policy"
|
||||||
|
import { Path } from "@/utils/deep-pick"
|
||||||
|
|
||||||
|
export class BlogPostsPolicy extends PolicyFactory(BlogPost) {
|
||||||
|
show(): boolean {
|
||||||
|
if (this.user.isSystemAdmin) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
create(): boolean {
|
||||||
|
if (this.user.isSystemAdmin) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
update(): boolean {
|
||||||
|
if (this.user.isSystemAdmin) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
destroy(): boolean {
|
||||||
|
if (this.user.isSystemAdmin) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
permittedAttributes(): Path[] {
|
||||||
|
return ["title", "slug", "content", "tags", "publishedAt"] as (keyof Attributes<BlogPost>)[]
|
||||||
|
}
|
||||||
|
|
||||||
|
permittedAttributesForCreate(): Path[] {
|
||||||
|
return [...this.permittedAttributes()]
|
||||||
|
}
|
||||||
|
|
||||||
|
permittedAttributesForUpdate(): Path[] {
|
||||||
|
return [...this.permittedAttributes()]
|
||||||
|
}
|
||||||
|
|
||||||
|
static policyScope(_user: User): FindOptions<Attributes<BlogPost>> {
|
||||||
|
return ALL_RECORDS_SCOPE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default BlogPostsPolicy
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
// Policy Bundles
|
// Policy Bundles
|
||||||
export { type BaseScopeOptions } from "./base-policy"
|
export { type BaseScopeOptions } from "./base-policy"
|
||||||
|
export { BlogPostsPolicy } from "./blog-posts-policy"
|
||||||
export { FlashcardDecksPolicy } from "./flashcard-decks-policy"
|
export { FlashcardDecksPolicy } from "./flashcard-decks-policy"
|
||||||
export { FlashcardsPolicy } from "./flashcards-policy"
|
export { FlashcardsPolicy } from "./flashcards-policy"
|
||||||
export { UsersPolicy } from "./users-policy"
|
export { UsersPolicy } from "./users-policy"
|
||||||
|
|||||||
+20
-5
@@ -16,7 +16,15 @@ import { logger } from "@/utils/logger"
|
|||||||
|
|
||||||
import { jwtMiddleware, authorizationMiddleware } from "@/middlewares"
|
import { jwtMiddleware, authorizationMiddleware } from "@/middlewares"
|
||||||
|
|
||||||
import { CurrentUserController, FlashcardDecksController, FlashcardsController, UsersController } from "@/controllers"
|
import {
|
||||||
|
BlogPostsController,
|
||||||
|
CurrentUserController,
|
||||||
|
FlashcardDecksController,
|
||||||
|
FlashcardsController,
|
||||||
|
Public,
|
||||||
|
Users,
|
||||||
|
UsersController,
|
||||||
|
} from "@/controllers"
|
||||||
|
|
||||||
export const router = Router()
|
export const router = Router()
|
||||||
|
|
||||||
@@ -29,6 +37,8 @@ router.route("/_status").get((_req: Request, res: Response) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// external (public) routes - no authentication required
|
// external (public) routes - no authentication required
|
||||||
|
router.route("/api/public/blog-posts").get(Public.BlogPostsController.index)
|
||||||
|
router.route("/api/public/blog-posts/:blogPostIdOrSlug").get(Public.BlogPostsController.show)
|
||||||
|
|
||||||
// api routes
|
// api routes
|
||||||
router.use("/api", jwtMiddleware, authorizationMiddleware)
|
router.use("/api", jwtMiddleware, authorizationMiddleware)
|
||||||
@@ -41,6 +51,7 @@ router
|
|||||||
.get(UsersController.show)
|
.get(UsersController.show)
|
||||||
.patch(UsersController.update)
|
.patch(UsersController.update)
|
||||||
.delete(UsersController.destroy)
|
.delete(UsersController.destroy)
|
||||||
|
router.route("/api/users/:userId/preferences/:key").patch(Users.PreferencesController.update)
|
||||||
|
|
||||||
router
|
router
|
||||||
.route("/api/flashcard-decks")
|
.route("/api/flashcard-decks")
|
||||||
@@ -52,16 +63,20 @@ router
|
|||||||
.patch(FlashcardDecksController.update)
|
.patch(FlashcardDecksController.update)
|
||||||
.delete(FlashcardDecksController.destroy)
|
.delete(FlashcardDecksController.destroy)
|
||||||
|
|
||||||
router
|
router.route("/api/flashcards").get(FlashcardsController.index).post(FlashcardsController.create)
|
||||||
.route("/api/flashcards")
|
|
||||||
.get(FlashcardsController.index)
|
|
||||||
.post(FlashcardsController.create)
|
|
||||||
router
|
router
|
||||||
.route("/api/flashcards/:flashcardId")
|
.route("/api/flashcards/:flashcardId")
|
||||||
.get(FlashcardsController.show)
|
.get(FlashcardsController.show)
|
||||||
.patch(FlashcardsController.update)
|
.patch(FlashcardsController.update)
|
||||||
.delete(FlashcardsController.destroy)
|
.delete(FlashcardsController.destroy)
|
||||||
|
|
||||||
|
router.route("/api/blog-posts").get(BlogPostsController.index).post(BlogPostsController.create)
|
||||||
|
router
|
||||||
|
.route("/api/blog-posts/:blogPostIdOrSlug")
|
||||||
|
.get(BlogPostsController.show)
|
||||||
|
.patch(BlogPostsController.update)
|
||||||
|
.delete(BlogPostsController.destroy)
|
||||||
|
|
||||||
// if no other routes match, return a 404
|
// if no other routes match, return a 404
|
||||||
router.use("/api", (req: Request, res: Response) => {
|
router.use("/api", (req: Request, res: Response) => {
|
||||||
return res.status(404).json({ message: "Not Found", url: req.path })
|
return res.status(404).json({ message: "Not Found", url: req.path })
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { pick } from "lodash"
|
||||||
|
|
||||||
|
import { BlogPost } from "@/models"
|
||||||
|
import BaseSerializer from "@/serializers/base-serializer"
|
||||||
|
|
||||||
|
export type BlogPostIndexView = Pick<
|
||||||
|
BlogPost,
|
||||||
|
"id" | "creatorId" | "title" | "slug" | "tags" | "publishedAt" | "createdAt" | "updatedAt"
|
||||||
|
>
|
||||||
|
|
||||||
|
export class IndexSerializer extends BaseSerializer<BlogPost> {
|
||||||
|
perform(): BlogPostIndexView {
|
||||||
|
return pick(this.record, [
|
||||||
|
"id",
|
||||||
|
"creatorId",
|
||||||
|
"title",
|
||||||
|
"slug",
|
||||||
|
"tags",
|
||||||
|
"publishedAt",
|
||||||
|
"createdAt",
|
||||||
|
"updatedAt",
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default IndexSerializer
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export { IndexSerializer } from "./index-serializer"
|
||||||
|
export { ShowSerializer } from "./show-serializer"
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import { pick } from "lodash"
|
||||||
|
|
||||||
|
import { BlogPost } from "@/models"
|
||||||
|
import BaseSerializer from "@/serializers/base-serializer"
|
||||||
|
|
||||||
|
export type BlogPostShowView = Pick<
|
||||||
|
BlogPost,
|
||||||
|
| "id"
|
||||||
|
| "creatorId"
|
||||||
|
| "title"
|
||||||
|
| "slug"
|
||||||
|
| "content"
|
||||||
|
| "tags"
|
||||||
|
| "publishedAt"
|
||||||
|
| "createdAt"
|
||||||
|
| "updatedAt"
|
||||||
|
>
|
||||||
|
|
||||||
|
export class ShowSerializer extends BaseSerializer<BlogPost> {
|
||||||
|
perform(): BlogPostShowView {
|
||||||
|
return pick(this.record, [
|
||||||
|
"id",
|
||||||
|
"creatorId",
|
||||||
|
"title",
|
||||||
|
"slug",
|
||||||
|
"content",
|
||||||
|
"tags",
|
||||||
|
"publishedAt",
|
||||||
|
"createdAt",
|
||||||
|
"updatedAt",
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ShowSerializer
|
||||||
@@ -1,15 +1,27 @@
|
|||||||
import { pick } from "lodash"
|
import { isUndefined, pick } from "lodash"
|
||||||
|
|
||||||
import { User } from "@/models"
|
import { User, UserPreference } from "@/models"
|
||||||
import BaseSerializer from "@/serializers/base-serializer"
|
import BaseSerializer from "@/serializers/base-serializer"
|
||||||
|
import {
|
||||||
|
ShowSerializer as UserPreferenceShowSerializer,
|
||||||
|
type UserPreferenceShowView,
|
||||||
|
} from "@/serializers/user-preferences/show-serializer"
|
||||||
|
|
||||||
export type UserShowView = Pick<
|
export type UserShowView = Pick<
|
||||||
User,
|
User,
|
||||||
"id" | "email" | "firstName" | "lastName" | "displayName" | "roles" | "createdAt" | "updatedAt"
|
"id" | "email" | "firstName" | "lastName" | "displayName" | "roles" | "createdAt" | "updatedAt"
|
||||||
>
|
> & {
|
||||||
|
preferences?: UserPreferenceShowView[]
|
||||||
|
}
|
||||||
|
|
||||||
export class ShowSerializer extends BaseSerializer<User> {
|
export class ShowSerializer extends BaseSerializer<User> {
|
||||||
perform(): UserShowView {
|
perform(): UserShowView {
|
||||||
|
const { userPreferences } = this.record
|
||||||
|
|
||||||
|
const serializedUserPreferences = isUndefined(userPreferences)
|
||||||
|
? undefined
|
||||||
|
: this.serializeUserPreferences(userPreferences)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...pick(this.record, [
|
...pick(this.record, [
|
||||||
"id",
|
"id",
|
||||||
@@ -21,8 +33,15 @@ export class ShowSerializer extends BaseSerializer<User> {
|
|||||||
"createdAt",
|
"createdAt",
|
||||||
"updatedAt",
|
"updatedAt",
|
||||||
]),
|
]),
|
||||||
|
preferences: serializedUserPreferences,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private serializeUserPreferences(userPreferences: UserPreference[]) {
|
||||||
|
return userPreferences.map((userPreference) =>
|
||||||
|
UserPreferenceShowSerializer.perform(userPreference)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ShowSerializer
|
export default ShowSerializer
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// Bundled exports
|
// Bundled exports
|
||||||
|
export * as BlogPosts from "./blog-posts"
|
||||||
export * as FlashcardDecks from "./flashcard-decks"
|
export * as FlashcardDecks from "./flashcard-decks"
|
||||||
export * as Flashcards from "./flashcards"
|
export * as Flashcards from "./flashcards"
|
||||||
export * as Users from "./users"
|
export * as Users from "./users"
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
export { ShowSerializer } from "./show-serializer"
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { pick } from "lodash"
|
||||||
|
|
||||||
|
import { UserPreference } from "@/models"
|
||||||
|
import BaseSerializer from "@/serializers/base-serializer"
|
||||||
|
|
||||||
|
export type UserPreferenceShowView = Pick<UserPreference, "key" | "value">
|
||||||
|
|
||||||
|
export class ShowSerializer extends BaseSerializer<UserPreference> {
|
||||||
|
perform(): UserPreferenceShowView {
|
||||||
|
return {
|
||||||
|
...pick(this.record, ["key", "value"]),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ShowSerializer
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import { CreationAttributes } from "@sequelize/core"
|
||||||
|
import { isNil } from "lodash"
|
||||||
|
|
||||||
|
import { BlogPost } from "@/models"
|
||||||
|
import BaseService from "@/services/base-service"
|
||||||
|
|
||||||
|
export type BlogPostCreationAttributes = Partial<CreationAttributes<BlogPost>>
|
||||||
|
|
||||||
|
export class CreateService extends BaseService {
|
||||||
|
constructor(private attributes: BlogPostCreationAttributes) {
|
||||||
|
super()
|
||||||
|
}
|
||||||
|
|
||||||
|
async perform(): Promise<BlogPost> {
|
||||||
|
const { creatorId, title, slug, content, ...optionalAttributes } = this.attributes
|
||||||
|
|
||||||
|
if (isNil(creatorId)) {
|
||||||
|
throw new Error("Creator is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNil(title)) {
|
||||||
|
throw new Error("Title is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNil(slug)) {
|
||||||
|
throw new Error("Slug is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNil(content)) {
|
||||||
|
throw new Error("Content is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
return BlogPost.create({
|
||||||
|
...optionalAttributes,
|
||||||
|
creatorId,
|
||||||
|
title,
|
||||||
|
slug,
|
||||||
|
content,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CreateService
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { BlogPost } from "@/models"
|
||||||
|
import BaseService from "@/services/base-service"
|
||||||
|
|
||||||
|
export class DestroyService extends BaseService {
|
||||||
|
constructor(private blogPost: BlogPost) {
|
||||||
|
super()
|
||||||
|
}
|
||||||
|
|
||||||
|
async perform(): Promise<void> {
|
||||||
|
return this.blogPost.destroy()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DestroyService
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export { CreateService } from "./create-service"
|
||||||
|
export { UpdateService } from "./update-service"
|
||||||
|
export { DestroyService } from "./destroy-service"
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { Attributes } from "@sequelize/core"
|
||||||
|
|
||||||
|
import { BlogPost } from "@/models"
|
||||||
|
import BaseService from "@/services/base-service"
|
||||||
|
|
||||||
|
export type BlogPostUpdateAttributes = Partial<Attributes<BlogPost>>
|
||||||
|
|
||||||
|
export class UpdateService extends BaseService {
|
||||||
|
constructor(
|
||||||
|
private blogPost: BlogPost,
|
||||||
|
private attributes: BlogPostUpdateAttributes
|
||||||
|
) {
|
||||||
|
super()
|
||||||
|
}
|
||||||
|
|
||||||
|
async perform(): Promise<BlogPost> {
|
||||||
|
return this.blogPost.update(this.attributes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default UpdateService
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
export * as BlogPosts from "./blog-posts"
|
||||||
export * as FlashcardDecks from "./flashcard-decks"
|
export * as FlashcardDecks from "./flashcard-decks"
|
||||||
export * as Flashcards from "./flashcards"
|
export * as Flashcards from "./flashcards"
|
||||||
export * as Users from "./users"
|
export * as Users from "./users"
|
||||||
|
|||||||
@@ -5,3 +5,5 @@ export { DestroyService } from "./destroy-service"
|
|||||||
// Special Services
|
// Special Services
|
||||||
export { EnsureFromAuth0TokenService } from "./ensure-from-auth0-token-service"
|
export { EnsureFromAuth0TokenService } from "./ensure-from-auth0-token-service"
|
||||||
export { FindFromAuth0TokenService } from "./find-from-auth0-token-service"
|
export { FindFromAuth0TokenService } from "./find-from-auth0-token-service"
|
||||||
|
|
||||||
|
export * as Preferences from "./preferences"
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
export { UpsertService } from "./upsert-service"
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import { User } from "@/models"
|
||||||
|
import UserPreference, { PreferenceKeys } from "@/models/user-preference"
|
||||||
|
import { preferenceValueValidators } from "@/models/user-preference-value-validators"
|
||||||
|
import BaseService from "@/services/base-service"
|
||||||
|
|
||||||
|
export class UpsertService extends BaseService {
|
||||||
|
constructor(
|
||||||
|
private user: User,
|
||||||
|
private key: string,
|
||||||
|
private value: unknown | null
|
||||||
|
) {
|
||||||
|
super()
|
||||||
|
}
|
||||||
|
|
||||||
|
async perform() {
|
||||||
|
const isPreferenceKey = Object.values(PreferenceKeys).includes(this.key as PreferenceKeys)
|
||||||
|
if (!isPreferenceKey) {
|
||||||
|
throw new Error("Provided key is not a valid PreferenceKey")
|
||||||
|
}
|
||||||
|
|
||||||
|
const key = this.key as PreferenceKeys
|
||||||
|
|
||||||
|
const validator = preferenceValueValidators[key]
|
||||||
|
if (!validator(this.value)) {
|
||||||
|
throw new Error("Invalid value for preference key")
|
||||||
|
}
|
||||||
|
|
||||||
|
return UserPreference.setValue(this.user.id, key, this.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default UpsertService
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export { isFiniteNumber } from "./is-finite-number"
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { isNumber } from "lodash"
|
||||||
|
|
||||||
|
export function isFiniteNumber(value: unknown): value is number {
|
||||||
|
return isNumber(value) && isFinite(value)
|
||||||
|
}
|
||||||
+1
-1
@@ -11,7 +11,7 @@
|
|||||||
crossorigin
|
crossorigin
|
||||||
/>
|
/>
|
||||||
<link
|
<link
|
||||||
href="https://fonts.googleapis.com/css2?family=Audiowide&family=Overpass:ital,wght@0,100..900;1,100..900&display=swap"
|
href="https://fonts.googleapis.com/css2?family=Audiowide&family=Overpass:ital,wght@0,100..900;1,100..900&family=Source+Serif+4:opsz,wght@8..60,400;8..60,600;8..60,700&display=swap"
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
import http from "@/api/http-client"
|
||||||
|
import { type FiltersOptions, type ModelOrder, type WhereOptions } from "@/api/base-api"
|
||||||
|
|
||||||
|
export type BlogPost = {
|
||||||
|
id: number
|
||||||
|
creatorId: number
|
||||||
|
title: string
|
||||||
|
slug: string
|
||||||
|
content: string
|
||||||
|
tags: string[]
|
||||||
|
publishedAt: string | null
|
||||||
|
createdAt: string
|
||||||
|
updatedAt: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type BlogPostIndexView = Omit<BlogPost, "content">
|
||||||
|
|
||||||
|
export type BlogPostWhereOptions = WhereOptions<BlogPost, "creatorId">
|
||||||
|
|
||||||
|
export type BlogPostFiltersOptions = FiltersOptions<{
|
||||||
|
search: string | string[]
|
||||||
|
}>
|
||||||
|
|
||||||
|
export type BlogPostQueryOptions = {
|
||||||
|
where?: BlogPostWhereOptions
|
||||||
|
filters?: BlogPostFiltersOptions
|
||||||
|
order?: ModelOrder[]
|
||||||
|
page?: number
|
||||||
|
perPage?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export const blogPostsApi = {
|
||||||
|
async list(params: BlogPostQueryOptions = {}): Promise<{
|
||||||
|
blogPosts: BlogPostIndexView[]
|
||||||
|
totalCount: number
|
||||||
|
}> {
|
||||||
|
const { data } = await http.get("/api/blog-posts", { params })
|
||||||
|
return data
|
||||||
|
},
|
||||||
|
async get(blogPostIdOrSlug: number | string): Promise<{
|
||||||
|
blogPost: BlogPost
|
||||||
|
}> {
|
||||||
|
const { data } = await http.get(`/api/blog-posts/${blogPostIdOrSlug}`)
|
||||||
|
return data
|
||||||
|
},
|
||||||
|
async create(attributes: Partial<BlogPost>): Promise<{
|
||||||
|
blogPost: BlogPost
|
||||||
|
}> {
|
||||||
|
const { data } = await http.post("/api/blog-posts", attributes)
|
||||||
|
return data
|
||||||
|
},
|
||||||
|
async update(
|
||||||
|
blogPostIdOrSlug: number | string,
|
||||||
|
attributes: Partial<BlogPost>
|
||||||
|
): Promise<{
|
||||||
|
blogPost: BlogPost
|
||||||
|
}> {
|
||||||
|
const { data } = await http.patch(`/api/blog-posts/${blogPostIdOrSlug}`, attributes)
|
||||||
|
return data
|
||||||
|
},
|
||||||
|
async delete(blogPostIdOrSlug: number | string): Promise<void> {
|
||||||
|
const { data } = await http.delete(`/api/blog-posts/${blogPostIdOrSlug}`)
|
||||||
|
return data
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
export default blogPostsApi
|
||||||
@@ -2,13 +2,16 @@ import http from "@/api/http-client"
|
|||||||
|
|
||||||
import { type Policy } from "@/api/base-api"
|
import { type Policy } from "@/api/base-api"
|
||||||
import { UserRoles, type User } from "@/api/users-api"
|
import { UserRoles, type User } from "@/api/users-api"
|
||||||
|
import { PreferenceAsShow } from "@/api/users/preferences-api"
|
||||||
|
|
||||||
export { UserRoles }
|
export { UserRoles }
|
||||||
|
|
||||||
export type UserAsShow = Pick<
|
export type UserAsShow = Pick<
|
||||||
User,
|
User,
|
||||||
"id" | "email" | "firstName" | "lastName" | "displayName" | "roles" | "createdAt" | "updatedAt"
|
"id" | "email" | "firstName" | "lastName" | "displayName" | "roles" | "createdAt" | "updatedAt"
|
||||||
>
|
> & {
|
||||||
|
preferences?: PreferenceAsShow[]
|
||||||
|
}
|
||||||
|
|
||||||
export const currentUserApi = {
|
export const currentUserApi = {
|
||||||
async get(): Promise<{
|
async get(): Promise<{
|
||||||
|
|||||||
@@ -21,8 +21,10 @@ export const httpClient = axios.create({
|
|||||||
})
|
})
|
||||||
|
|
||||||
httpClient.interceptors.request.use(async (config) => {
|
httpClient.interceptors.request.use(async (config) => {
|
||||||
// Only add the Authorization header to requests that start with "/api"
|
// Only add the Authorization header to authenticated "/api" requests.
|
||||||
if (config.url?.startsWith("/api")) {
|
// "/api/public" routes are mounted ahead of the auth middleware and must
|
||||||
|
// stay reachable for anonymous visitors, so skip attaching a token there.
|
||||||
|
if (config.url?.startsWith("/api") && !config.url?.startsWith("/api/public")) {
|
||||||
const accessToken = await auth0.getAccessTokenSilently()
|
const accessToken = await auth0.getAccessTokenSilently()
|
||||||
config.headers["Authorization"] = `Bearer ${accessToken}`
|
config.headers["Authorization"] = `Bearer ${accessToken}`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import http from "@/api/http-client"
|
||||||
|
import { type FiltersOptions, type ModelOrder, type WhereOptions } from "@/api/base-api"
|
||||||
|
|
||||||
|
export type PublicBlogPost = {
|
||||||
|
id: number
|
||||||
|
creatorId: number
|
||||||
|
title: string
|
||||||
|
slug: string
|
||||||
|
content: string
|
||||||
|
tags: string[]
|
||||||
|
publishedAt: string | null
|
||||||
|
createdAt: string
|
||||||
|
updatedAt: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type PublicBlogPostIndexView = Omit<PublicBlogPost, "content">
|
||||||
|
|
||||||
|
export type PublicBlogPostWhereOptions = WhereOptions<PublicBlogPost, "creatorId">
|
||||||
|
|
||||||
|
export type PublicBlogPostFiltersOptions = FiltersOptions<{
|
||||||
|
search: string | string[]
|
||||||
|
}>
|
||||||
|
|
||||||
|
export type PublicBlogPostQueryOptions = {
|
||||||
|
where?: PublicBlogPostWhereOptions
|
||||||
|
filters?: PublicBlogPostFiltersOptions
|
||||||
|
order?: ModelOrder[]
|
||||||
|
page?: number
|
||||||
|
perPage?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export const publicBlogPostsApi = {
|
||||||
|
async list(params: PublicBlogPostQueryOptions = {}): Promise<{
|
||||||
|
blogPosts: PublicBlogPostIndexView[]
|
||||||
|
totalCount: number
|
||||||
|
}> {
|
||||||
|
const { data } = await http.get("/api/public/blog-posts", { params })
|
||||||
|
return data
|
||||||
|
},
|
||||||
|
async get(blogPostIdOrSlug: number | string): Promise<{
|
||||||
|
blogPost: PublicBlogPost
|
||||||
|
}> {
|
||||||
|
const { data } = await http.get(`/api/public/blog-posts/${blogPostIdOrSlug}`)
|
||||||
|
return data
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
export default publicBlogPostsApi
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export { publicBlogPostsApi } from "./blog-posts-api"
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export { preferencesApi } from "./preferences-api"
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import http from "@/api/http-client"
|
||||||
|
|
||||||
|
/** Keep in sync with api/src/models/user-preference.ts */
|
||||||
|
export enum PreferenceKeys {
|
||||||
|
FLASHCARDS_DAY_STREAK = "flashcards.day_streak",
|
||||||
|
}
|
||||||
|
|
||||||
|
export type PreferenceValueMap = {
|
||||||
|
[PreferenceKeys.FLASHCARDS_DAY_STREAK]: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Preference = {
|
||||||
|
key: PreferenceKeys
|
||||||
|
value: unknown | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export type PreferenceAsShow = Preference
|
||||||
|
|
||||||
|
export const preferencesApi = {
|
||||||
|
async upsert<K extends PreferenceKeys>(
|
||||||
|
userId: number,
|
||||||
|
key: K,
|
||||||
|
value: PreferenceValueMap[K] | null
|
||||||
|
): Promise<{ message: string }> {
|
||||||
|
const { data } = await http.patch(`/api/users/${userId}/preferences/${key}`, {
|
||||||
|
value,
|
||||||
|
})
|
||||||
|
return data
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
export default preferencesApi
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
<template>
|
||||||
|
<v-card
|
||||||
|
flat
|
||||||
|
color="transparent"
|
||||||
|
class="post-card"
|
||||||
|
>
|
||||||
|
<v-card-text class="post">
|
||||||
|
<div class="post-date">
|
||||||
|
<span class="post-date-day font-weight-bold">{{
|
||||||
|
formatDate(blogPost.publishedAt, "dd")
|
||||||
|
}}</span>
|
||||||
|
<span>{{ formatDate(blogPost.publishedAt, "MMM yyyy") }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="post-content">
|
||||||
|
<div class="post-main">
|
||||||
|
<h3 class="font-serif post-title">
|
||||||
|
{{ blogPost.title }}
|
||||||
|
</h3>
|
||||||
|
<p class="font-serif post-excerpt">
|
||||||
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio praesent
|
||||||
|
libero sed cursus ante dapibus diam.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="post-footer">
|
||||||
|
<span class="post-read-time">5 min read</span>
|
||||||
|
<div
|
||||||
|
v-if="blogPost.tags.length"
|
||||||
|
class="post-tags ml-2"
|
||||||
|
>
|
||||||
|
<v-chip
|
||||||
|
v-for="tag in blogPost.tags"
|
||||||
|
:key="tag"
|
||||||
|
size="small"
|
||||||
|
variant="tonal"
|
||||||
|
class="post-tag ml-2"
|
||||||
|
>
|
||||||
|
{{ tag }}
|
||||||
|
</v-chip>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</v-card-text>
|
||||||
|
</v-card>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { toRefs } from "vue"
|
||||||
|
|
||||||
|
import { BlogPostIndexView } from "@/api/blog-posts-api"
|
||||||
|
import { formatDate } from "@/utils/formatters"
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
blogPost: BlogPostIndexView
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { blogPost } = toRefs(props)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.post {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 76px 1fr;
|
||||||
|
gap: 32px;
|
||||||
|
padding: 18px 0;
|
||||||
|
min-height: 180px;
|
||||||
|
height: 100%;
|
||||||
|
border-bottom: 1px solid rgb(var(--v-theme-borderColor));
|
||||||
|
}
|
||||||
|
|
||||||
|
.post:first-child {
|
||||||
|
padding-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post:last-child {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-date {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
font-family: ui-monospace, Menlo, Monaco, Consolas, "Ubuntu Mono", monospace;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.5;
|
||||||
|
color: rgb(var(--v-theme-textSecondary) / 70%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-date-day {
|
||||||
|
display: block;
|
||||||
|
font-size: 20px;
|
||||||
|
line-height: 1.5;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-content {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: space-between;
|
||||||
|
height: 100%;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-main {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-title {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 1.35rem;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-excerpt {
|
||||||
|
margin: 6px 0 0;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
color: rgb(var(--v-theme-textSecondary) / 65%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-footer {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
margin-top: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-tags {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-tag {
|
||||||
|
font-family: ui-monospace, Menlo, Monaco, Consolas, "Ubuntu Mono", monospace;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
<template>
|
||||||
|
<v-skeleton-loader
|
||||||
|
v-if="isEmpty(publicBlogPosts) && isLoading"
|
||||||
|
type="list-item-three-line"
|
||||||
|
/>
|
||||||
|
<v-empty-state
|
||||||
|
v-else-if="isEmpty(publicBlogPosts) && !isLoading"
|
||||||
|
text="No blog posts found."
|
||||||
|
/>
|
||||||
|
<template v-else>
|
||||||
|
<BlogPostListItemCard
|
||||||
|
v-for="blogPost in publicBlogPosts"
|
||||||
|
:key="blogPost.id"
|
||||||
|
:blog-post="blogPost"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
<EnhancedPagination
|
||||||
|
v-model="page"
|
||||||
|
v-model:per-page="perPage"
|
||||||
|
:total-count="totalCount"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { computed } from "vue"
|
||||||
|
import { isEmpty } from "lodash"
|
||||||
|
|
||||||
|
import useRouteQueryPagination from "@/use/utils/use-route-query-pagination"
|
||||||
|
import usePublicBlogPosts, {
|
||||||
|
type PublicBlogPostFiltersOptions,
|
||||||
|
type PublicBlogPostQueryOptions,
|
||||||
|
type PublicBlogPostWhereOptions,
|
||||||
|
} from "@/use/use-public-blog-posts"
|
||||||
|
|
||||||
|
import EnhancedPagination from "@/components/common/EnhancedPagination.vue"
|
||||||
|
import BlogPostListItemCard from "@/components/blog-posts/BlogPostListItemCard.vue"
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
filters?: PublicBlogPostFiltersOptions
|
||||||
|
where?: PublicBlogPostWhereOptions
|
||||||
|
routeQuerySuffix?: string
|
||||||
|
waiting?: boolean
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
filters: () => ({}),
|
||||||
|
where: () => ({}),
|
||||||
|
routeQuerySuffix: "BlogPosts",
|
||||||
|
waiting: false,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const { page, perPage } = useRouteQueryPagination({ routeQuerySuffix: props.routeQuerySuffix })
|
||||||
|
const blogPostQueryOptions = computed<PublicBlogPostQueryOptions>(() => ({
|
||||||
|
where: props.where,
|
||||||
|
filters: props.filters,
|
||||||
|
page: page.value,
|
||||||
|
perPage: perPage.value,
|
||||||
|
}))
|
||||||
|
|
||||||
|
const { publicBlogPosts, totalCount, isLoading, refresh } = usePublicBlogPosts(
|
||||||
|
blogPostQueryOptions,
|
||||||
|
{ skipWatchIf: () => props.waiting }
|
||||||
|
)
|
||||||
|
|
||||||
|
defineExpose({ refresh })
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
<template>
|
||||||
|
<v-card
|
||||||
|
elevation="8"
|
||||||
|
hover
|
||||||
|
>
|
||||||
|
<v-card-item>
|
||||||
|
<div class="d-flex align-center">
|
||||||
|
<v-avatar
|
||||||
|
:color="color"
|
||||||
|
size="56"
|
||||||
|
class="mr-4"
|
||||||
|
>
|
||||||
|
<slot name="icon"></slot>
|
||||||
|
</v-avatar>
|
||||||
|
<div>
|
||||||
|
<v-card-title class="text-h5">{{ title }}</v-card-title>
|
||||||
|
<v-card-subtitle>{{ subtitle }}</v-card-subtitle>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</v-card-item>
|
||||||
|
|
||||||
|
<v-divider />
|
||||||
|
|
||||||
|
<v-card-text>
|
||||||
|
<div class="d-flex align-center justify-space-between">
|
||||||
|
<span class="text-h3 font-weight-bold">{{ count ?? " " }}</span>
|
||||||
|
<v-icon
|
||||||
|
size="large"
|
||||||
|
:color="color"
|
||||||
|
>
|
||||||
|
mdi-chevron-right
|
||||||
|
</v-icon>
|
||||||
|
</div>
|
||||||
|
<div class="text-caption text-medium-emphasis mt-1">{{ countLabel ?? " " }}</div>
|
||||||
|
</v-card-text>
|
||||||
|
</v-card>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
title: string
|
||||||
|
subtitle?: string
|
||||||
|
count?: number | null
|
||||||
|
countLabel?: string | null
|
||||||
|
color?: string
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
subtitle: "",
|
||||||
|
count: null,
|
||||||
|
countLabel: null,
|
||||||
|
color: "primary",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
</script>
|
||||||
@@ -8,86 +8,20 @@
|
|||||||
<span class="term-green">caleb</span>
|
<span class="term-green">caleb</span>
|
||||||
<span class="term-cyan">@</span>
|
<span class="term-cyan">@</span>
|
||||||
<span class="term-green mr-2">burke</span>
|
<span class="term-green mr-2">burke</span>
|
||||||
<span class="term-white">~</span>
|
|
||||||
<span class="term-cyan mr-2">$</span>
|
|
||||||
<span class="term-white">{{ typedText }}</span>
|
|
||||||
<span
|
|
||||||
v-if="animated"
|
|
||||||
class="term-cursor"
|
|
||||||
>
|
|
||||||
█
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
</RouterLink>
|
</RouterLink>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onMounted, onUnmounted, ref } from "vue"
|
withDefaults(
|
||||||
|
|
||||||
const props = withDefaults(
|
|
||||||
defineProps<{
|
defineProps<{
|
||||||
to?: string
|
to?: string
|
||||||
animated?: boolean
|
|
||||||
}>(),
|
}>(),
|
||||||
{
|
{
|
||||||
to: "/dashboard",
|
to: "/dashboard",
|
||||||
animated: false,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
const TYPED_PHRASES = [
|
|
||||||
" Hello!",
|
|
||||||
" Cheers!",
|
|
||||||
" привет",
|
|
||||||
" クリア",
|
|
||||||
" Εβίβα!",
|
|
||||||
" 干杯",
|
|
||||||
" Будьмо!",
|
|
||||||
" Na zdraví!",
|
|
||||||
" 乾杯!",
|
|
||||||
]
|
|
||||||
const TYPE_DELAY_MS = 150
|
|
||||||
const DELETE_DELAY_MS = 100
|
|
||||||
const PAUSE_AFTER_TYPED_MS = 1500
|
|
||||||
const INITIAL_DELAY_MS = 800
|
|
||||||
|
|
||||||
const typedText = ref("")
|
|
||||||
let currentPhrase = ""
|
|
||||||
let typingTimeoutId: ReturnType<typeof setTimeout>
|
|
||||||
|
|
||||||
function pickRandomPhrase() {
|
|
||||||
return TYPED_PHRASES[Math.floor(Math.random() * TYPED_PHRASES.length)]
|
|
||||||
}
|
|
||||||
|
|
||||||
function typeCharacter(index: number) {
|
|
||||||
typedText.value = currentPhrase.slice(0, index)
|
|
||||||
|
|
||||||
if (index < currentPhrase.length) {
|
|
||||||
typingTimeoutId = setTimeout(() => typeCharacter(index + 1), TYPE_DELAY_MS)
|
|
||||||
} else {
|
|
||||||
typingTimeoutId = setTimeout(() => deleteCharacter(index), PAUSE_AFTER_TYPED_MS)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function deleteCharacter(index: number) {
|
|
||||||
typedText.value = currentPhrase.slice(0, index)
|
|
||||||
|
|
||||||
if (index > 0) {
|
|
||||||
typingTimeoutId = setTimeout(() => deleteCharacter(index - 1), DELETE_DELAY_MS)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
if (!props.animated) return
|
|
||||||
|
|
||||||
currentPhrase = pickRandomPhrase()
|
|
||||||
typingTimeoutId = setTimeout(() => typeCharacter(0), INITIAL_DELAY_MS)
|
|
||||||
})
|
|
||||||
|
|
||||||
onUnmounted(() => {
|
|
||||||
clearTimeout(typingTimeoutId)
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
@@ -18,22 +18,6 @@
|
|||||||
<v-spacer />
|
<v-spacer />
|
||||||
|
|
||||||
<ProfileMenu />
|
<ProfileMenu />
|
||||||
|
|
||||||
<template #extension>
|
|
||||||
<v-tabs
|
|
||||||
class="ml-2"
|
|
||||||
color="primary"
|
|
||||||
>
|
|
||||||
<v-tab
|
|
||||||
:to="{ name: 'DashboardPage' }"
|
|
||||||
text="Dashboard"
|
|
||||||
/>
|
|
||||||
<v-tab
|
|
||||||
:to="{ name: 'FlashcardsPage' }"
|
|
||||||
text="Flashcards"
|
|
||||||
/>
|
|
||||||
</v-tabs>
|
|
||||||
</template>
|
|
||||||
</v-app-bar>
|
</v-app-bar>
|
||||||
</div>
|
</div>
|
||||||
<div v-else>
|
<div v-else>
|
||||||
@@ -51,19 +35,14 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<v-tabs
|
<div class="d-flex align-center">
|
||||||
class="ml-2"
|
<v-divider vertical />
|
||||||
color="primary"
|
<ExactingBreadcrumbs
|
||||||
>
|
class="appbar-title"
|
||||||
<v-tab
|
density="compact"
|
||||||
:to="{ name: 'DashboardPage' }"
|
:items="breadcrumbs"
|
||||||
text="Dashboard"
|
|
||||||
/>
|
/>
|
||||||
<v-tab
|
</div>
|
||||||
:to="{ name: 'FlashcardsPage' }"
|
|
||||||
text="Flashcards"
|
|
||||||
/>
|
|
||||||
</v-tabs>
|
|
||||||
|
|
||||||
<v-spacer />
|
<v-spacer />
|
||||||
|
|
||||||
@@ -92,8 +71,30 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useDisplay } from "vuetify"
|
import { useDisplay } from "vuetify"
|
||||||
|
|
||||||
|
import useBreadcrumbs from "@/use/use-breadcrumbs"
|
||||||
|
|
||||||
import PublicAppLogo from "@/components/common/PublicAppLogo.vue"
|
import PublicAppLogo from "@/components/common/PublicAppLogo.vue"
|
||||||
import ProfileMenu from "@/components/layout/ProfileMenu.vue"
|
import ProfileMenu from "@/components/layout/ProfileMenu.vue"
|
||||||
|
import ExactingBreadcrumbs from "@/components/layout/ExactingBreadcrumbs.vue"
|
||||||
|
|
||||||
const { mobile } = useDisplay()
|
const { mobile } = useDisplay()
|
||||||
|
const { breadcrumbs } = useBreadcrumbs(undefined, undefined, {
|
||||||
|
baseCrumb: {
|
||||||
|
title: "Dashboard",
|
||||||
|
to: {
|
||||||
|
name: "DashboardPage",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.appbar-title {
|
||||||
|
margin-left: 12px;
|
||||||
|
padding: 0 0 0 12px;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 1.1rem;
|
||||||
|
font-weight: 600;
|
||||||
|
letter-spacing: 0.01em;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -30,10 +30,7 @@
|
|||||||
class="main-head pl-2"
|
class="main-head pl-2"
|
||||||
>
|
>
|
||||||
<div class="mr-3">
|
<div class="mr-3">
|
||||||
<PublicAppLogo
|
<PublicAppLogo to="/" />
|
||||||
to="/"
|
|
||||||
:animated="isHomePage"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<v-spacer />
|
<v-spacer />
|
||||||
@@ -51,17 +48,12 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed } from "vue"
|
|
||||||
import { useRoute } from "vue-router"
|
|
||||||
import { useDisplay } from "vuetify"
|
import { useDisplay } from "vuetify"
|
||||||
import { useAuth0 } from "@auth0/auth0-vue"
|
import { useAuth0 } from "@auth0/auth0-vue"
|
||||||
|
|
||||||
import ProfileMenu from "@/components/layout/ProfileMenu.vue"
|
import ProfileMenu from "@/components/layout/ProfileMenu.vue"
|
||||||
import PublicAppLogo from "@/components/common/PublicAppLogo.vue"
|
import PublicAppLogo from "@/components/common/PublicAppLogo.vue"
|
||||||
|
|
||||||
const route = useRoute()
|
|
||||||
const isHomePage = computed(() => route.name === "HomePage")
|
|
||||||
|
|
||||||
const { mobile } = useDisplay()
|
const { mobile } = useDisplay()
|
||||||
const { isAuthenticated } = useAuth0()
|
const { isAuthenticated } = useAuth0()
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,22 +1,224 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-app>
|
<v-app>
|
||||||
<PublicAppBar />
|
<PublicAppBar class="mb-2" />
|
||||||
|
|
||||||
<v-main>
|
<v-main>
|
||||||
<v-container
|
<v-container
|
||||||
fluid
|
fluid
|
||||||
:class="mobile ? 'pa-2' : 'pa-4'"
|
:class="mobile ? 'pa-2' : 'pa-4'"
|
||||||
|
>
|
||||||
|
<div class="public-content mt-4">
|
||||||
|
<v-row class="public-row">
|
||||||
|
<v-col
|
||||||
|
cols="12"
|
||||||
|
md="3"
|
||||||
|
class="sidebar-col"
|
||||||
|
>
|
||||||
|
<aside class="sidebar">
|
||||||
|
<nav
|
||||||
|
class="sidebar-nav mb-6"
|
||||||
|
aria-label="Primary"
|
||||||
|
>
|
||||||
|
<RouterLink
|
||||||
|
:to="{ name: 'HomePage' }"
|
||||||
|
class="sidebar-nav-link"
|
||||||
|
>
|
||||||
|
<span>Home</span
|
||||||
|
><span :class="{ 'text-warning': route.name === 'HomePage' }">~/</span>
|
||||||
|
</RouterLink>
|
||||||
|
<RouterLink
|
||||||
|
:to="{ name: 'BlogPage' }"
|
||||||
|
class="sidebar-nav-link"
|
||||||
|
>
|
||||||
|
<span>Blog</span
|
||||||
|
><span :class="{ 'text-warning': route.name === 'BlogPage' }">~/blog</span>
|
||||||
|
</RouterLink>
|
||||||
|
</nav>
|
||||||
|
</aside>
|
||||||
|
</v-col>
|
||||||
|
|
||||||
|
<v-col
|
||||||
|
cols="12"
|
||||||
|
md="9"
|
||||||
>
|
>
|
||||||
<router-view />
|
<router-view />
|
||||||
|
</v-col>
|
||||||
|
</v-row>
|
||||||
|
</div>
|
||||||
</v-container>
|
</v-container>
|
||||||
</v-main>
|
</v-main>
|
||||||
|
|
||||||
|
<footer class="public-footer">
|
||||||
|
<span>© {{ currentYear }} Caleb Burke</span>
|
||||||
|
|
||||||
|
<div class="social-links">
|
||||||
|
<a
|
||||||
|
href="https://github.com/burkkyy"
|
||||||
|
class="social-link"
|
||||||
|
title="GitHub"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
<v-icon size="24">mdi-github</v-icon>
|
||||||
|
</a>
|
||||||
|
<a
|
||||||
|
href="https://gitea.burke.host/burkkyy"
|
||||||
|
class="social-link"
|
||||||
|
title="Gitea"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
class="social-svg"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="currentColor"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
>
|
||||||
|
<title>Gitea</title>
|
||||||
|
<path
|
||||||
|
d="M4.209 4.603c-.247 0-.525.02-.84.088-.333.07-1.28.283-2.054 1.027C-.403 7.25.035 9.685.089 10.052c.065.446.263 1.687 1.21 2.768 1.749 2.141 5.513 2.092 5.513 2.092s.462 1.103 1.168 2.119c.955 1.263 1.936 2.248 2.89 2.367 2.406 0 7.212-.004 7.212-.004s.458.004 1.08-.394c.535-.324 1.013-.893 1.013-.893s.492-.527 1.18-1.73c.21-.37.385-.729.538-1.068 0 0 2.107-4.471 2.107-8.823-.042-1.318-.367-1.55-.443-1.627-.156-.156-.366-.153-.366-.153s-4.475.252-6.792.306c-.508.011-1.012.023-1.512.027v4.474l-.634-.301c0-1.39-.004-4.17-.004-4.17-1.107.016-3.405-.084-3.405-.084s-5.399-.27-5.987-.324c-.187-.011-.401-.032-.648-.032zm.354 1.832h.111s.271 2.269.6 3.597C5.549 11.147 6.22 13 6.22 13s-.996-.119-1.641-.348c-.99-.324-1.409-.714-1.409-.714s-.73-.511-1.096-1.52C1.444 8.73 2.021 7.7 2.021 7.7s.32-.859 1.47-1.145c.395-.106.863-.12 1.072-.12zm8.33 2.554c.26.003.509.127.509.127l.868.422-.529 1.075a.686.686 0 0 0-.614.359.685.685 0 0 0 .072.756l-.939 1.924a.69.69 0 0 0-.66.527.687.687 0 0 0 .347.763.686.686 0 0 0 .867-.206.688.688 0 0 0-.069-.882l.916-1.874a.667.667 0 0 0 .237-.02.657.657 0 0 0 .271-.137 8.826 8.826 0 0 1 1.016.512.761.761 0 0 1 .286.282c.073.21-.073.569-.073.569-.087.29-.702 1.55-.702 1.55a.692.692 0 0 0-.676.477.681.681 0 1 0 1.157-.252c.073-.141.141-.282.214-.431.19-.397.515-1.16.515-1.16.035-.066.218-.394.103-.814-.095-.435-.48-.638-.48-.638-.467-.301-1.116-.58-1.116-.58s0-.156-.042-.27a.688.688 0 0 0-.148-.241l.516-1.062 2.89 1.401s.48.218.583.619c.073.282-.019.534-.069.657-.24.587-2.1 4.317-2.1 4.317s-.232.554-.748.588a1.065 1.065 0 0 1-.393-.045l-.202-.08-4.31-2.1s-.417-.218-.49-.596c-.083-.31.104-.691.104-.691l2.073-4.272s.183-.37.466-.497a.855.855 0 0 1 .35-.077z"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
<a
|
||||||
|
href="https://discord.com/users/burkkyy"
|
||||||
|
class="social-link"
|
||||||
|
title="Discord"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
class="social-svg"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="currentColor"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
>
|
||||||
|
<title>Discord</title>
|
||||||
|
<path
|
||||||
|
d="M20.317 4.3698a19.7913 19.7913 0 00-4.8851-1.5152.0741.0741 0 00-.0785.0371c-.211.3753-.4447.8648-.6083 1.2495-1.8447-.2762-3.68-.2762-5.4868 0-.1636-.3933-.4058-.8742-.6177-1.2495a.077.077 0 00-.0785-.037 19.7363 19.7363 0 00-4.8852 1.515.0699.0699 0 00-.0321.0277C.5334 9.0458-.319 13.5799.0992 18.0578a.0824.0824 0 00.0312.0561c2.0528 1.5076 4.0413 2.4228 5.9929 3.0294a.0777.0777 0 00.0842-.0276c.4616-.6304.8731-1.2952 1.226-1.9942a.076.076 0 00-.0416-.1057c-.6528-.2476-1.2743-.5495-1.8722-.8923a.077.077 0 01-.0076-.1277c.1258-.0943.2517-.1923.3718-.2914a.0743.0743 0 01.0776-.0105c3.9278 1.7933 8.18 1.7933 12.0614 0a.0739.0739 0 01.0785.0095c.1202.099.246.1981.3728.2924a.077.077 0 01-.0066.1276 12.2986 12.2986 0 01-1.873.8914.0766.0766 0 00-.0407.1067c.3604.698.7719 1.3628 1.225 1.9932a.076.076 0 00.0842.0286c1.961-.6067 3.9495-1.5219 6.0023-3.0294a.077.077 0 00.0313-.0552c.5004-5.177-.8382-9.6739-3.5485-13.6604a.061.061 0 00-.0312-.0286zM8.02 15.3312c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9555-2.4189 2.157-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.9555 2.4189-2.1569 2.4189zm7.9748 0c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9554-2.4189 2.1569-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.946 2.4189-2.1568 2.4189Z"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
<a
|
||||||
|
href="https://www.linkedin.com/in/calebburke91/"
|
||||||
|
class="social-link"
|
||||||
|
title="LinkedIn"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
<v-icon size="24">mdi-linkedin</v-icon>
|
||||||
|
</a>
|
||||||
|
<a
|
||||||
|
href="mailto:calebburke91@gmail.com"
|
||||||
|
class="social-link"
|
||||||
|
title="Gmail"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
<v-icon size="24">mdi-gmail</v-icon>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
</v-app>
|
</v-app>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useDisplay } from "vuetify"
|
import { useDisplay } from "vuetify"
|
||||||
|
import { useRoute } from "vue-router"
|
||||||
|
import { DateTime } from "luxon"
|
||||||
|
|
||||||
import PublicAppBar from "@/components/layout/PublicAppBar.vue"
|
import PublicAppBar from "@/components/layout/PublicAppBar.vue"
|
||||||
|
|
||||||
const { mobile } = useDisplay()
|
const { mobile } = useDisplay()
|
||||||
|
const route = useRoute()
|
||||||
|
const currentYear = DateTime.local().year
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.public-content {
|
||||||
|
max-width: 1300px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar {
|
||||||
|
position: sticky;
|
||||||
|
top: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-nav {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-nav-link {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 16px 10px;
|
||||||
|
margin: 0 -10px;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-family: ui-monospace, Menlo, Monaco, Consolas, "Ubuntu Mono", monospace;
|
||||||
|
font-size: 14px;
|
||||||
|
color: rgb(var(--v-theme-textSecondary));
|
||||||
|
text-decoration: none;
|
||||||
|
transition:
|
||||||
|
background-color 0.15s ease,
|
||||||
|
color 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-nav-link:hover,
|
||||||
|
.sidebar-nav-link.router-link-active {
|
||||||
|
background-color: rgb(var(--v-theme-hoverColor));
|
||||||
|
color: rgb(var(--v-theme-textPrimary));
|
||||||
|
}
|
||||||
|
|
||||||
|
.social-links {
|
||||||
|
display: flex;
|
||||||
|
gap: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.social-link {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
color: rgb(var(--v-theme-textSecondary));
|
||||||
|
text-decoration: none;
|
||||||
|
transition: color 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.social-link:hover {
|
||||||
|
color: rgb(var(--v-theme-primary));
|
||||||
|
}
|
||||||
|
|
||||||
|
.social-svg {
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.public-footer {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 16px;
|
||||||
|
padding: 16px 24px;
|
||||||
|
border-top: 1px solid rgb(var(--v-theme-borderColor));
|
||||||
|
font-family: ui-monospace, Menlo, Monaco, Consolas, "Ubuntu Mono", monospace;
|
||||||
|
font-size: 12px;
|
||||||
|
color: rgb(var(--v-theme-textSecondary));
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 960px) {
|
||||||
|
.sidebar {
|
||||||
|
position: static;
|
||||||
|
}
|
||||||
|
|
||||||
|
.public-footer {
|
||||||
|
justify-content: center;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<template>
|
||||||
|
<v-row class="home-row ml-5">
|
||||||
|
<v-col
|
||||||
|
cols="12"
|
||||||
|
md="8"
|
||||||
|
>
|
||||||
|
<main>
|
||||||
|
<section class="posts-section">
|
||||||
|
<PublicBlogPostsList />
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
</v-col>
|
||||||
|
</v-row>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import useBreadcrumbs from "@/use/use-breadcrumbs"
|
||||||
|
|
||||||
|
import PublicBlogPostsList from "@/components/blog-posts/PublicBlogPostsList.vue"
|
||||||
|
|
||||||
|
useBreadcrumbs("Blog", [
|
||||||
|
{
|
||||||
|
title: "Blog",
|
||||||
|
to: {
|
||||||
|
name: "BlogPage",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.section-eyebrow {
|
||||||
|
display: block;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -4,15 +4,70 @@
|
|||||||
You are a system admin
|
You are a system admin
|
||||||
</AppCard>
|
</AppCard>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<v-row class="mt-1">
|
||||||
|
<v-col
|
||||||
|
cols="12"
|
||||||
|
md="6"
|
||||||
|
lg="4"
|
||||||
|
>
|
||||||
|
<DashboardCard
|
||||||
|
:to="{ name: 'FlashcardsPage' }"
|
||||||
|
title="Flashcards"
|
||||||
|
subtitle="Study and manage your flashcard decks"
|
||||||
|
:count="flashcardDecksCount"
|
||||||
|
count-label="Total Decks"
|
||||||
|
color="success"
|
||||||
|
>
|
||||||
|
<template #icon>
|
||||||
|
<v-icon
|
||||||
|
size="32"
|
||||||
|
color="white"
|
||||||
|
>
|
||||||
|
mdi-cards-outline
|
||||||
|
</v-icon>
|
||||||
|
</template>
|
||||||
|
</DashboardCard>
|
||||||
|
</v-col>
|
||||||
|
<v-col
|
||||||
|
cols="12"
|
||||||
|
md="6"
|
||||||
|
lg="4"
|
||||||
|
>
|
||||||
|
<DashboardCard
|
||||||
|
:to="{ name: 'BlogPage' }"
|
||||||
|
title="Blog Posts"
|
||||||
|
subtitle="Read and manage blog posts"
|
||||||
|
:count="blogPostsCount"
|
||||||
|
count-label="Total Posts"
|
||||||
|
color="info"
|
||||||
|
>
|
||||||
|
<template #icon>
|
||||||
|
<v-icon
|
||||||
|
size="32"
|
||||||
|
color="white"
|
||||||
|
>
|
||||||
|
mdi-post-outline
|
||||||
|
</v-icon>
|
||||||
|
</template>
|
||||||
|
</DashboardCard>
|
||||||
|
</v-col>
|
||||||
|
</v-row>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import useBreadcrumbs from "@/use/use-breadcrumbs"
|
import useBreadcrumbs from "@/use/use-breadcrumbs"
|
||||||
import useCurrentUser from "@/use/use-current-user"
|
import useCurrentUser from "@/use/use-current-user"
|
||||||
|
import useFlashcardDecks from "@/use/use-flashcard-decks"
|
||||||
|
import useBlogPosts from "@/use/use-blog-posts"
|
||||||
|
|
||||||
import AppCard from "@/components/common/AppCard.vue"
|
import AppCard from "@/components/common/AppCard.vue"
|
||||||
|
import DashboardCard from "@/components/common/DashboardCard.vue"
|
||||||
|
|
||||||
const { isSystemAdmin } = useCurrentUser<true>()
|
const { isSystemAdmin } = useCurrentUser<true>()
|
||||||
|
|
||||||
useBreadcrumbs()
|
const { totalCount: flashcardDecksCount } = useFlashcardDecks()
|
||||||
|
const { totalCount: blogPostsCount } = useBlogPosts()
|
||||||
|
|
||||||
|
useBreadcrumbs("Dashboard", [])
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -154,5 +154,12 @@ function openFlashcardCreateDialog() {
|
|||||||
flashcardCreateDialog.value?.show()
|
flashcardCreateDialog.value?.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
useBreadcrumbs("Study")
|
useBreadcrumbs("Flashcards", [
|
||||||
|
{
|
||||||
|
title: "Flashcards",
|
||||||
|
to: {
|
||||||
|
name: "FlashcardsPage",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
+375
-11
@@ -1,28 +1,392 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<v-row class="home-row">
|
||||||
<v-row>
|
<v-col
|
||||||
|
cols="12"
|
||||||
|
md="8"
|
||||||
|
>
|
||||||
|
<main>
|
||||||
|
<div class="terminal mb-10">
|
||||||
|
<div class="terminal-bar">
|
||||||
|
<span class="terminal-dot terminal-dot-red"></span>
|
||||||
|
<span class="terminal-dot terminal-dot-yellow"></span>
|
||||||
|
<span class="terminal-dot terminal-dot-green"></span>
|
||||||
|
<span class="terminal-title">calebburke.dev</span>
|
||||||
|
</div>
|
||||||
|
<div class="terminal-prompt">
|
||||||
|
<span class="term-green">caleb</span>
|
||||||
|
<span class="term-cyan">@</span><span class="term-green">burke</span>
|
||||||
|
<span class="term-white"> ~</span>
|
||||||
|
<span class="term-cyan">$</span>
|
||||||
|
<span class="terminal-cmd"> cat about.txt</span>
|
||||||
|
<span class="terminal-out"> Full Stack Developer </span>
|
||||||
|
|
||||||
|
<span class="term-green">caleb</span>
|
||||||
|
<span class="term-cyan">@</span>
|
||||||
|
<span class="term-green">burke</span>
|
||||||
|
<span class="term-white"> ~</span>
|
||||||
|
<span class="term-cyan">$ </span>
|
||||||
|
<span class="terminal-cmd">{{ typedText }}</span>
|
||||||
|
<span class="term-cursor">█</span>
|
||||||
|
<!-- <span class="term-green">caleb</span><span class="term-cyan">@</span
|
||||||
|
><span class="term-green">burke</span><span class="term-white">:~$</span>
|
||||||
|
<span class="terminal-cmd"> ls ~/posts | head -3</span>
|
||||||
|
<span
|
||||||
|
v-if="isLoading"
|
||||||
|
class="terminal-out terminal-out-dim"
|
||||||
|
>loading…</span
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
v-else-if="recentBlogPosts.length === 0"
|
||||||
|
class="terminal-out terminal-out-dim"
|
||||||
|
>(no posts published yet)</span
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
v-else
|
||||||
|
class="terminal-out terminal-out-dim"
|
||||||
|
>{{ recentBlogPosts.map((blogPost) => blogPost.slug).join(" ") }}</span
|
||||||
|
> -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<section class="posts-section">
|
||||||
|
<div class="section-head">
|
||||||
|
<div>
|
||||||
|
<span class="section-eyebrow font-mono mb-4 text-warning">~/blog</span>
|
||||||
|
<h2 class="text-h3 font-serif">Recent posts</h2>
|
||||||
|
</div>
|
||||||
|
<RouterLink
|
||||||
|
:to="{ name: 'BlogPage' }"
|
||||||
|
class="section-view-all"
|
||||||
|
>
|
||||||
|
view all
|
||||||
|
</RouterLink>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="isLoading">
|
||||||
|
<v-skeleton-loader
|
||||||
|
v-for="index in 3"
|
||||||
|
:key="index"
|
||||||
|
type="list-item-two-line"
|
||||||
|
class="mb-2"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<p
|
||||||
|
v-else-if="totalCount === 0"
|
||||||
|
class="text-medium-emphasis"
|
||||||
|
>
|
||||||
|
Nothing published yet — check back soon.
|
||||||
|
</p>
|
||||||
|
<div
|
||||||
|
v-for="(blogPost, index) of recentBlogPosts"
|
||||||
|
v-else
|
||||||
|
:key="index"
|
||||||
|
>
|
||||||
|
<BlogPostListItemCard
|
||||||
|
:blog-post="blogPost"
|
||||||
|
class="mb-2"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
</v-col>
|
||||||
|
|
||||||
<v-col
|
<v-col
|
||||||
cols="12"
|
cols="12"
|
||||||
sm="6"
|
|
||||||
md="4"
|
md="4"
|
||||||
lg="2"
|
|
||||||
>
|
>
|
||||||
<AppCard
|
<aside class="rail">
|
||||||
|
<!-- <div
|
||||||
|
v-if="allTags.length"
|
||||||
|
class="rail-block"
|
||||||
|
>
|
||||||
|
<span class="rail-eyebrow">Tags</span>
|
||||||
|
<div class="tag-cloud">
|
||||||
|
<span
|
||||||
|
v-for="tag in allTags"
|
||||||
|
:key="tag"
|
||||||
|
class="tag-chip"
|
||||||
|
>{{ tag }}</span
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div> -->
|
||||||
|
|
||||||
|
<div class="rail-block">
|
||||||
|
<v-card
|
||||||
|
variant="outlined"
|
||||||
|
class="now-box pa-4 mb-4"
|
||||||
|
>
|
||||||
|
<div class="d-flex justify-space-between ga-2">
|
||||||
|
<span class="text-medium-emphasis">release</span>
|
||||||
|
<span>{{ status.releaseTag || "dev" }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="d-flex justify-space-between ga-2 my-2">
|
||||||
|
<span class="text-medium-emphasis">commit</span>
|
||||||
|
<span>{{ shortCommitHash }}</span>
|
||||||
|
</div>
|
||||||
|
<RouterLink
|
||||||
|
:to="{ name: 'StatusPage' }"
|
||||||
|
class="text-primary text-decoration-none mt-2 d-block"
|
||||||
|
>
|
||||||
|
view status
|
||||||
|
</RouterLink>
|
||||||
|
</v-card>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
v-if="isAuthenticated"
|
v-if="isAuthenticated"
|
||||||
:to="{ name: 'DashboardPage' }"
|
class="rail-block"
|
||||||
elevation="6"
|
|
||||||
>
|
>
|
||||||
You are signed in. Go to Dashboard
|
<v-card
|
||||||
</AppCard>
|
variant="tonal"
|
||||||
|
color="primary"
|
||||||
|
class="pa-4"
|
||||||
|
>
|
||||||
|
<p class="text-body-2 mb-3">Welcome back — jump into your dashboard.</p>
|
||||||
|
<v-btn
|
||||||
|
:to="isAuthenticated ? { name: 'DashboardPage' } : { name: 'SignInPage' }"
|
||||||
|
color="primary"
|
||||||
|
variant="tonal"
|
||||||
|
size="small"
|
||||||
|
text="Go to dashboard"
|
||||||
|
/>
|
||||||
|
</v-card>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { computed, onMounted, onUnmounted, reactive, ref } from "vue"
|
||||||
import { useAuth0 } from "@auth0/auth0-vue"
|
import { useAuth0 } from "@auth0/auth0-vue"
|
||||||
|
|
||||||
import AppCard from "@/components/common/AppCard.vue"
|
import http from "@/api/http-client"
|
||||||
|
|
||||||
|
import usePublicBlogPosts from "@/use/use-public-blog-posts"
|
||||||
|
|
||||||
|
import BlogPostListItemCard from "@/components/blog-posts/BlogPostListItemCard.vue"
|
||||||
|
|
||||||
const { isAuthenticated } = useAuth0()
|
const { isAuthenticated } = useAuth0()
|
||||||
|
|
||||||
|
const { publicBlogPosts, totalCount, isLoading } = usePublicBlogPosts()
|
||||||
|
|
||||||
|
const recentBlogPosts = computed(() => publicBlogPosts.value.slice(0, 4))
|
||||||
|
// const allTags = computed(() => [
|
||||||
|
// ...new Set(publicBlogPosts.value.flatMap((blogPost) => blogPost.tags)),
|
||||||
|
// ])
|
||||||
|
|
||||||
|
const status = reactive({
|
||||||
|
releaseTag: "",
|
||||||
|
gitCommitHash: "",
|
||||||
|
})
|
||||||
|
|
||||||
|
const shortCommitHash = computed(() => status.gitCommitHash.slice(0, 7) || "local")
|
||||||
|
|
||||||
|
const TYPED_PHRASES = [
|
||||||
|
" Hello!",
|
||||||
|
" sudo rm -rf --no-preserve-root /",
|
||||||
|
" :(){ :|:& };:",
|
||||||
|
" Cheers!",
|
||||||
|
" привет",
|
||||||
|
" クリア",
|
||||||
|
" Εβίβα!",
|
||||||
|
" 干杯",
|
||||||
|
" Будьмо!",
|
||||||
|
" Na zdraví!",
|
||||||
|
" 乾杯!",
|
||||||
|
]
|
||||||
|
const TYPE_DELAY_MS = 150
|
||||||
|
const DELETE_DELAY_MS = 100
|
||||||
|
const PAUSE_AFTER_TYPED_MS = 1500
|
||||||
|
const PAUSE_AFTER_DELETED_MS = 5000
|
||||||
|
const INITIAL_DELAY_MS = 800
|
||||||
|
|
||||||
|
const typedText = ref("")
|
||||||
|
let currentPhrase = ""
|
||||||
|
let typingTimeoutId: ReturnType<typeof setTimeout>
|
||||||
|
|
||||||
|
function pickRandomPhrase() {
|
||||||
|
return TYPED_PHRASES[Math.floor(Math.random() * TYPED_PHRASES.length)]
|
||||||
|
}
|
||||||
|
|
||||||
|
function typeCharacter(index: number) {
|
||||||
|
typedText.value = currentPhrase.slice(0, index)
|
||||||
|
|
||||||
|
if (index < currentPhrase.length) {
|
||||||
|
typingTimeoutId = setTimeout(() => typeCharacter(index + 1), TYPE_DELAY_MS)
|
||||||
|
} else {
|
||||||
|
typingTimeoutId = setTimeout(() => deleteCharacter(index), PAUSE_AFTER_TYPED_MS)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteCharacter(index: number) {
|
||||||
|
typedText.value = currentPhrase.slice(0, index)
|
||||||
|
|
||||||
|
if (index > 0) {
|
||||||
|
typingTimeoutId = setTimeout(() => deleteCharacter(index - 1), DELETE_DELAY_MS)
|
||||||
|
} else {
|
||||||
|
typingTimeoutId = setTimeout(() => {
|
||||||
|
currentPhrase = pickRandomPhrase()
|
||||||
|
typeCharacter(0)
|
||||||
|
}, PAUSE_AFTER_DELETED_MS)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
currentPhrase = pickRandomPhrase()
|
||||||
|
typingTimeoutId = setTimeout(() => typeCharacter(0), INITIAL_DELAY_MS)
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { data } = await http.get("/_status")
|
||||||
|
status.releaseTag = data.RELEASE_TAG
|
||||||
|
status.gitCommitHash = data.GIT_COMMIT_HASH
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to fetch status:", error)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
clearTimeout(typingTimeoutId)
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.rail {
|
||||||
|
position: sticky;
|
||||||
|
top: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Terminal hero */
|
||||||
|
.terminal {
|
||||||
|
background-color: rgb(var(--v-theme-surface));
|
||||||
|
border: 1px solid rgb(var(--v-theme-borderColor));
|
||||||
|
border-radius: 8px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.terminal-bar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 10px 14px;
|
||||||
|
background-color: rgb(var(--v-theme-containerBg));
|
||||||
|
border-bottom: 1px solid rgb(var(--v-theme-borderColor));
|
||||||
|
}
|
||||||
|
|
||||||
|
.terminal-dot {
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.terminal-dot-red {
|
||||||
|
background-color: rgb(var(--v-theme-error));
|
||||||
|
}
|
||||||
|
|
||||||
|
.terminal-dot-yellow {
|
||||||
|
background-color: rgb(var(--v-theme-warning));
|
||||||
|
}
|
||||||
|
|
||||||
|
.terminal-dot-green {
|
||||||
|
background-color: rgb(var(--v-theme-success));
|
||||||
|
}
|
||||||
|
|
||||||
|
.terminal-title {
|
||||||
|
margin: 0 auto;
|
||||||
|
transform: translateX(-16px);
|
||||||
|
font-family: ui-monospace, Menlo, Monaco, Consolas, "Ubuntu Mono", monospace;
|
||||||
|
font-size: 12px;
|
||||||
|
color: rgb(var(--v-theme-textSecondary));
|
||||||
|
}
|
||||||
|
|
||||||
|
.terminal-prompt {
|
||||||
|
display: block;
|
||||||
|
padding: 20px 22px 24px;
|
||||||
|
font-family: ui-monospace, Menlo, Monaco, Consolas, "Ubuntu Mono", monospace;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 1.9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.terminal-cmd {
|
||||||
|
color: rgb(var(--v-theme-textPrimary));
|
||||||
|
}
|
||||||
|
|
||||||
|
.terminal-out {
|
||||||
|
display: block;
|
||||||
|
margin: 0 0 10px;
|
||||||
|
color: rgb(var(--v-theme-textSecondary));
|
||||||
|
}
|
||||||
|
|
||||||
|
.terminal-out-dim {
|
||||||
|
color: rgb(var(--v-theme-textSecondary) / 60%);
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes terminal-blink {
|
||||||
|
50% {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Section headers */
|
||||||
|
.section-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-eyebrow {
|
||||||
|
display: block;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-view-all {
|
||||||
|
font-family: ui-monospace, Menlo, Monaco, Consolas, "Ubuntu Mono", monospace;
|
||||||
|
font-size: 12px;
|
||||||
|
color: rgb(var(--v-theme-textSecondary));
|
||||||
|
text-decoration: none;
|
||||||
|
border-bottom: 1px solid rgb(var(--v-theme-borderColor));
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-view-all:hover {
|
||||||
|
color: rgb(var(--v-theme-primary));
|
||||||
|
}
|
||||||
|
|
||||||
|
.tag-chip {
|
||||||
|
font-family: ui-monospace, Menlo, Monaco, Consolas, "Ubuntu Mono", monospace;
|
||||||
|
font-size: 11px;
|
||||||
|
padding: 2px 8px;
|
||||||
|
border-radius: 20px;
|
||||||
|
background-color: rgb(var(--v-theme-surface));
|
||||||
|
border: 1px solid rgb(var(--v-theme-borderColor));
|
||||||
|
color: rgb(var(--v-theme-textSecondary));
|
||||||
|
}
|
||||||
|
|
||||||
|
.tag-cloud {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Right rail */
|
||||||
|
.rail-eyebrow {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
font-family: ui-monospace, Menlo, Monaco, Consolas, "Ubuntu Mono", monospace;
|
||||||
|
font-size: 11px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.06em;
|
||||||
|
color: rgb(var(--v-theme-textSecondary) / 70%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.now-box {
|
||||||
|
font-family: ui-monospace, Menlo, Monaco, Consolas, "Ubuntu Mono", monospace;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 960px) {
|
||||||
|
.rail {
|
||||||
|
position: static;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -1,105 +1,53 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<v-row>
|
<v-row>
|
||||||
<!-- Users Card -->
|
|
||||||
<v-col
|
<v-col
|
||||||
v-if="isSystemAdmin"
|
v-if="isSystemAdmin"
|
||||||
cols="12"
|
cols="12"
|
||||||
md="6"
|
md="6"
|
||||||
lg="4"
|
lg="4"
|
||||||
>
|
>
|
||||||
<v-card
|
<DashboardCard
|
||||||
elevation="10"
|
|
||||||
:to="{ name: 'administration/UsersPage' }"
|
:to="{ name: 'administration/UsersPage' }"
|
||||||
hover
|
title="Users"
|
||||||
>
|
subtitle="Manage users and permissions"
|
||||||
<v-card-item>
|
:count="usersCount"
|
||||||
<div class="d-flex align-center">
|
count-label="Total Users"
|
||||||
<v-avatar
|
|
||||||
color="success"
|
color="success"
|
||||||
size="56"
|
|
||||||
class="mr-4"
|
|
||||||
>
|
>
|
||||||
|
<template #icon>
|
||||||
<v-icon
|
<v-icon
|
||||||
size="32"
|
size="32"
|
||||||
color="white"
|
color="white"
|
||||||
>
|
>
|
||||||
mdi-account-group
|
mdi-account-group
|
||||||
</v-icon>
|
</v-icon>
|
||||||
</v-avatar>
|
</template>
|
||||||
<div>
|
</DashboardCard>
|
||||||
<v-card-title class="text-h5">Users</v-card-title>
|
|
||||||
<v-card-subtitle>Manage users and permissions</v-card-subtitle>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</v-card-item>
|
|
||||||
|
|
||||||
<v-divider />
|
|
||||||
|
|
||||||
<v-card-text>
|
|
||||||
<div class="d-flex align-center justify-space-between">
|
|
||||||
<span class="text-h3 font-weight-bold">{{ usersCount }}</span>
|
|
||||||
<v-icon
|
|
||||||
size="large"
|
|
||||||
color="success"
|
|
||||||
>
|
|
||||||
mdi-chevron-right
|
|
||||||
</v-icon>
|
|
||||||
</div>
|
|
||||||
<div class="text-caption text-medium-emphasis mt-1">Total Users</div>
|
|
||||||
</v-card-text>
|
|
||||||
</v-card>
|
|
||||||
</v-col>
|
</v-col>
|
||||||
|
|
||||||
<!-- Settings Card -->
|
|
||||||
<v-col
|
<v-col
|
||||||
v-if="isSystemAdmin"
|
v-if="isSystemAdmin"
|
||||||
cols="12"
|
cols="12"
|
||||||
md="6"
|
md="6"
|
||||||
lg="4"
|
lg="4"
|
||||||
>
|
>
|
||||||
<v-card
|
<DashboardCard
|
||||||
elevation="10"
|
|
||||||
:to="{ name: 'administration/SettingsPage' }"
|
:to="{ name: 'administration/SettingsPage' }"
|
||||||
hover
|
title="Settings"
|
||||||
>
|
subtitle="System configuration"
|
||||||
<v-card-item>
|
count-label="Configure System"
|
||||||
<div class="d-flex align-center">
|
|
||||||
<v-avatar
|
|
||||||
color="info"
|
color="info"
|
||||||
size="56"
|
|
||||||
class="mr-4"
|
|
||||||
>
|
>
|
||||||
|
<template #icon>
|
||||||
<v-icon
|
<v-icon
|
||||||
size="32"
|
size="32"
|
||||||
color="white"
|
color="white"
|
||||||
>
|
>
|
||||||
mdi-cog
|
mdi-cog
|
||||||
</v-icon>
|
</v-icon>
|
||||||
</v-avatar>
|
</template>
|
||||||
<div>
|
</DashboardCard>
|
||||||
<v-card-title class="text-h5">Settings</v-card-title>
|
|
||||||
<v-card-subtitle>System configuration</v-card-subtitle>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</v-card-item>
|
|
||||||
|
|
||||||
<v-divider />
|
|
||||||
|
|
||||||
<v-card-text>
|
|
||||||
<div class="d-flex align-center justify-space-between">
|
|
||||||
<span class="text-h3 font-weight-bold"> </span>
|
|
||||||
|
|
||||||
<v-icon
|
|
||||||
size="large"
|
|
||||||
color="info"
|
|
||||||
>
|
|
||||||
mdi-chevron-right
|
|
||||||
</v-icon>
|
|
||||||
</div>
|
|
||||||
<div class="text-caption text-medium-emphasis mt-1">Configure System</div>
|
|
||||||
</v-card-text>
|
|
||||||
</v-card>
|
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
</div>
|
</div>
|
||||||
@@ -110,6 +58,8 @@ import useBreadcrumbs from "@/use/use-breadcrumbs"
|
|||||||
import useUsers from "@/use/use-users"
|
import useUsers from "@/use/use-users"
|
||||||
import useCurrentUser from "@/use/use-current-user"
|
import useCurrentUser from "@/use/use-current-user"
|
||||||
|
|
||||||
|
import DashboardCard from "@/components/common/DashboardCard.vue"
|
||||||
|
|
||||||
const { isSystemAdmin } = useCurrentUser()
|
const { isSystemAdmin } = useCurrentUser()
|
||||||
|
|
||||||
const { totalCount: usersCount } = useUsers()
|
const { totalCount: usersCount } = useUsers()
|
||||||
|
|||||||
+13
-3
@@ -4,7 +4,6 @@ import { authGuard } from "@auth0/auth0-vue"
|
|||||||
import { APPLICATION_NAME } from "@/config"
|
import { APPLICATION_NAME } from "@/config"
|
||||||
import administrationRoutes from "@/routes/administration-routes"
|
import administrationRoutes from "@/routes/administration-routes"
|
||||||
import { authorizationGuard } from "@/utils/authorization-guards"
|
import { authorizationGuard } from "@/utils/authorization-guards"
|
||||||
import publicRoutes from "@/routes/public-routes"
|
|
||||||
|
|
||||||
const routes: RouteRecordRaw[] = [
|
const routes: RouteRecordRaw[] = [
|
||||||
{
|
{
|
||||||
@@ -14,9 +13,21 @@ const routes: RouteRecordRaw[] = [
|
|||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
path: "",
|
path: "",
|
||||||
|
redirect: { name: "HomePage" },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "home",
|
||||||
name: "HomePage",
|
name: "HomePage",
|
||||||
component: () => import("@/pages/HomePage.vue"),
|
component: () => import("@/pages/HomePage.vue"),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "BlogPage",
|
||||||
|
path: "blog",
|
||||||
|
component: () => import("@/pages/BlogPage.vue"),
|
||||||
|
meta: {
|
||||||
|
title: "Blog",
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -37,7 +48,7 @@ const routes: RouteRecordRaw[] = [
|
|||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
path: "",
|
path: "",
|
||||||
redirect: "sign-in",
|
redirect: { name: "DashboardPage" },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "DashboardPage",
|
name: "DashboardPage",
|
||||||
@@ -95,7 +106,6 @@ const routes: RouteRecordRaw[] = [
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
...publicRoutes,
|
|
||||||
...administrationRoutes,
|
...administrationRoutes,
|
||||||
{
|
{
|
||||||
name: "StatusPage",
|
name: "StatusPage",
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
import { RouteRecordRaw } from "vue-router"
|
|
||||||
|
|
||||||
export const publicRoutes: Readonly<RouteRecordRaw[]> = [
|
|
||||||
{
|
|
||||||
path: "/public",
|
|
||||||
component: () => import("@/layouts/PublicLayout.vue"),
|
|
||||||
meta: { requiresAuth: false },
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
export default publicRoutes
|
|
||||||
@@ -476,6 +476,14 @@
|
|||||||
text-align: start;
|
text-align: start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.font-serif {
|
||||||
|
font-family: "Source Serif 4", Georgia, serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.font-mono {
|
||||||
|
font-family: ui-monospace, Menlo, Monaco, Consolas, "Ubuntu Mono", monospace;
|
||||||
|
}
|
||||||
|
|
||||||
@media screen and (max-width: 1199px) {
|
@media screen and (max-width: 1199px) {
|
||||||
.ps-96 {
|
.ps-96 {
|
||||||
padding-inline-start: 60px !important;
|
padding-inline-start: 60px !important;
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
import { type Ref, reactive, toRefs, unref, watch } from "vue"
|
||||||
|
import { isNil } from "lodash"
|
||||||
|
|
||||||
|
import blogPostsApi, { type BlogPost } from "@/api/blog-posts-api"
|
||||||
|
|
||||||
|
export { type BlogPost }
|
||||||
|
|
||||||
|
export function useBlogPost(idOrSlug: Ref<number | string | null | undefined>) {
|
||||||
|
const state = reactive<{
|
||||||
|
blogPost: BlogPost | null
|
||||||
|
isLoading: boolean
|
||||||
|
isErrored: boolean
|
||||||
|
}>({
|
||||||
|
blogPost: null,
|
||||||
|
isLoading: false,
|
||||||
|
isErrored: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
async function fetch(): Promise<BlogPost> {
|
||||||
|
const staticIdOrSlug = unref(idOrSlug)
|
||||||
|
if (isNil(staticIdOrSlug)) {
|
||||||
|
throw new Error("idOrSlug is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
state.isLoading = true
|
||||||
|
try {
|
||||||
|
const { blogPost } = await blogPostsApi.get(staticIdOrSlug)
|
||||||
|
state.isErrored = false
|
||||||
|
state.blogPost = blogPost
|
||||||
|
return blogPost
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to fetch blog post:", error)
|
||||||
|
state.isErrored = true
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
state.isLoading = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function save(): Promise<BlogPost> {
|
||||||
|
const staticIdOrSlug = unref(idOrSlug)
|
||||||
|
if (isNil(staticIdOrSlug)) {
|
||||||
|
throw new Error("idOrSlug is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNil(state.blogPost)) {
|
||||||
|
throw new Error("No blog post to save")
|
||||||
|
}
|
||||||
|
|
||||||
|
state.isLoading = true
|
||||||
|
try {
|
||||||
|
const { blogPost } = await blogPostsApi.update(staticIdOrSlug, state.blogPost)
|
||||||
|
state.isErrored = false
|
||||||
|
state.blogPost = blogPost
|
||||||
|
return blogPost
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to save blog post:", error)
|
||||||
|
state.isErrored = true
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
state.isLoading = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => unref(idOrSlug),
|
||||||
|
async (newIdOrSlug) => {
|
||||||
|
if (isNil(newIdOrSlug)) return
|
||||||
|
|
||||||
|
await fetch()
|
||||||
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
)
|
||||||
|
|
||||||
|
return {
|
||||||
|
...toRefs(state),
|
||||||
|
fetch,
|
||||||
|
refresh: fetch,
|
||||||
|
save,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default useBlogPost
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
import { type Ref, reactive, toRefs, ref, unref, watch } from "vue"
|
||||||
|
|
||||||
|
import blogPostsApi, {
|
||||||
|
type BlogPostIndexView,
|
||||||
|
type BlogPostWhereOptions,
|
||||||
|
type BlogPostFiltersOptions,
|
||||||
|
type BlogPostQueryOptions,
|
||||||
|
} from "@/api/blog-posts-api"
|
||||||
|
|
||||||
|
export {
|
||||||
|
type BlogPostIndexView,
|
||||||
|
type BlogPostWhereOptions,
|
||||||
|
type BlogPostFiltersOptions,
|
||||||
|
type BlogPostQueryOptions,
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useBlogPosts(
|
||||||
|
queryOptions: Ref<BlogPostQueryOptions> = ref({}),
|
||||||
|
{ skipWatchIf = () => false }: { skipWatchIf?: () => boolean } = {}
|
||||||
|
) {
|
||||||
|
const state = reactive<{
|
||||||
|
blogPosts: BlogPostIndexView[]
|
||||||
|
totalCount: number
|
||||||
|
isLoading: boolean
|
||||||
|
isErrored: boolean
|
||||||
|
}>({
|
||||||
|
blogPosts: [],
|
||||||
|
totalCount: 0,
|
||||||
|
isLoading: false,
|
||||||
|
isErrored: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
async function fetch(): Promise<BlogPostIndexView[]> {
|
||||||
|
state.isLoading = true
|
||||||
|
try {
|
||||||
|
const { blogPosts, totalCount } = await blogPostsApi.list(unref(queryOptions))
|
||||||
|
state.isErrored = false
|
||||||
|
state.blogPosts = blogPosts
|
||||||
|
state.totalCount = totalCount
|
||||||
|
return blogPosts
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to fetch blog posts:", error)
|
||||||
|
state.isErrored = true
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
state.isLoading = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => [skipWatchIf(), unref(queryOptions)],
|
||||||
|
async ([skip]) => {
|
||||||
|
if (skip) return
|
||||||
|
|
||||||
|
await fetch()
|
||||||
|
},
|
||||||
|
{ deep: true, immediate: true }
|
||||||
|
)
|
||||||
|
|
||||||
|
return {
|
||||||
|
...toRefs(state),
|
||||||
|
fetch,
|
||||||
|
refresh: fetch,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default useBlogPosts
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
import { computed, reactive, toRefs } from "vue"
|
import { computed, reactive, toRefs } from "vue"
|
||||||
import { DateTime } from "luxon"
|
import { DateTime } from "luxon"
|
||||||
|
import { isNil, isNull, isUndefined } from "lodash"
|
||||||
|
|
||||||
import currentUserApi, { UserRoles, type UserAsShow } from "@/api/current-user-api"
|
import currentUserApi, { UserRoles, type UserAsShow } from "@/api/current-user-api"
|
||||||
|
import { PreferenceKeys, PreferenceValueMap } from "@/api/users/preferences-api"
|
||||||
|
|
||||||
export { UserRoles, type UserAsShow }
|
export { UserRoles, type UserAsShow }
|
||||||
|
|
||||||
@@ -35,6 +37,18 @@ export function useCurrentUser<IsLoaded extends boolean = false>() {
|
|||||||
return state.currentUser?.roles.includes(UserRoles.SYSTEM_ADMIN)
|
return state.currentUser?.roles.includes(UserRoles.SYSTEM_ADMIN)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function getPreference<K extends PreferenceKeys>(key: K): PreferenceValueMap[K] | null {
|
||||||
|
if (isNull(state.currentUser)) return null
|
||||||
|
|
||||||
|
const { preferences } = state.currentUser
|
||||||
|
if (isUndefined(preferences)) return null
|
||||||
|
|
||||||
|
const preference = preferences.find((p) => p.key === key)
|
||||||
|
if (isNil(preference)) return null
|
||||||
|
|
||||||
|
return preference.value as PreferenceValueMap[K]
|
||||||
|
}
|
||||||
|
|
||||||
async function fetch(): Promise<UserAsShow> {
|
async function fetch(): Promise<UserAsShow> {
|
||||||
state.isLoading = true
|
state.isLoading = true
|
||||||
try {
|
try {
|
||||||
@@ -68,6 +82,7 @@ export function useCurrentUser<IsLoaded extends boolean = false>() {
|
|||||||
reset,
|
reset,
|
||||||
// helpers
|
// helpers
|
||||||
isSystemAdmin,
|
isSystemAdmin,
|
||||||
|
getPreference,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
import { type Ref, reactive, toRefs, ref, unref, watch } from "vue"
|
||||||
|
|
||||||
|
import publicBlogPostsApi, {
|
||||||
|
type PublicBlogPostIndexView,
|
||||||
|
type PublicBlogPostWhereOptions,
|
||||||
|
type PublicBlogPostFiltersOptions,
|
||||||
|
type PublicBlogPostQueryOptions,
|
||||||
|
} from "@/api/public/blog-posts-api"
|
||||||
|
|
||||||
|
export {
|
||||||
|
type PublicBlogPostIndexView,
|
||||||
|
type PublicBlogPostWhereOptions,
|
||||||
|
type PublicBlogPostFiltersOptions,
|
||||||
|
type PublicBlogPostQueryOptions,
|
||||||
|
}
|
||||||
|
|
||||||
|
export function usePublicBlogPosts(
|
||||||
|
queryOptions: Ref<PublicBlogPostQueryOptions> = ref({}),
|
||||||
|
{ skipWatchIf = () => false }: { skipWatchIf?: () => boolean } = {}
|
||||||
|
) {
|
||||||
|
const state = reactive<{
|
||||||
|
publicBlogPosts: PublicBlogPostIndexView[]
|
||||||
|
totalCount: number
|
||||||
|
isLoading: boolean
|
||||||
|
isErrored: boolean
|
||||||
|
}>({
|
||||||
|
publicBlogPosts: [],
|
||||||
|
totalCount: 0,
|
||||||
|
isLoading: false,
|
||||||
|
isErrored: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
async function fetch(): Promise<PublicBlogPostIndexView[]> {
|
||||||
|
state.isLoading = true
|
||||||
|
try {
|
||||||
|
const { blogPosts, totalCount } = await publicBlogPostsApi.list(unref(queryOptions))
|
||||||
|
state.isErrored = false
|
||||||
|
state.publicBlogPosts = blogPosts
|
||||||
|
state.totalCount = totalCount
|
||||||
|
return blogPosts
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to fetch blog posts:", error)
|
||||||
|
state.isErrored = true
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
state.isLoading = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => [skipWatchIf(), unref(queryOptions)],
|
||||||
|
async ([skip]) => {
|
||||||
|
if (skip) return
|
||||||
|
|
||||||
|
await fetch()
|
||||||
|
},
|
||||||
|
{ deep: true, immediate: true }
|
||||||
|
)
|
||||||
|
|
||||||
|
return {
|
||||||
|
...toRefs(state),
|
||||||
|
fetch,
|
||||||
|
refresh: fetch,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default usePublicBlogPosts
|
||||||
@@ -1,15 +1,18 @@
|
|||||||
import { isNil, isEmpty } from "lodash"
|
import { isNil, isEmpty } from "lodash"
|
||||||
import { DateTime } from "luxon"
|
import { DateTime } from "luxon"
|
||||||
|
|
||||||
export function formatDate(input: string | Date | undefined): string {
|
export function formatDate(
|
||||||
|
input: string | Date | undefined | null,
|
||||||
|
formatOption: string = "yyyy-MM-dd"
|
||||||
|
): string {
|
||||||
if (isNil(input) || isEmpty(input)) {
|
if (isNil(input) || isEmpty(input)) {
|
||||||
return ""
|
return ""
|
||||||
} else if (typeof input == "string") {
|
} else if (typeof input == "string") {
|
||||||
const parsed = DateTime.fromISO(input, { zone: "utc" })
|
const parsed = DateTime.fromISO(input, { zone: "utc" })
|
||||||
const isMidnight = parsed.hour === 0 && parsed.minute === 0 && parsed.second === 0
|
const isMidnight = parsed.hour === 0 && parsed.minute === 0 && parsed.second === 0
|
||||||
return isMidnight ? parsed.toFormat("yyyy-MM-dd") : parsed.toLocal().toFormat("yyyy-MM-dd")
|
return isMidnight ? parsed.toFormat(formatOption) : parsed.toLocal().toFormat(formatOption)
|
||||||
} else if (input instanceof Date) {
|
} else if (input instanceof Date) {
|
||||||
return DateTime.fromJSDate(input).toLocal().toFormat("yyyy-MM-dd")
|
return DateTime.fromJSDate(input).toLocal().toFormat(formatOption)
|
||||||
} else {
|
} else {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user