Skip to content

Commit

Permalink
Merge branch 'fix/markdown-again' of github.com:Satellite-im/Uplink i…
Browse files Browse the repository at this point in the history
…nto fix/markdown-again
  • Loading branch information
InfamousVague committed Oct 17, 2023
2 parents 58552f5 + d17d3dc commit f17ffd7
Show file tree
Hide file tree
Showing 19 changed files with 281 additions and 49 deletions.
14 changes: 12 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions common/src/state/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub enum Action<'a> {
#[display(fmt = "SetExtensionEnabled")]
SetExtensionEnabled(String, bool),
// UI
#[display(fmt = "SetDevSettings {_0}")]
SetDevSettings(bool),
#[display(fmt = "SetAccentColor")]
SetAccentColor((u8, u8, u8)),
#[display(fmt = "ClearAccentColor")]
Expand Down
7 changes: 7 additions & 0 deletions common/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ impl State {
Action::ClearAccentColor => {
self.ui.accent_color = None;
}
Action::SetDevSettings(enabled) => {
self.set_show_dev_settings(enabled);
}
Action::SetExtensionEnabled(extension, enabled) => {
if enabled {
self.ui.extensions.enable(extension);
Expand Down Expand Up @@ -1350,6 +1353,10 @@ impl State {}

// for settings
impl State {
fn set_show_dev_settings(&mut self, value: bool) {
self.ui.show_dev_settings = value;
}

/// Sets the user's language.
fn set_language(&mut self, string: &str) {
self.settings.language = string.to_string();
Expand Down
11 changes: 7 additions & 4 deletions common/src/state/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ pub struct WindowMeta {
pub focused: bool,
pub maximized: bool,
pub minimized: bool,
pub full_screen: bool,
pub minimal_view: bool, // We can use this to detect mobile or portrait mode
}

Expand Down Expand Up @@ -195,8 +196,8 @@ pub struct UI {
pub active_welcome: bool,
pub sidebar_hidden: bool,
pub window_maximized: bool,
pub window_width: u32,
pub window_height: u32,
pub window_size: Option<(u32, u32)>,
pub window_position: Option<(i32, i32)>,
pub metadata: WindowMeta,
#[serde(default = "default_emojis")]
pub emojis: EmojiCounter,
Expand All @@ -215,6 +216,7 @@ pub struct UI {
pub file_previews: HashMap<Uuid, WindowId>,
#[serde(default = "bool_true")]
pub show_settings_welcome: bool,
pub show_dev_settings: bool,
// Cached username used in login page
pub cached_username: Option<String>,
#[serde(skip)]
Expand All @@ -236,8 +238,8 @@ impl Default for UI {
active_welcome: Default::default(),
sidebar_hidden: Default::default(),
window_maximized: Default::default(),
window_width: Default::default(),
window_height: Default::default(),
window_size: None,
window_position: None,
metadata: Default::default(),
emojis: default_emojis(),
emoji_destination: Default::default(),
Expand All @@ -247,6 +249,7 @@ impl Default for UI {
extensions: Default::default(),
file_previews: Default::default(),
show_settings_welcome: true,
show_dev_settings: false,
cached_username: Default::default(),
ignore_focus: Default::default(),
transform_markdown_text: true,
Expand Down
3 changes: 2 additions & 1 deletion kit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
emojis = "0.5.2"
regex = "1.8.4"
scraper = "0.17.1"
chrono = { workspace = true }
Expand All @@ -24,7 +25,7 @@ linkify = { workspace = true }
reqwest = { workspace = true }
base64 = { workspace = true }
mime = { workspace = true }
markdowns = { git = "https://github.com/satellite-im/markdowns", rev = "170a3f7c5be57e09739713c07762a14217cd2805" }
markdowns = { git = "https://github.com/satellite-im/markdowns", rev = "aea02b46e22f85939ece8215681a7b0e988a74f5" }
unic-segment = "0.9"
unic-emoji-char = "0.9"

Expand Down
36 changes: 26 additions & 10 deletions kit/src/components/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,14 +391,16 @@ fn is_only_emojis(input: &str) -> bool {
let input = input.trim();
let mut indices = unic_segment::GraphemeIndices::new(input);
indices.all(|(_, grapheme)| {
grapheme.trim().chars().all(|char| {
is_emoji(char)
|| is_emoji_component(char)
|| is_emoji_modifier(char)
|| is_emoji_modifier_base(char)
|| is_emoji_presentation(char)
grapheme.trim().chars().all(|c| {
is_emoji(c)
|| is_emoji_component(c)
|| is_emoji_modifier(c)
|| is_emoji_modifier_base(c)
|| is_emoji_presentation(c)
// some emojis are multiple emojis joined by this character
|| char == '\u{200d}'
|| c == '\u{200d}'
// failsafe
|| emojis::get(&String::from(c)).is_some()
})
})
}
Expand Down Expand Up @@ -438,9 +440,23 @@ mod tests {
}

#[test]
fn test_double_emoji() {
let input = "😮😮";
let expected = "<span class=\"single-emoji\">😮😮</span>";
fn test_triple_emoji() {
let input = "😮😮👨‍👩‍👦‍👦";
let expected = "<span class=\"single-emoji\">😮😮👨‍👩‍👦‍👦</span>";
assert_eq!(&transform_only_emoji(input), expected);
}

#[test]
fn test_multiple_emoji() {
let input = "🤓😎🥸🤓";
let expected = "<span class=\"single-emoji\">🤓😎🥸🤓</span>";
assert_eq!(&transform_only_emoji(input), expected);
}

#[test]
fn test_multiple_emoji2() {
let input = "🤓😎🤓🤓";
let expected = "<span class=\"single-emoji\">🤓😎🤓🤓</span>";
assert_eq!(&transform_only_emoji(input), expected);
}

Expand Down
29 changes: 29 additions & 0 deletions kit/src/components/message_reply/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,35 @@
font-size: var(--text-size-less);
border-radius: var(--border-radius-more);
border-bottom-right-radius: var(--border-radius-less);

h1, h2, h3, h4, h5 {
font-weight: bold;
}

h1 {
font-size: 2rem;
}
h2 {
font-size: 1.75rem;
}
h3 {
font-size: 1.5rem;
}
h4 {
font-size: 1.25rem;
}

s {
text-decoration: line-through;
}

strong {
font-weight: bold;
}

em {
font-style: italic;
}
}
.content {
position: relative;
Expand Down
29 changes: 29 additions & 0 deletions kit/src/components/user/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,35 @@
-webkit-line-clamp: 2;
line-clamp: 2;
-webkit-box-orient: vertical;

h1, h2, h3, h4, h5 {
font-weight: bold;
}

h1 {
font-size: 2rem;
}
h2 {
font-size: 1.75rem;
}
h3 {
font-size: 1.5rem;
}
h4 {
font-size: 1.25rem;
}

s {
text-decoration: line-through;
}

strong {
font-weight: bold;
}

em {
font-style: italic;
}
}
.badge {
position: absolute;
Expand Down
6 changes: 4 additions & 2 deletions kit/src/layout/chatbar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use dioxus_elements::input_data::keyboard_types::Code;
use warp::constellation::file::File;

use crate::{
components::{embeds::file_embed::FileEmbed, message_typing::MessageTyping},
components::{embeds::file_embed::FileEmbed, message_typing::MessageTyping, message::format_text},
elements::{button::Button, label::Label, textarea, Appearance},
};

Expand Down Expand Up @@ -53,11 +53,13 @@ pub struct ReplyProps<'a> {
attachments: Option<Vec<File>>,
onclose: EventHandler<'a>,
children: Element<'a>,
markdown: Option<bool>
}

#[allow(non_snake_case)]
pub fn Reply<'a>(cx: Scope<'a, ReplyProps<'a>>) -> Element<'a> {
let remote = cx.props.remote.unwrap_or_default();
let message = format_text(&cx.props.message, cx.props.markdown.unwrap_or_default());

let has_attachments = cx
.props
Expand Down Expand Up @@ -107,7 +109,7 @@ pub fn Reply<'a>(cx: Scope<'a, ReplyProps<'a>>) -> Element<'a> {
aria_label: {
format_args!("reply-text-message{}", if remote { "-remote" } else { "" })
},
"{cx.props.message}"
dangerous_inner_html: "{message}",
has_attachments.then(|| {
rsx!(
attachment_list.map(|list| {
Expand Down
29 changes: 29 additions & 0 deletions kit/src/layout/chatbar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,35 @@
text-overflow: ellipsis;
overflow: hidden;
text-align: left;

h1, h2, h3, h4, h5 {
font-weight: bold;
}

h1 {
font-size: 2rem;
}
h2 {
font-size: 1.75rem;
}
h3 {
font-size: 1.5rem;
}
h4 {
font-size: 1.25rem;
}

s {
text-decoration: line-through;
}

strong {
font-weight: bold;
}

em {
font-style: italic;
}
}
.btn-wrap {
position: absolute;
Expand Down
2 changes: 1 addition & 1 deletion native_extensions/emoji_selector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dioxus-desktop = { workspace = true }
extensions = { workspace = true }
common = { workspace = true }
kit = { workspace = true }
emojis = "0.5.2"
emojis = "0.6.1"
once_cell = { workspace = true }
warp = { workspace = true}
uuid = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions native_extensions/emoji_selector/src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
flex: 1;
min-height: 0;
overflow-y: auto;
overflow-x: hidden;
}

#emoji_selector .emoji {
Expand Down
5 changes: 3 additions & 2 deletions ui/src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ pub(crate) fn use_boostrap<'a>(
state.ui.overlays.push(window);
}

let size = desktop.webview.inner_size();
let size = scaled_window_size(desktop.webview.inner_size(), desktop);
// Update the window metadata now that we've created a window
let window_meta = WindowMeta {
focused: desktop.is_focused(),
maximized: desktop.is_maximized(),
minimized: desktop.is_minimized(),
minimal_view: size.width < get_window_minimal_width(desktop),
full_screen: state.ui.metadata.full_screen,
minimal_view: size.width < 600,
};
state.ui.metadata = window_meta;
state.set_warp_ch(WARP_CMD_CH.tx.clone());
Expand Down
7 changes: 5 additions & 2 deletions ui/src/components/settings/sidebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub fn Sidebar<'a>(cx: Scope<'a, Props<'a>>) -> Element<'a> {
..UIRoute::default()
};

let routes = vec![
let mut routes = vec![
profile,
general,
messages,
Expand All @@ -153,11 +153,14 @@ pub fn Sidebar<'a>(cx: Scope<'a, Props<'a>>) -> Element<'a> {
extensions,
accessibility,
notifications,
developer,
about,
licenses,
];

if state.read().ui.show_dev_settings {
routes.push(developer);
}

let active_route = routes[0].clone();

cx.render(rsx!(
Expand Down
Loading

0 comments on commit f17ffd7

Please sign in to comment.