Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

feat: enable to set theme for the scene #67

Merged
merged 30 commits into from Sep 10, 2021
Merged

Conversation

issmail-basel
Copy link
Contributor

Overview

Add Scene theme option, users can define the basic theme which is used for all components on the scene.

What I've done

  • Add pre made theme colors
  • Add option to change used theme/colors in scene tab
  • Calculate colors for custom theme

How I tested

  • Change options in scene tab -> Publish Theme
  • Choose pre made theme or custom theme with color preferences
  • Check changes in the Editor, Preview page and published project

Screenshot

2021-08-23_09-48_1
2021-08-23_09-49
2021-08-23_09-50

Which point I want you to review particularly

  • Ways to improve code quality
  • Any missing styles

@netlify
Copy link

netlify bot commented Aug 23, 2021

✔️ Deploy Preview for reearth-web ready!

🔨 Explore the source changes: 4ff8efd

🔍 Inspect the deploy log: https://app.netlify.com/sites/reearth-web/deploys/613af9a8a19b930008e5fe5e

😎 Browse the preview: https://deploy-preview-67--reearth-web.netlify.app

@issmail-basel issmail-basel changed the title Scene theme front feat: enable to set theme for the scene Aug 23, 2021
@codecov
Copy link

codecov bot commented Aug 23, 2021

Codecov Report

Merging #67 (4ff8efd) into main (481df59) will decrease coverage by 0.63%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #67      +/-   ##
==========================================
- Coverage   58.10%   57.46%   -0.64%     
==========================================
  Files          40       44       +4     
  Lines         685      703      +18     
  Branches       96      104       +8     
==========================================
+ Hits          398      404       +6     
- Misses        245      257      +12     
  Partials       42       42              
Impacted Files Coverage Δ
src/theme/colors.ts 100.00% <ø> (ø)
src/theme/publishTheme/index.ts 20.00% <20.00%> (ø)
src/theme/publishTheme/dark.ts 100.00% <100.00%> (ø)
src/theme/publishTheme/forest.ts 100.00% <100.00%> (ø)
src/theme/publishTheme/light.ts 100.00% <100.00%> (ø)

@issmail-basel
Copy link
Contributor Author

@lavalse , what about menu colors, should they stay dark?
if not please update figma to take care of missing parts
2021-08-23_09-54

@lavalse
Copy link
Member

lavalse commented Aug 24, 2021

@issmail-basel For the menu widgets, because we will refine the logic in the future. So for now,
image
this is the solution. They should also use the theme by default I think. Is that ok?

Copy link
Member

@rot1024 rot1024 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a somewhat roundabout implementation:

  • Current: SceneProperty in Visualizer -up-> Global theme context -down-> Visualizer -down-> Each component (What was inside goes outside and then back inside again)
  • Should be: Visualizer (SceneProperty) -down-> Each component

Since public themes are used only inside Visualizer, they do not depend on the global theme context (@reearth/theme) and should be used by defining a premade theme inside Visualizer.

