feat: add visible flag for works
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
use crate::*;
|
||||
use serde::Serialize;
|
||||
use serde::de::DeserializeOwned;
|
||||
use spacetimedb::AnonymousViewContext;
|
||||
|
||||
const WORK_VISIBLE_DEFAULT: bool = true;
|
||||
|
||||
pub const VISUAL_NOVEL_SOURCE_IDEA: &str = "idea";
|
||||
pub const VISUAL_NOVEL_SOURCE_DOCUMENT: &str = "document";
|
||||
pub const VISUAL_NOVEL_SOURCE_BLANK: &str = "blank";
|
||||
@@ -94,6 +95,9 @@ pub struct VisualNovelWorkProfileRow {
|
||||
pub(crate) created_at: Timestamp,
|
||||
pub(crate) updated_at: Timestamp,
|
||||
pub(crate) published_at: Option<Timestamp>,
|
||||
// ???????????????????????????????
|
||||
#[default(WORK_VISIBLE_DEFAULT)]
|
||||
pub(crate) visible: bool,
|
||||
}
|
||||
|
||||
/// 视觉小说运行态 run 表。
|
||||
@@ -178,6 +182,7 @@ pub fn visual_novel_gallery_view(ctx: &AnonymousViewContext) -> Vec<VisualNovelG
|
||||
.visual_novel_work_profile()
|
||||
.by_visual_novel_work_publication_status()
|
||||
.filter(VISUAL_NOVEL_PUBLICATION_PUBLISHED)
|
||||
.filter(|row| row.visible)
|
||||
.filter_map(|row| match build_gallery_view_row(&row) {
|
||||
Ok(item) => Some(item),
|
||||
Err(error) => {
|
||||
@@ -421,13 +426,13 @@ pub struct VisualNovelRuntimeEventProcedureResult {
|
||||
pub error_message: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, SpacetimeType)]
|
||||
#[derive(Clone, Debug, PartialEq, serde::Serialize, SpacetimeType)]
|
||||
pub struct VisualNovelJsonField {
|
||||
pub key: String,
|
||||
pub value: VisualNovelJsonValue,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, SpacetimeType)]
|
||||
#[derive(Clone, Debug, PartialEq, serde::Serialize, SpacetimeType)]
|
||||
pub enum VisualNovelJsonValue {
|
||||
Null,
|
||||
Bool(bool),
|
||||
@@ -437,7 +442,7 @@ pub enum VisualNovelJsonValue {
|
||||
Object(Vec<VisualNovelJsonField>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, SpacetimeType)]
|
||||
#[derive(Clone, Debug, PartialEq, serde::Serialize, SpacetimeType)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct VisualNovelAgentMessageSnapshot {
|
||||
pub message_id: String,
|
||||
@@ -448,7 +453,7 @@ pub struct VisualNovelAgentMessageSnapshot {
|
||||
pub created_at_micros: i64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, SpacetimeType)]
|
||||
#[derive(Clone, Debug, PartialEq, serde::Serialize, SpacetimeType)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct VisualNovelAgentSessionSnapshot {
|
||||
pub session_id: String,
|
||||
@@ -468,7 +473,7 @@ pub struct VisualNovelAgentSessionSnapshot {
|
||||
pub updated_at_micros: i64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, SpacetimeType)]
|
||||
#[derive(Clone, Debug, PartialEq, serde::Serialize, SpacetimeType)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct VisualNovelWorkSnapshot {
|
||||
pub work_id: String,
|
||||
@@ -490,7 +495,7 @@ pub struct VisualNovelWorkSnapshot {
|
||||
pub published_at_micros: Option<i64>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, SpacetimeType)]
|
||||
#[derive(Clone, Debug, PartialEq, serde::Serialize, SpacetimeType)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct VisualNovelRuntimeHistoryEntrySnapshot {
|
||||
pub entry_id: String,
|
||||
@@ -506,7 +511,7 @@ pub struct VisualNovelRuntimeHistoryEntrySnapshot {
|
||||
pub created_at_micros: i64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, SpacetimeType)]
|
||||
#[derive(Clone, Debug, PartialEq, serde::Serialize, SpacetimeType)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct VisualNovelRunSnapshot {
|
||||
pub run_id: String,
|
||||
@@ -526,7 +531,7 @@ pub struct VisualNovelRunSnapshot {
|
||||
pub updated_at_micros: i64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, SpacetimeType)]
|
||||
#[derive(Clone, Debug, PartialEq, serde::Serialize, SpacetimeType)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct VisualNovelRuntimeEventSnapshot {
|
||||
pub event_id: String,
|
||||
@@ -1029,6 +1034,7 @@ fn compile_visual_novel_work_profile_tx(
|
||||
created_at: compiled_at,
|
||||
updated_at: compiled_at,
|
||||
published_at: None,
|
||||
visible: true,
|
||||
};
|
||||
upsert_work(ctx, work);
|
||||
replace_session(
|
||||
@@ -1731,6 +1737,7 @@ fn clone_work(row: &VisualNovelWorkProfileRow) -> VisualNovelWorkProfileRow {
|
||||
created_at: row.created_at,
|
||||
updated_at: row.updated_at,
|
||||
published_at: row.published_at,
|
||||
visible: row.visible,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1971,7 +1978,7 @@ fn parse_json<T: DeserializeOwned>(value: &str, label: &str) -> Result<T, String
|
||||
serde_json::from_str(value).map_err(|error| format!("{label} 非法: {error}"))
|
||||
}
|
||||
|
||||
fn to_json_string<T: Serialize>(value: &T) -> String {
|
||||
fn to_json_string<T: serde::Serialize>(value: &T) -> String {
|
||||
serde_json::to_string(value).unwrap_or_else(|_| "{}".to_string())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user