Skip to content

Commit

Permalink
Merge 073a69c into 883633a
Browse files Browse the repository at this point in the history
  • Loading branch information
lauti7 committed Oct 9, 2023
2 parents 883633a + 073a69c commit c5df478
Show file tree
Hide file tree
Showing 103 changed files with 11,067 additions and 1,127 deletions.
12 changes: 3 additions & 9 deletions src/__data__/categories.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import { CategoryAttributes } from "../entities/Category/types"

export const categories: CategoryAttributes[] = [
export const categoriesWithPlacesCount = [
{
name: "Art",
active: true,
created_at: new Date("2023-04-01T04:53:07.000Z"),
updated_at: new Date("2023-04-01T04:53:07.000Z"),
count: "10",
},
{
name: "music",
active: true,
created_at: new Date("2023-04-01T04:53:07.000Z"),
updated_at: new Date("2023-04-01T04:53:07.000Z"),
count: "10",
},
]
4 changes: 0 additions & 4 deletions src/__data__/placeGenesisPlaza.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,15 @@ export const placeGenesisPlaza: PlaceAttributes = {
like_score: 0,
highlighted: false,
highlighted_image: null,
featured: false,
featured_image: null,
disabled: false,
updated_at: new Date("2023-03-28T18:37:39.918Z"),
categories: [],
world: false,
world_name: null,
title: "Genesis Plaza",
description:
"Jump in to strike up a chat with other visitors, retake the commands tutorial with a cute floating robot, or dive into the swirling portal to get to Decentraland's visitor center.",
owner: null,
image: "https://decentraland.org/images/thumbnail/genesis-plaza.png",
tags: ["plaza"],
base_position: "-9,-9",
positions: [
"-1,-1",
Expand Down
5 changes: 1 addition & 4 deletions src/__data__/placeGenesisPlazaWithAggregatedAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const placeGenesisPlazaWithAggregatedAttributes: AggregatePlaceAttributes
"Jump in to strike up a chat with other visitors, retake the commands tutorial with a cute floating robot, or dive into the swirling portal to get to Decentraland's visitor center.",
image: "https://localhost:8000/images/places/genesis_plaza.jpg",
owner: null,
tags: [],
positions: [
"-1,-1",
"-1,-2",
Expand Down Expand Up @@ -408,12 +407,10 @@ export const placeGenesisPlazaWithAggregatedAttributes: AggregatePlaceAttributes
like_score: 0,
highlighted: true,
highlighted_image: "/images/places/genesis_plaza_banner.jpg",
featured: false,
featured_image: null,
user_favorite: false,
user_like: false,
user_dislike: false,
categories: [],
category_ids: [],
world: false,
world_name: null,
deployed_at: new Date("2022-11-14T17:22:05.307Z"),
Expand Down
4 changes: 0 additions & 4 deletions src/__data__/placeRoad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,14 @@ export const placeRoad: PlaceAttributes = {
like_score: 0,
highlighted: false,
highlighted_image: null,
featured: false,
featured_image: null,
disabled: false,
updated_at: new Date("2023-03-28T18:37:39.918Z"),
categories: [],
world: false,
world_name: null,
title: "Road at -89,11 (open road OpenRoad_C)",
description: null,
owner: null,
image: "https://decentraland.org/images/thumbnail/road.png",
tags: ["road"],
base_position: "-89,11",
positions: ["-89,11"],
contact_name: "Decentraland Foundation",
Expand Down
12 changes: 0 additions & 12 deletions src/__data__/world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const worldPlaceParalax: PlaceAttributes = {
image:
"https://api.decentraland.org/v2/map.png?height=1024&width=1024&selected=0%2C0&center=0%2C0&size=20",
owner: null,
tags: [],
positions: ["0,0"],
base_position: "0,0",
contact_name: "paralax",
Expand All @@ -31,12 +30,9 @@ export const worldPlaceParalax: PlaceAttributes = {
likes: 0,
dislikes: 0,
like_score: 0,
categories: [],
like_rate: 0.5,
highlighted: false,
highlighted_image: null,
featured: false,
featured_image: null,
world: true,
world_name: "paralax.dcl.eth",
deployed_at: new Date("2023-03-28T13:05:45.437Z"),
Expand All @@ -51,7 +47,6 @@ export const worldPlaceParalaxWithAggregated: AggregatePlaceAttributes = {
image:
"https://api.decentraland.org/v2/map.png?height=1024&width=1024&selected=0%2C0&center=0%2C0&size=20",
owner: null,
tags: [],
positions: ["0,0"],
base_position: "0,0",
contact_name: "paralax",
Expand All @@ -64,13 +59,10 @@ export const worldPlaceParalaxWithAggregated: AggregatePlaceAttributes = {
favorites: 0,
likes: 0,
dislikes: 0,
categories: [],
like_rate: 0.5,
like_score: 0,
highlighted: false,
highlighted_image: null,
featured: false,
featured_image: null,
world: true,
world_name: "paralax.dcl.eth",
deployed_at: new Date("2023-03-28T13:05:45.437Z"),
Expand Down Expand Up @@ -199,7 +191,6 @@ export const worldPlaceTemplegame: AggregatePlaceAttributes = {
image:
"https://peer.decentraland.org/content/contents/bafkreiag7fylur5qlntcxb2oyaw3asmchxsbhoxnw6iipayfgj4wwmqkli",
owner: null,
tags: [],
positions: [
"-1,0",
"-1,1",
Expand Down Expand Up @@ -273,13 +264,10 @@ export const worldPlaceTemplegame: AggregatePlaceAttributes = {
favorites: 0,
likes: 0,
dislikes: 0,
categories: [],
like_rate: 0.5,
like_score: 0,
highlighted: false,
highlighted_image: null,
featured: false,
featured_image: null,
world: true,
world_name: "templegame.dcl.eth",
deployed_at: new Date("2023-05-16T15:44:26.395Z"),
Expand Down
20 changes: 19 additions & 1 deletion src/api/Places.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ export default class Places extends API {

async getPlacesFeatured(options?: { limit: number; offset: number }) {
return this.getPlaces({
only_featured: true,
...options,
category_ids: ["featured"],
})
}

Expand Down Expand Up @@ -192,4 +192,22 @@ export default class Places extends API {
this.options({ method: "PUT" }).json(params).authorization({ sign: true })
)
}

async getCategories() {
const result = await super.fetch<{
ok: boolean
data: { name: string; count: number }[]
}>("/categories")

return result.data
}

async getPlaceCategories(placeId: string) {
const result = await super.fetch<{
ok: boolean
data: { categories: string[] }
}>(`/places/${placeId}/categories`)

return result.data
}
}
78 changes: 78 additions & 0 deletions src/components/Categories/CategoriesFilters.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import React from "react"

import { CategoryFilter } from "./CategoryFilter"

type CategoriesFiltersProps = {
categories: { name: string; active: boolean; count: number }[]
onChange: (
newCategories: { name: string; active: boolean; count: number }[]
) => void
onlyActives?: boolean
filtersIcon?: JSX.Element
unremovableFilters?: boolean
}

export const CategoriesFilters = ({
categories,
onChange,
filtersIcon,
onlyActives,
unremovableFilters,
}: CategoriesFiltersProps) => {
function handleCategorySelection(
action: "add" | "remove",
categoryId: string
): { name: string; active: boolean; count: number }[] {
let currentCategories = categories.filter(({ active }) => active)
if (action === "add") {
if (!currentCategories.find(({ name }) => name === categoryId)) {
const category = {
...categories.find(({ name }) => name === categoryId)!,
}
category.active = true
currentCategories.push(category)
}
}

if (action === "remove") {
currentCategories = currentCategories.filter(
({ name }) => name !== categoryId
)
}

return currentCategories
}

return (
<>
{categories
.filter(({ active }) => {
if (onlyActives) {
return active
} else {
return true
}
})
.map((category) => (
<CategoryFilter
key={category.name}
category={category.name}
active={category.active}
onChange={(_e, { active, category }) => {
const newOnes = handleCategorySelection(
active ? "add" : !unremovableFilters ? "remove" : "add",
category
)
if (
categories.filter(({ active }) => active).length !=
newOnes.length
) {
onChange(newOnes)
}
}}
actionIcon={filtersIcon}
/>
))}
</>
)
}
40 changes: 40 additions & 0 deletions src/components/Categories/CategoriesList.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.categories-list__box {
background-color: var(--secondary-on-modal-hover);
width: 248px;
padding: 16px;
border-radius: 10px;
}

.categories-list__title {
margin-bottom: 15px;
display: flex;
align-items: center;
}

.categories-list__title > p {
color: var(--secondary-text);
letter-spacing: 1px;
font-weight: 700;
font-size: 14px;
margin: 0 16px 0 0;
text-transform: uppercase;
}

.categories-list__title > .ui.label {
font-weight: 700;
font-size: 8px;
background-color: var(--primary);
padding: 2px 5px;
line-height: normal;
border-radius: 3px;
color: var(--text-on-primary);
}

.categories-list__listing {
display: flex;
flex-direction: column;
}

.categories-list__listing > .category-filter__box {
margin-bottom: 8px;
}
41 changes: 41 additions & 0 deletions src/components/Categories/CategoriesList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from "react"

import useFormatMessage from "decentraland-gatsby/dist/hooks/useFormatMessage"
import Label from "semantic-ui-react/dist/commonjs/elements/Label"

import { Check } from "../Icon/Check"
import { CategoriesFilters } from "./CategoriesFilters"

import "./CategoriesList.css"

type CategoriesListProps = {
onChange: (
categories: { name: string; active: boolean; count: number }[]
) => void
categories: { name: string; active: boolean; count: number }[]
}

export const CategoriesList = React.memo(
({ categories, onChange }: CategoriesListProps) => {
const l = useFormatMessage()

return (
<div className="categories-list__box">
<div className="categories-list__title">
<p>{l("categories.title")}</p>
<Label>{l("categories.new_label")}</Label>
</div>
<div className="categories-list__listing">
{
<CategoriesFilters
categories={categories}
onChange={onChange}
filtersIcon={<Check />}
unremovableFilters
/>
}
</div>
</div>
)
}
)
Loading

0 comments on commit c5df478

Please sign in to comment.