mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: show category page options on wizard 'homepage' step
This commit is contained in:
@@ -20,9 +20,12 @@ export default createPreviewComponent(659, 320, {
|
||||
if (this.get('step.fieldsById.homepage_style.value') === "latest") {
|
||||
this.drawPills(colors, height * 0.15);
|
||||
this.renderLatest(ctx, colors, width, height);
|
||||
} else {
|
||||
} else if (["categories_only", "categories_with_featured_topics"].includes(this.get('step.fieldsById.homepage_style.value'))) {
|
||||
this.drawPills(colors, height * 0.15, { categories: true });
|
||||
this.renderCategories(ctx, colors, width, height);
|
||||
} else {
|
||||
this.drawPills(colors, height * 0.15, { categories: true });
|
||||
this.renderCategoriesWithTopics(ctx, colors, width, height);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -30,6 +33,89 @@ export default createPreviewComponent(659, 320, {
|
||||
const textColor = darkLightDiff(colors.primary, colors.secondary, 50, 50);
|
||||
const margin = height * 0.03;
|
||||
const bodyFontSize = height / 440.0;
|
||||
const titles = this.getTitles();
|
||||
let categoryHeight = height / 6;
|
||||
|
||||
const drawLine = (x, y) => {
|
||||
ctx.beginPath();
|
||||
ctx.strokeStyle = darkLightDiff(colors.primary, colors.secondary, 90, -75);
|
||||
ctx.moveTo(margin + x, y);
|
||||
ctx.lineTo(width - margin, y);
|
||||
ctx.stroke();
|
||||
};
|
||||
|
||||
const cols = [0.025, 0.45, 0.53, 0.58, 0.94, 0.96].map(c => c * width);
|
||||
|
||||
const headingY = height * 0.33;
|
||||
ctx.font = `${bodyFontSize * 0.9}em 'Arial'`;
|
||||
ctx.fillStyle = textColor;
|
||||
ctx.fillText("Category", cols[0], headingY);
|
||||
if (this.get('step.fieldsById.homepage_style.value') === "categories_only") {
|
||||
ctx.fillText("Topics", cols[4], headingY);
|
||||
} else {
|
||||
ctx.fillText("Topics", cols[1], headingY);
|
||||
ctx.fillText("Latest", cols[2], headingY);
|
||||
categoryHeight = height / 5;
|
||||
}
|
||||
|
||||
let y = headingY + (bodyFontSize * 12);
|
||||
ctx.lineWidth = 2;
|
||||
drawLine(0, y);
|
||||
drawLine(width / 2, y);
|
||||
|
||||
// Categories
|
||||
this.categories().forEach(category => {
|
||||
const textPos = y + (categoryHeight * 0.35);
|
||||
ctx.font = `Bold ${bodyFontSize * 1.1}em 'Arial'`;
|
||||
ctx.fillStyle = colors.primary;
|
||||
ctx.fillText(category.name, cols[0], textPos);
|
||||
|
||||
ctx.font = `${bodyFontSize * 0.8}em 'Arial'`;
|
||||
ctx.fillStyle = textColor;
|
||||
ctx.fillText(titles[0], cols[0] - (margin * 0.25), textPos + (categoryHeight * 0.36));
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(margin, y);
|
||||
ctx.strokeStyle = category.color;
|
||||
ctx.lineWidth = 3.5;
|
||||
ctx.lineTo(margin, y + categoryHeight);
|
||||
ctx.stroke();
|
||||
|
||||
if (this.get('step.fieldsById.homepage_style.value') === "categories_with_featured_topics") {
|
||||
ctx.font = `${bodyFontSize}em 'Arial'`;
|
||||
ctx.fillText(Math.floor(Math.random() * 90) + 10, cols[1] + 15, textPos);
|
||||
} else {
|
||||
ctx.font = `${bodyFontSize}em 'Arial'`;
|
||||
ctx.fillText(Math.floor(Math.random() * 90) + 10, cols[5], textPos);
|
||||
}
|
||||
|
||||
y += categoryHeight;
|
||||
ctx.lineWidth = 1;
|
||||
drawLine(0, y);
|
||||
});
|
||||
|
||||
// Featured Topics
|
||||
if (this.get('step.fieldsById.homepage_style.value') === "categories_with_featured_topics") {
|
||||
const topicHeight = height / 15;
|
||||
|
||||
y = headingY + (bodyFontSize * 22);
|
||||
ctx.lineWidth = 1;
|
||||
ctx.fillStyle = colors.tertiary;;
|
||||
|
||||
titles.forEach(title => {
|
||||
ctx.font = `${bodyFontSize}em 'Arial'`;
|
||||
const textPos = y + (topicHeight * 0.35);
|
||||
ctx.fillStyle = colors.tertiary;;
|
||||
ctx.fillText(`${title}`, cols[2], textPos);
|
||||
y += topicHeight;
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
renderCategoriesWithTopics(ctx, colors, width, height) {
|
||||
const textColor = darkLightDiff(colors.primary, colors.secondary, 50, 50);
|
||||
const margin = height * 0.03;
|
||||
const bodyFontSize = height / 440.0;
|
||||
|
||||
const drawLine = (x, y) => {
|
||||
ctx.beginPath();
|
||||
@@ -39,14 +125,18 @@ export default createPreviewComponent(659, 320, {
|
||||
ctx.stroke();
|
||||
};
|
||||
|
||||
const cols = [0.025, 0.4, 0.53, 0.58, 0.94].map(c => c * width);
|
||||
const cols = [0.025, 0.42, 0.53, 0.58, 0.94].map(c => c * width);
|
||||
|
||||
const headingY = height * 0.33;
|
||||
ctx.font = `${bodyFontSize * 0.9}em 'Arial'`;
|
||||
ctx.fillStyle = textColor;
|
||||
ctx.fillText("Category", cols[0], headingY);
|
||||
ctx.fillText("Topics", cols[1], headingY);
|
||||
ctx.fillText("Latest", cols[2], headingY);
|
||||
if (this.get('step.fieldsById.homepage_style.value') === "categories_and_latest_topics") {
|
||||
ctx.fillText("Latest", cols[2], headingY);
|
||||
} else{
|
||||
ctx.fillText("Top", cols[2], headingY);
|
||||
}
|
||||
|
||||
let y = headingY + (bodyFontSize * 12);
|
||||
ctx.lineWidth = 2;
|
||||
@@ -74,12 +164,15 @@ export default createPreviewComponent(659, 320, {
|
||||
ctx.lineTo(margin, y + categoryHeight);
|
||||
ctx.stroke();
|
||||
|
||||
ctx.font = `${bodyFontSize}em 'Arial'`;
|
||||
ctx.fillText(Math.floor(Math.random() * 90) + 10, cols[1] + 15, textPos);
|
||||
|
||||
y += categoryHeight;
|
||||
ctx.lineWidth = 1;
|
||||
drawLine(0, y);
|
||||
});
|
||||
|
||||
// Categories - Latest Topics
|
||||
// Latest/Top Topics
|
||||
const topicHeight = height / 8;
|
||||
const avatarSize = topicHeight * 0.7;
|
||||
y = headingY + (bodyFontSize * 12);
|
||||
@@ -112,11 +205,10 @@ export default createPreviewComponent(659, 320, {
|
||||
|
||||
drawLine(width / 2, y);
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
getTitles() {
|
||||
return LOREM.split(".").slice(0, 7).map(t => t.substring(0, 40));
|
||||
return LOREM.split(".").slice(0, 8).map(t => t.substring(0, 40));
|
||||
},
|
||||
|
||||
renderLatest(ctx, colors, width, height) {
|
||||
|
||||
@@ -88,7 +88,7 @@ export function createPreviewComponent(width, height, obj) {
|
||||
},
|
||||
|
||||
categories() {
|
||||
return [{name: 'consecteteur', color: '#652D90'}, {name: 'ultrices', color: '#3AB54A'}];
|
||||
return [{name: 'consecteteur', color: '#652D90'}, {name: 'ultrices', color: '#3AB54A'}, {name: 'placerat', color: '#25AAE2'}];
|
||||
},
|
||||
|
||||
scaleImage(image, x, y, w, h) {
|
||||
|
||||
Reference in New Issue
Block a user