src/components/molecules/Visualizer/Engine/index.tsx Outdated Show resolved Hide resolved
@issmail-basel issmail-basel marked this pull request as ready for review August 30, 2021 07:15
@@ -38,10 +38,12 @@ export type Props = {
button: Button;
menuItems?: MenuItem[];
pos: Position;
sceneProperty?: any;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sceneProperty?: any;
sceneProperty?: SceneProperty;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also needs the SceneProperty imported

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still isn't resolved.

export default (seneThemeOptions?: ReTheme) => {
const [publishedTheme, setPublishedTheme] = useState<PublishTheme>(dark);
function addAlpha(color?: string, opacity?: number): string {
// coerce values so ti is between 0 and 1.
Copy link
Member

@KaWaite KaWaite Aug 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// coerce values so ti is between 0 and 1.
// coerce values so it is between 0 and 1.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still doesn't seem to be updated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not resolved

themeBackgroundColor?: string;
};

export default (seneThemeOptions?: ReTheme) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seneThemeOptions => sceneThemeOptions

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not resolved

@@ -174,22 +194,23 @@ const Title = styled(Text)`
}
`;

const StyledIcon = styled(Icon)`
color: ${props => props.theme.main.text};
const StyledIcon = styled(Icon)<{ publishedTheme: PublishTheme }>`
Copy link
Member

@KaWaite KaWaite Aug 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, one more thing. In components like this StyledIcon where all you are using is mainIcon from publishedTheme, can you pass JUST what you need, rather than the whole publishedTheme object.
In this case you could pass a color=publishedTheme.mainIcon prop instead.
Please update other places where this applies.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't addressed. Please let me know if you don't catch what I mean and I can explain more!

@@ -160,7 +179,8 @@ const Current = styled(Flex)`
}
`;

const Title = styled(Text)`
const Title = styled(Text)<{ color: string }>`
color: ${({ color }) => color}!important;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The !important isn't necessary. Above where you use Title just pass customColor and you should be good to go!
ie

<Title color={publishedTheme.mainText} size="m" weight="bold" customColor>
....

KaWaite
KaWaite previously approved these changes Sep 1, 2021
Copy link
Member

@KaWaite KaWaite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one change requested and then LGTM! I'll approve but please make the change!

Copy link
Member

@rot1024 rot1024 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usePublicTheme seems redundant, and I don't see the need to use Hooks. It's enough to simply have the following code:

@reearth/theme/public.ts:

export type Theme = { themeBackgroundColor: string, /*...*/ };
export type ThemeType = "dark" | "light" | "forest";
export type ThemeConfig = Partial<Theme> & { type?: ThemeType | "custom" };

const defaultTheme: ThemeType = "dark";
const premade: {[key in ThemeType]: Theme } = {
  dark: { ... },
  light: { ... },
  forest: { ... }
};

export function publicTheme(theme?: ThemeConfig): Theme {
  return theme?.type === "custom"
    ? { ...premade[defaultTheme], ...theme }
    : premade[theme?.type || defaultTheme];
}

Usage:

import { publicTheme } from "@reearth/theme";

function Storytelling({ sceneProperty }) {
  const theme = publicTheme(sceneProperty?.theme);

  // use theme!
}

This code doesn't use hooks so the code is very clean.

@issmail-basel
Copy link
Contributor Author

@rot1024 , thank you for your comment.
but hooks are needed to detect theme changes.
Your code is working when the component is rendered for the first time, but if we change the pre-made theme to (light for example) it won't detect the change.
That's why I've used hooks (useEffect).
What do you recommend to solve this issue? Should I keep using hooks?

@rot1024
Copy link
Member

rot1024 commented Sep 7, 2021

It's strange. In my code, theme should be switched when sceneProperty is updated. Let me try my code in this PR.

@rot1024
Copy link
Member

rot1024 commented Sep 8, 2021

OK, and I tried and I understand hooks is needed because custom theme uses object and it's needed to prevent useless re-rendering. But there are rooms to be refactored so I did.

Please check:

scene-theme-front...scene-theme-front-refactor

Points:

  • useState and useEffect can be replaced with useMemo
  • Separate the logic into hooks and a function that returns a theme object
  • Non-unified name: PublishTheme and PublishedTheme, I unified them with PublishTheme
  • Simpler file name and fewer files at src/theme

@issmail-basel issmail-basel merged commit 58e6707 into main Sep 10, 2021
@issmail-basel issmail-basel deleted the scene-theme-front branch September 10, 2021 06:40
keiya01 pushed a commit that referenced this pull request Apr 25, 2023
* feat: tag system domain models (#39)

* feat: tag system domain models

* refactor: * add tag interface * tag -> group and tag->item conversation

* testing: generate test cases for the tagID

* resolve notes

* fix unit tests errors

* add NewId test code
fix NewId func

* add more test cases
refactor some parts

* feat: tag system data-layer (mongo) (#44)

* feat: tag system data-layer (mongo)

* remove len > 0 check

* goimport

* Update pkg/tag/group_builder.go

Co-authored-by: rot1024 <aayhrot@gmail.com>

* Update pkg/tag/item_builder.go

Co-authored-by: rot1024 <aayhrot@gmail.com>

* rename itemFrom and groupFrom funcs

Co-authored-by: rot1024 <aayhrot@gmail.com>

* feat: create tag group and tag item (#45)

* tag item and group schema

* feat: creat tags (GQL schema)

* tag items and tag groups resolvers

* datalayer (dummy memory) and usecases

* receive list by reference

* check if nil for list

* resolve notes

* generate new models

* feat: memory infrastructure (#46)

* refactor: implement memory infrastructure

* test: implement memory infrastructure test cases

* test: fix FindByScene test case

* feat: attach/detach tag from layer (#50)

* tag item and group schema

* feat: creat tags (GQL schema)

* tag items and tag groups resolvers

* datalayer (dummy memory) and usecases

* receive list by reference

* check if nil for list

* feat: introduce tags to layers

* feat: attach/detach tags from layers

* fix imports

* refactor: resolve notes

* test: test units for tags

* refactor: resolve notes

* feat: attach/detach tag item from group (#52)

* refactor: transform group tags list to reference

* feat: attach/detach tags

* refactor: use params as use-case input

* test: mongodoc testing (#61)

* test: mongodoc testing

* resolve notes

* feat: remove tag (#58)

* feat: remove a tag (init)

* feat: remove tag

* feat: remove tag usecase and infra

* resolve notes

* feat: tag system queries (#54)

* feat: tag system queries

* resolve notes

* feat: update tag (#49)

* tag item and group schema

* feat: creat tags (GQL schema)

* tag items and tag groups resolvers

* datalayer (dummy memory) and usecases

* receive list by reference

* check if nil for list

* feat: rename tag group

* refactor: rename -> update

* resolve notes

* resolve notes

* change find by id func return type

* Merge branch 'tag-system' of https://github.com/reearth/reearth-backend into tag/update-group-label

# Conflicts:
#	internal/adapter/gql/generated.go
#	internal/adapter/gql/gqlmodel/convert_tag.go

* fix testing

* resolve notes

* resolve notes

* resolve notes

Co-authored-by: HideBa <baba.papa1120.ba@gmail.com>
Co-authored-by: rot1024 <aayhrot@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
5 participants