1
0
Fork 0
mirror of https://github.com/Nutomic/ibis.git synced 2024-11-22 13:31:08 +00:00
This commit is contained in:
Felix Ableitner 2024-11-20 10:48:07 +01:00
parent f9f83974d3
commit 14e6382765
7 changed files with 58 additions and 32 deletions

View file

@ -1,8 +1,13 @@
use crate::{
backend::{database::IbisData, error::MyResult, federation::activities::follow::Follow},
common::{
DbInstance, FollowInstance, FollowInstanceResponse, GetInstance, InstanceView,
LocalUserView, ResolveObject,
DbInstance,
FollowInstance,
FollowInstanceResponse,
GetInstance,
InstanceView,
LocalUserView,
ResolveObject,
},
};
use activitypub_federation::{config::Data, fetch::object_id::ObjectId};

View file

@ -7,7 +7,13 @@ use crate::{
utils::generate_activity_id,
},
common::{
utils::http_protocol_str, Auth, DbArticle, DbInstance, DbPerson, EditVersion, AUTH_COOKIE,
utils::http_protocol_str,
Auth,
DbArticle,
DbInstance,
DbPerson,
EditVersion,
AUTH_COOKIE,
MAIN_PAGE_NAME,
},
frontend::app::{shell, App},
@ -26,7 +32,8 @@ use axum::{
middleware::Next,
response::{IntoResponse, Response},
routing::get,
Router, ServiceExt,
Router,
ServiceExt,
};
use axum_extra::extract::CookieJar;
use axum_macros::debug_middleware;
@ -37,7 +44,8 @@ use diesel::{
};
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
use federation::objects::{
articles_collection::local_articles_url, instance_collection::linked_instances_url,
articles_collection::local_articles_url,
instance_collection::linked_instances_url,
};
use leptos::prelude::*;
use leptos_axum::{generate_route_list, LeptosRoutes};

View file

@ -246,7 +246,7 @@ pub struct FollowInstance {
#[derive(Deserialize, Serialize, Debug)]
pub struct FollowInstanceResponse {
pub success: bool
pub success: bool,
}
#[derive(Deserialize, Serialize, Clone, Debug)]

View file

@ -2,19 +2,38 @@ use crate::{
common::{
newtypes::{ArticleId, ConflictId},
utils::http_protocol_str,
ApiConflict, ApproveArticleForm, ArticleView, CreateArticleForm, DbArticle, DbInstance,
DbPerson, DeleteConflictForm, EditArticleForm, FollowInstance, FollowInstanceResponse,
ForkArticleForm, GetArticleForm, GetInstance, GetUserForm, InstanceView, ListArticlesForm,
LocalUserView, LoginUserForm, Notification, ProtectArticleForm, RegisterUserForm,
ResolveObject, SearchArticleForm, SiteView,
ApiConflict,
ApproveArticleForm,
ArticleView,
CreateArticleForm,
DbArticle,
DbInstance,
DbPerson,
DeleteConflictForm,
EditArticleForm,
FollowInstance,
FollowInstanceResponse,
ForkArticleForm,
GetArticleForm,
GetInstance,
GetUserForm,
InstanceView,
ListArticlesForm,
LocalUserView,
LoginUserForm,
Notification,
ProtectArticleForm,
RegisterUserForm,
ResolveObject,
SearchArticleForm,
SiteView,
},
frontend::error::MyResult,
};
use anyhow::anyhow;
use http::*;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
use std::sync::LazyLock;
use std::{fmt::Debug, sync::LazyLock};
use url::Url;
pub static CLIENT: LazyLock<ApiClient> = LazyLock::new(|| {
@ -39,12 +58,9 @@ pub struct ApiClient {
impl ApiClient {
#[cfg(feature = "ssr")]
pub fn new(client: reqwest::Client, hostname_: Option<String>) -> Self {
let mut hostname;
let ssl;
use leptos::config::get_config_from_str;
let leptos_options = get_config_from_str(include_str!("../../Cargo.toml")).unwrap();
hostname = leptos_options.site_addr.to_string();
ssl = false;
let mut hostname = leptos_options.site_addr.to_string();
// required for tests
if let Some(hostname_) = hostname_ {
hostname = hostname_;
@ -52,7 +68,7 @@ impl ApiClient {
Self {
client,
hostname,
ssl,
ssl: false,
}
}
#[cfg(not(feature = "ssr"))]
@ -177,10 +193,7 @@ impl ApiClient {
}
pub async fn logout(&self) -> MyResult<()> {
Ok(self
.get("/api/v1/account/logout", None::<()>)
.await
.unwrap())
self.get("/api/v1/account/logout", None::<()>).await
}
pub async fn fork_article(&self, form: &ForkArticleForm) -> MyResult<ArticleView> {
@ -273,12 +286,13 @@ impl ApiClient {
let path_with_endpoint = self.request_endpoint(path);
let path = if method == Method::GET {
// Cannot pass the struct directly but need to convert it manually
// https://github.com/rustwasm/gloo/issues/378
let query = serde_urlencoded::to_string(&params).unwrap();
format!("{path_with_endpoint}?{query}")
} else {
path_with_endpoint
};
log::info!("{path}");
let builder = RequestBuilder::new(&path)
.method(method.clone())
.abort_signal(abort_signal.as_ref())

View file

@ -6,8 +6,12 @@ use crate::{
dark_mode::DarkMode,
pages::{
article::{
actions::ArticleActions, create::CreateArticle, edit::EditArticle,
history::ArticleHistory, list::ListArticles, read::ReadArticle,
actions::ArticleActions,
create::CreateArticle,
edit::EditArticle,
history::ArticleHistory,
list::ListArticles,
read::ReadArticle,
},
diff::EditDiff,
instance::{details::InstanceDetails, list::ListInstances},
@ -57,7 +61,7 @@ impl<T: Default + Send + Sync> DefaultResource<T> for Resource<T> {
}
pub fn shell(options: LeptosOptions) -> impl IntoView {
view! {
<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />

View file

@ -51,7 +51,7 @@ pub fn Nav() -> impl IntoView {
<A href="/article/list">"Articles"</A>
</li>
<Transition>
<Show when=move || is_logged_in()>
<Show when=is_logged_in>
<li>
<A href="/article/create">"Create Article"</A>
</li>

View file

@ -32,9 +32,6 @@ pub fn ListArticles() -> impl IntoView {
class="btn rounded-r-none"
node_ref=button_only_local
on:click=move |_| {
// TODO
//button_all.get().map(|c| c.class("btn-primary", false));
//button_only_local.get().map(|c| c.class("btn-primary", true));
set_only_local.set(true);
}
/>
@ -44,8 +41,6 @@ pub fn ListArticles() -> impl IntoView {
class="btn btn-primary rounded-l-none"
node_ref=button_all
on:click=move |_| {
//button_all.get().map(|c| c.class("btn-primary", true));
//button_only_local.get().map(|c| c.class("btn-primary", false));
set_only_local.set(false);
}
/>